-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(observability): (new style sinks) Emit
EventsDropped
and `Err…
…or` internal events in the service driver (#14836) * 'bit of a poc' * completed: loki,vector,splunk_hec,new_relic,s3_common(dd archives, aws_s3) * gcs_common * datadog_logs * datadog_metrics * datadog_traces * datadog_events * aws_sqs * amqp * azure_common (datadog archives, azure blob) * aws_cloudwatch_logs * aws_kinesis_stream * aws_kinesis_firehose + compilation errors * cleanup * cleanup * don't emit Error events in sink retry logic anymore. * Fixed issue with the new Error events not being detected by the test framework * fixed issue with deprecated batch sinks not emitting internal events * clippy * fix issue where BatchHttpService call within Service call was not emitting internal events * feedback sg * merging event files * event file org for aws_kinesis PR * Revert "event file org for aws_kinesis PR" This reverts commit f9dac54. * Revert "merging event files" This reverts commit 6f06e53. * feedback sw - from_batch * feedback sw (usize/u64) + nasty merge issue with ComponentEventsDropped * feedback sw- pub(crate) * feedback sw * feedback tz- rate limit * feedback tz - double add * feedback tz- optimize vector sink request metadata calc * optimization to vector sink was incomplete * feedback bg - use match * feedback bg- impl Add * feedback bg- event collection struct + MetaDescriptive return by value * feedback bg- save * feedback bg- refactor RequestBuilder Co-authored-by: Jesse Szwedko <[email protected]>
- Loading branch information
Showing
103 changed files
with
1,489 additions
and
762 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
lib/vector-common/src/internal_event/component_events_dropped.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use super::{Count, InternalEvent, InternalEventHandle, RegisterInternalEvent}; | ||
use metrics::{register_counter, Counter}; | ||
|
||
pub const INTENTIONAL: bool = true; | ||
pub const UNINTENTIONAL: bool = false; | ||
|
||
#[derive(Debug)] | ||
pub struct ComponentEventsDropped<'a, const INTENTIONAL: bool> { | ||
pub count: usize, | ||
pub reason: &'a str, | ||
} | ||
|
||
impl<'a, const INTENTIONAL: bool> InternalEvent for ComponentEventsDropped<'a, INTENTIONAL> { | ||
fn emit(self) { | ||
let count = self.count; | ||
self.register().emit(Count(count)); | ||
} | ||
|
||
fn name(&self) -> Option<&'static str> { | ||
Some("ComponentEventsDropped") | ||
} | ||
} | ||
|
||
impl<'a, const INTENTIONAL: bool> From<&'a str> for ComponentEventsDropped<'a, INTENTIONAL> { | ||
fn from(reason: &'a str) -> Self { | ||
Self { count: 0, reason } | ||
} | ||
} | ||
|
||
impl<'a, const INTENTIONAL: bool> RegisterInternalEvent | ||
for ComponentEventsDropped<'a, INTENTIONAL> | ||
{ | ||
type Handle = DroppedHandle<'a, INTENTIONAL>; | ||
fn register(self) -> Self::Handle { | ||
Self::Handle { | ||
discarded_events: register_counter!( | ||
"component_discarded_events_total", | ||
"intentional" => if INTENTIONAL { "true" } else { "false" }, | ||
), | ||
reason: self.reason, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct DroppedHandle<'a, const INTENDED: bool> { | ||
discarded_events: Counter, | ||
reason: &'a str, | ||
} | ||
|
||
impl<'a, const INTENDED: bool> InternalEventHandle for DroppedHandle<'a, INTENDED> { | ||
type Data = Count; | ||
fn emit(&self, data: Self::Data) { | ||
let message = "Events dropped"; | ||
if INTENDED { | ||
debug!( | ||
message, | ||
intentional = INTENDED, | ||
count = data.0, | ||
reason = self.reason, | ||
internal_log_rate_limit = true, | ||
); | ||
} else { | ||
error!( | ||
message, | ||
intentional = INTENDED, | ||
count = data.0, | ||
reason = self.reason, | ||
internal_log_rate_limit = true, | ||
); | ||
} | ||
self.discarded_events.increment(data.0 as u64); | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use std::ops::Add; | ||
|
||
/// Metadata for batch requests. | ||
#[derive(Clone, Debug, Default, Copy)] | ||
pub struct RequestMetadata { | ||
/// Number of events represented by this batch request. | ||
event_count: usize, | ||
/// Size, in bytes, of the in-memory representation of all events in this batch request. | ||
events_byte_size: usize, | ||
/// Size, in bytes, of the estimated JSON-encoded representation of all events in this batch request. | ||
events_estimated_json_encoded_byte_size: usize, | ||
/// Uncompressed size, in bytes, of the encoded events in this batch request. | ||
request_encoded_size: usize, | ||
/// On-the-wire size, in bytes, of the batch request itself after compression, etc. | ||
/// | ||
/// This is akin to the bytes sent/received over the network, regardless of whether or not compression was used. | ||
request_wire_size: usize, | ||
} | ||
|
||
// TODO: Make this struct the object which emits the actual internal telemetry i.e. events sent, bytes sent, etc. | ||
impl RequestMetadata { | ||
#[must_use] | ||
pub fn new( | ||
event_count: usize, | ||
events_byte_size: usize, | ||
request_encoded_size: usize, | ||
request_wire_size: usize, | ||
events_estimated_json_encoded_byte_size: usize, | ||
) -> Self { | ||
Self { | ||
event_count, | ||
events_byte_size, | ||
events_estimated_json_encoded_byte_size, | ||
request_encoded_size, | ||
request_wire_size, | ||
} | ||
} | ||
|
||
#[must_use] | ||
pub const fn event_count(&self) -> usize { | ||
self.event_count | ||
} | ||
|
||
#[must_use] | ||
pub const fn events_byte_size(&self) -> usize { | ||
self.events_byte_size | ||
} | ||
|
||
#[must_use] | ||
pub const fn events_estimated_json_encoded_byte_size(&self) -> usize { | ||
self.events_estimated_json_encoded_byte_size | ||
} | ||
|
||
#[must_use] | ||
pub const fn request_encoded_size(&self) -> usize { | ||
self.request_encoded_size | ||
} | ||
|
||
#[must_use] | ||
pub const fn request_wire_size(&self) -> usize { | ||
self.request_wire_size | ||
} | ||
|
||
/// Constructs a `RequestMetadata` by summation of the "batch" of `RequestMetadata` provided. | ||
#[must_use] | ||
pub fn from_batch<T: IntoIterator<Item = RequestMetadata>>(metadata_iter: T) -> Self { | ||
let mut metadata_sum = RequestMetadata::new(0, 0, 0, 0, 0); | ||
|
||
for metadata in metadata_iter { | ||
metadata_sum = metadata_sum + &metadata; | ||
} | ||
metadata_sum | ||
} | ||
} | ||
|
||
impl<'a> Add<&'a RequestMetadata> for RequestMetadata { | ||
type Output = RequestMetadata; | ||
|
||
/// Adds the other `RequestMetadata` to this one. | ||
fn add(self, other: &'a Self::Output) -> Self::Output { | ||
Self::Output { | ||
event_count: self.event_count + other.event_count, | ||
events_byte_size: self.events_byte_size + other.events_byte_size, | ||
events_estimated_json_encoded_byte_size: self.events_estimated_json_encoded_byte_size | ||
+ other.events_estimated_json_encoded_byte_size, | ||
request_encoded_size: self.request_encoded_size + other.request_encoded_size, | ||
request_wire_size: self.request_wire_size + other.request_wire_size, | ||
} | ||
} | ||
} | ||
|
||
/// Objects implementing this trait have metadata that describes the request. | ||
pub trait MetaDescriptive { | ||
/// Returns the `RequestMetadata` associated with this object. | ||
fn get_metadata(&self) -> RequestMetadata; | ||
} |
This file contains 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 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.