-
Notifications
You must be signed in to change notification settings - Fork 2k
enhancement(observability): Add metrics to measure total event processing time #24481
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
25416c6
68f79fb
d5e5b7e
59e4022
7a38f9f
3e83ae5
1645439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Added the `event_processing_time_seconds` histogram and `event_processing_time_mean_seconds` gauge internal_metrics, | ||
| exposing the total time events spend between the originating source and final sink in a topology. | ||
|
|
||
| authors: bruceg |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use metrics::Gauge; | ||
|
|
||
| use super::AtomicEwma; | ||
|
|
||
| /// The default alpha parameter used when constructing EWMA-backed gauges. | ||
| pub const DEFAULT_EWMA_ALPHA: f64 = 0.9; | ||
|
|
||
| /// Couples a [`Gauge`] with an [`AtomicEwma`] so gauge readings reflect the EWMA. | ||
| #[derive(Clone, Debug)] | ||
| pub struct EwmaGauge { | ||
| gauge: Gauge, | ||
| // Note that the `Gauge` internally is equivalent to an `Arc<AtomicF64>` so we need to use the | ||
| // same semantics for the EWMA calculation as well. | ||
| ewma: Arc<AtomicEwma>, | ||
| } | ||
|
|
||
| impl EwmaGauge { | ||
| #[must_use] | ||
| pub fn new(gauge: Gauge, alpha: Option<f64>) -> Self { | ||
| let alpha = alpha.unwrap_or(DEFAULT_EWMA_ALPHA); | ||
| let ewma = Arc::new(AtomicEwma::new(alpha)); | ||
| Self { gauge, ewma } | ||
| } | ||
|
|
||
| /// Records a new value, updates the EWMA, and sets the gauge accordingly. | ||
| pub fn record(&self, value: f64) { | ||
| let average = self.ewma.update(value); | ||
| self.gauge.set(average); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ use std::{collections::HashMap, fmt, num::NonZeroUsize, sync::Arc}; | |
|
|
||
| use bitmask_enum::bitmask; | ||
| use bytes::Bytes; | ||
| use chrono::{DateTime, Utc}; | ||
|
|
||
| mod global_options; | ||
| mod log_schema; | ||
|
|
@@ -487,28 +486,38 @@ impl LogNamespace { | |
| } | ||
|
|
||
| /// Vector: The `ingest_timestamp`, and `source_type` fields are added to "event metadata", nested | ||
| /// under the name "vector". This data will be marked as read-only in VRL. | ||
| /// under the name "vector". This data will be marked as read-only in VRL. The `ingest_timestamp` | ||
| /// is only inserted if it already exists on the event metadata. | ||
| /// | ||
| /// Legacy: The values of `source_type_key`, and `timestamp_key` are stored as keys on the event root, | ||
| /// only if a field with that name doesn't already exist. | ||
| #[allow(clippy::missing_panics_doc, reason = "Can only panic in test")] | ||
| pub fn insert_standard_vector_source_metadata( | ||
| &self, | ||
| log: &mut LogEvent, | ||
| source_name: &'static str, | ||
| now: DateTime<Utc>, | ||
| ) { | ||
|
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. I'm worried the removal of Since we're already getting pub fn insert_standard_vector_source_metadata(
&self,
log: &mut LogEvent,
source_name: &'static str,
now: Option<DateTime<Utc>>, // Not sure if Option is needed here
) {
if let Some(now) = now {
log.metadata_mut().set_ingest_timestamp(now);
}
// ...This way we can remove the many Or maybe we can move this into
Member
Author
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. I can get behind this, and it will shrink the diff too. I don't think
Member
Author
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. Done in 1645439 |
||
| self.insert_vector_metadata( | ||
| log, | ||
| log_schema().source_type_key(), | ||
| path!("source_type"), | ||
| Bytes::from_static(source_name.as_bytes()), | ||
| ); | ||
| self.insert_vector_metadata( | ||
| log, | ||
| log_schema().timestamp_key(), | ||
| path!("ingest_timestamp"), | ||
| now, | ||
| // We could automatically set the ingest timestamp here, but it's better to make the source | ||
| // set it so that it can ensure that all events in a batch have the same timestamp. | ||
| #[cfg(test)] | ||
| assert!( | ||
| log.metadata().ingest_timestamp().is_some(), | ||
| "Event ingest_timestamp was not set by the source" | ||
| ); | ||
| if let Some(timestamp) = log.metadata().ingest_timestamp() { | ||
| self.insert_vector_metadata( | ||
| log, | ||
| log_schema().timestamp_key(), | ||
| path!("ingest_timestamp"), | ||
| timestamp, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Vector: This is added to the "event metadata", nested under the name "vector". This data | ||
|
|
@@ -587,7 +596,8 @@ mod test { | |
|
|
||
| let namespace = LogNamespace::Legacy; | ||
| let mut event = LogEvent::from("log"); | ||
| namespace.insert_standard_vector_source_metadata(&mut event, "source", Utc::now()); | ||
| event.metadata_mut().set_ingest_timestamp(Utc::now()); | ||
| namespace.insert_standard_vector_source_metadata(&mut event, "source"); | ||
|
|
||
| assert!(event.get(event_path!("a", "b", "c", "d")).is_some()); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.