-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(derive): Stage Level Metrics (#309)
* feat(derive): stage metrics * feat: pull out feature flags into macros * fix: merge * fix: use macros
- Loading branch information
Showing
19 changed files
with
268 additions
and
125 deletions.
There are no files selected for viewing
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,55 @@ | ||
//! Macros for use across derive. | ||
/// Starts the timer with a label value. | ||
#[macro_export] | ||
macro_rules! timer { | ||
(START, $metric:ident, $labels:expr, $timer:ident) => { | ||
#[cfg(feature = "metrics")] | ||
let $timer = $crate::metrics::$metric.with_label_values($labels).start_timer(); | ||
#[cfg(not(feature = "metrics"))] | ||
let $timer = (); | ||
}; | ||
(DISCARD, $timer:ident) => { | ||
#[cfg(feature = "metrics")] | ||
$timer.stop_and_discard(); | ||
}; | ||
(STOP, $timer:ident) => { | ||
#[cfg(feature = "metrics")] | ||
$timer.stop_and_record(); | ||
}; | ||
} | ||
|
||
/// Increments a metric with a label value. | ||
#[macro_export] | ||
macro_rules! inc_gauge { | ||
($metric:ident, $label:expr) => { | ||
#[cfg(feature = "metrics")] | ||
$crate::metrics::$metric.with_label_values(&[$label]).inc(); | ||
}; | ||
($metric:ident, $value:expr, $label:expr) => { | ||
#[cfg(feature = "metrics")] | ||
$crate::metrics::$metric.with_label_values(&[$label]).add($value); | ||
}; | ||
} | ||
|
||
/// Observes a metric with a label value. | ||
#[macro_export] | ||
macro_rules! observe_histogram { | ||
($metric:ident, $value:expr) => { | ||
#[cfg(feature = "metrics")] | ||
$crate::metrics::$metric.observe($value); | ||
}; | ||
($metric:ident, $value:expr, $label:expr) => { | ||
#[cfg(feature = "metrics")] | ||
$crate::metrics::$metric.with_label_values(&[$label]).observe($value); | ||
}; | ||
} | ||
|
||
/// Sets a metric value. | ||
#[macro_export] | ||
macro_rules! metrics_set { | ||
($metric:ident, $value:expr) => { | ||
#[cfg(feature = "metrics")] | ||
$crate::metrics::$metric.set($value); | ||
}; | ||
} |
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,54 @@ | ||
//! Metrics for derivation pipeline stages. | ||
use alloc::{boxed::Box, string::String}; | ||
use lazy_static::lazy_static; | ||
use prometheus::{ | ||
self, opts, register_gauge_vec, register_histogram, register_histogram_vec, register_int_gauge, | ||
GaugeVec, Histogram, HistogramVec, IntGauge, | ||
}; | ||
|
||
const RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 18] = &[ | ||
0.00001, 0.00005, 0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.008, 0.01, 0.02, 0.05, 0.08, | ||
0.1, 0.2, 0.5, 0.8, 1.0, | ||
]; | ||
|
||
lazy_static! { | ||
/// Tracks the L1 origin for the L1 Traversal Stage. | ||
pub static ref ORIGIN_GAUGE: IntGauge = register_int_gauge!( | ||
"origin_gauge", | ||
"Tracks the L1 origin for the L1 Traversal Stage" | ||
).expect("Origin Gauge failed to register"); | ||
|
||
/// Tracks the time taken for provider methods. | ||
pub static ref PROVIDER_RESPONSE_TIME: HistogramVec = register_histogram_vec!( | ||
"provider_response_time_seconds", | ||
"Provider response times", | ||
&["provider", "method"], | ||
RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() | ||
) | ||
.expect("Failed to register histogram vec"); | ||
|
||
/// Tracks the time taken for stage advance methods. | ||
pub static ref STAGE_ADVANCE_RESPONSE_TIME: HistogramVec = register_histogram_vec!( | ||
"stage_advance_response_time_seconds", | ||
"Stage advance response times", | ||
&["stage"], | ||
RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() | ||
).expect("Failed to register histogram vec"); | ||
|
||
/// Tracks the number of derived frames. | ||
pub static ref DERIVED_FRAMES_COUNT: GaugeVec = { | ||
let opts = opts!("derived_frames_count", "Number of derived frames"); | ||
register_gauge_vec!(opts, &["status"]).expect("Derived Frames Count failed to register") | ||
}; | ||
|
||
/// Tracks the number of channel timeouts. | ||
pub static ref CHANNEL_TIMEOUTS: Histogram = { | ||
let channel_timeout_buckets: [f64; 100] = core::array::from_fn(|i| (i * 10) as f64); | ||
register_histogram!( | ||
"channel_timeouts", | ||
"Channel timeouts", | ||
channel_timeout_buckets.to_vec() | ||
).expect("Failed to register histogram vec") | ||
}; | ||
} |
Oops, something went wrong.