-
Notifications
You must be signed in to change notification settings - Fork 3
OBE-10327: rejection reports for splunk hec / in general #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akshayakumar-t
wants to merge
8
commits into
master
Choose a base branch
from
OBE-10327_log_hec_api_call
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
91e216b
OBE-10327: rejection reports for splunk hec / in general
akshayakumar-t cd0adca
OBE-10327: add tests for rejection report infrastructure and HEC serv…
akshayakumar-t 983e3ae
OBE-10327: remove unnecessary comments from rejection report tests
akshayakumar-t 5458392
OBE-10327: remove log_category from RejectionContext trait
akshayakumar-t e444894
OBE-10327: address review feedback on HecRejectionContext
akshayakumar-t 5e122bb
OBE-10327: add missing rejection_report field to HecLogsSinkConfig in…
akshayakumar-t b2cf757
OBE-10327: add missing fields to HEC integration test config helpers
akshayakumar-t 524d3d1
OBE-10327: address v2 review feedback
akshayakumar-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ use crate::{ | |
| sinks::util::{ | ||
| auth::Auth, | ||
| http::{HttpBatchService, RequestConfig}, | ||
| Compression, ElementCount, Decompressor, | ||
| Compression, ElementCount, emit_rejection_error, RejectionContext, | ||
| }, | ||
| }; | ||
|
|
||
|
|
@@ -77,6 +77,26 @@ pub struct Telemetry { | |
| pub indexed: Counter, | ||
| } | ||
|
|
||
| pub struct ElasticsearchRejectionContext { | ||
| pub telemetry: Telemetry, | ||
| } | ||
|
|
||
| impl RejectionContext for ElasticsearchRejectionContext { | ||
| fn error_code(&self, status: u16) -> String { | ||
| format!("http_response_{status}") | ||
| } | ||
|
|
||
| fn error_message(&self, status: u16, body: &Bytes) -> String { | ||
| err_summary(status, body).msg | ||
| } | ||
|
|
||
| fn record_rejection(&self, status: u16, body: &Bytes) { | ||
| let s = err_summary(status, body); | ||
| self.telemetry.rejected.increment(s.rejected); | ||
| self.telemetry.indexed.increment(s.indexed); | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct ElasticsearchService { | ||
| // TODO: `HttpBatchService` has been deprecated for direct use in sinks. | ||
|
|
@@ -88,7 +108,7 @@ pub struct ElasticsearchService { | |
| >, | ||
| rej_rpt: RejectionReport, | ||
| compression: Compression, | ||
| telemetry: Telemetry, | ||
| context: Arc<ElasticsearchRejectionContext>, | ||
| } | ||
|
|
||
| impl ElasticsearchService { | ||
|
|
@@ -97,7 +117,7 @@ impl ElasticsearchService { | |
| http_request_builder: HttpRequestBuilder, | ||
| rej_rpt: RejectionReport, | ||
| compression: Compression, | ||
| telemetry: Telemetry, | ||
| context: Arc<ElasticsearchRejectionContext>, | ||
| ) -> ElasticsearchService { | ||
| let http_request_builder = Arc::new(http_request_builder); | ||
| let batch_service = HttpBatchService::new(http_client, move |req| { | ||
|
|
@@ -106,7 +126,7 @@ impl ElasticsearchService { | |
| Box::pin(async move { request_builder.build_request(req).await }); | ||
| future | ||
| }); | ||
| ElasticsearchService { batch_service, rej_rpt, compression, telemetry } | ||
| ElasticsearchService { batch_service, rej_rpt, compression, context } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -213,14 +233,14 @@ impl Service<ElasticsearchRequest> for ElasticsearchService { | |
| } else { | ||
| None | ||
| }; | ||
| let telemetry = self.telemetry.clone(); | ||
| let context = Arc::clone(&self.context); | ||
| Box::pin(async move { | ||
| http_service.ready().await?; | ||
| let events_byte_size = | ||
| std::mem::take(req.metadata_mut()).into_events_estimated_json_encoded_byte_size(); | ||
| let http_response = http_service.call(req).await?; | ||
|
|
||
| let event_status = get_event_status(&http_response, req_for_rpt, rej_rpt, telemetry); | ||
| let event_status = get_event_status(&http_response, req_for_rpt, rej_rpt, &context); | ||
| Ok(ElasticsearchResponse { | ||
| event_status, | ||
| http_response, | ||
|
|
@@ -230,8 +250,6 @@ impl Service<ElasticsearchRequest> for ElasticsearchService { | |
| } | ||
| } | ||
|
|
||
| const ES_REJ_RPT: &str = "es_rej_rpt"; | ||
|
|
||
| fn response_frag(key: &str, val_prefix: &str) -> String { | ||
| format!("\"{key}\":{val_prefix}") | ||
| } | ||
|
|
@@ -244,97 +262,55 @@ struct ErrSummary { | |
| rejected: u64, | ||
| } | ||
|
|
||
| fn err_summary(response: &Response<Bytes>) -> ErrSummary { | ||
| let body = String::from_utf8_lossy(response.body()); | ||
| let i = | ||
| body | ||
| fn err_summary(status: u16, body: &Bytes) -> ErrSummary { | ||
| let body_str = String::from_utf8_lossy(body); | ||
| let i: u64 = | ||
| body_str | ||
| .match_indices(response_frag("status", "201").as_str()) | ||
| .count() | ||
| .try_into() | ||
| .unwrap(); | ||
| let r = | ||
| body | ||
| let r: u64 = | ||
| body_str | ||
| .match_indices(response_frag("status", "400").as_str()) | ||
| .count() | ||
| .try_into() | ||
| .unwrap(); | ||
| ErrSummary { | ||
| error_code: format!("http_response_{}", response.status().as_u16()), | ||
| error_code: format!("http_response_{status}"), | ||
| msg: format!("Request contained errors (indexed: {i}, rejected: {r})."), | ||
| indexed: i, | ||
| rejected: r | ||
| } | ||
| } | ||
|
|
||
| fn emit_bad_response_error( | ||
| response: &Response<Bytes>, | ||
| request: Option<(ElasticsearchRequest, Compression)>, | ||
| rej_rpt: RejectionReport, | ||
| telemetry: Telemetry, | ||
| ) { | ||
| let err_summary = err_summary(response); | ||
| telemetry.indexed.increment(err_summary.indexed); | ||
| telemetry.rejected.increment(err_summary.rejected); | ||
|
|
||
| match (rej_rpt, request) { | ||
| (RejectionReport::RequestResponse, Some((req, comp))) => { | ||
| let decomp = Decompressor::from(comp); | ||
| let req_data = match decomp.decompress(req.payload) { | ||
| Ok(data) => data, | ||
| Err(err) => format!("- decompression failed({comp}): '{err}' -").into() | ||
| }; | ||
|
|
||
| error!( | ||
| category = ES_REJ_RPT, | ||
| message = err_summary.msg, | ||
| error_code = err_summary.error_code, | ||
| response = ?response, | ||
| request = %String::from_utf8_lossy(&req_data), | ||
| ); | ||
| } | ||
| (RejectionReport::Stats, _) => { | ||
| error!( | ||
| category = ES_REJ_RPT, | ||
| message = err_summary.msg, | ||
| error_code = err_summary.error_code, | ||
| ); | ||
| } | ||
| _ => { | ||
| error!( | ||
| category = ES_REJ_RPT, | ||
| message = err_summary.msg, | ||
| error_code = err_summary.error_code, | ||
| response = ?response, | ||
| ); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn get_event_status( | ||
| response: &Response<Bytes>, | ||
| request: Option<(ElasticsearchRequest, Compression)>, | ||
| rej_rpt: RejectionReport, | ||
| telemetry: Telemetry, | ||
| context: &ElasticsearchRejectionContext, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let us uniformly call it |
||
| ) -> EventStatus { | ||
| let status = response.status(); | ||
| if status.is_success() { | ||
| let body = String::from_utf8_lossy(response.body()); | ||
| if body.contains(response_frag("errors", "true").as_str()) { | ||
| emit_bad_response_error(response, request, rej_rpt, telemetry); | ||
| let body = response.body(); | ||
| if String::from_utf8_lossy(body).contains(response_frag("errors", "true").as_str()) { | ||
| let req = request.map(|(req, comp)| (req.payload, comp)); | ||
| emit_rejection_error(context, status.as_u16(), body, req, rej_rpt); | ||
| EventStatus::Rejected | ||
| } else { | ||
| EventStatus::Delivered | ||
| } | ||
| } else if status.is_server_error() { | ||
| let rej_rpt = if rej_rpt == RejectionReport::RequestResponse { | ||
| let mode = if rej_rpt == RejectionReport::RequestResponse { | ||
| RejectionReport::Response | ||
| } else { | ||
| rej_rpt | ||
| }; | ||
| emit_bad_response_error(response, None, rej_rpt, telemetry); | ||
| emit_rejection_error(context, status.as_u16(), response.body(), None, mode); | ||
| EventStatus::Errored | ||
| } else { | ||
| emit_bad_response_error(response, request, rej_rpt, telemetry); | ||
| let req = request.map(|(req, comp)| (req.payload, comp)); | ||
| emit_rejection_error(context, status.as_u16(), response.body(), req, rej_rpt); | ||
| EventStatus::Rejected | ||
| } | ||
| } | ||
|
|
@@ -366,7 +342,7 @@ mod tests { | |
| assert!(body.contains(response_frag("errors", "true").as_str())); | ||
|
|
||
| assert_eq!( | ||
| err_summary(&res), | ||
| err_summary(res.status().as_u16(), res.body()), | ||
| ErrSummary { | ||
| error_code: "http_response_200".into(), | ||
| msg: "Request contained errors (indexed: 259, rejected: 5).".to_string(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/context/rec_ctx/