-
Notifications
You must be signed in to change notification settings - Fork 35
add burst monitoring for global task injector #85
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
be620ef
00ad45f
f175ad0
7ae8e40
af34a0c
5b47610
30b88f1
d01ed0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,11 @@ | |||||||||||||||||||||||
| //! Metrics of the thread pool. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| use lazy_static::lazy_static; | ||||||||||||||||||||||||
| use prometheus::core::{Collector, Desc, Metric, MetricVec, MetricVecBuilder}; | ||||||||||||||||||||||||
| use prometheus::*; | ||||||||||||||||||||||||
| use std::sync::Mutex; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| use std::sync::atomic::{AtomicU64, Ordering}; | ||||||||||||||||||||||||
| use std::sync::{Arc, Mutex}; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| lazy_static! { | ||||||||||||||||||||||||
| /// Elapsed time of each level in the multilevel task queue. | ||||||||||||||||||||||||
|
|
@@ -71,6 +74,16 @@ lazy_static! { | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Max enqueue throughput of the global task injector (QueueCore) since last scrape. | ||||||||||||||||||||||||
| pub static ref QUEUE_CORE_BURST_THROUGHPUT: MaxGaugeVec = MaxGaugeVec::new( | ||||||||||||||||||||||||
| new_opts( | ||||||||||||||||||||||||
| "yatp_queue_core_burst_throughput", | ||||||||||||||||||||||||
| "max enqueue throughput (tasks/sec) of the global task injector since last scrape" | ||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||
| &["name"] | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| static ref NAMESPACE: Mutex<Option<String>> = Mutex::new(None); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -98,3 +111,182 @@ fn new_histogram_opts(name: &str, help: &str, buckets: Vec<f64>) -> HistogramOpt | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| opts | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// A gauge that tracks the maximum value since the last scrape. | ||||||||||||||||||||||||
| #[derive(Clone, Debug)] | ||||||||||||||||||||||||
| pub struct MaxGauge { | ||||||||||||||||||||||||
| gauge: Gauge, | ||||||||||||||||||||||||
| max_val: Arc<AtomicU64>, | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| impl MaxGauge { | ||||||||||||||||||||||||
| /// Wraps a `Gauge` to create a `MaxGauge`. The `Gauge` should not be used directly after being wrapped, otherwise | ||||||||||||||||||||||||
| /// the maximum tracking will be broken. | ||||||||||||||||||||||||
| pub fn wrap(gauge: Gauge) -> Self { | ||||||||||||||||||||||||
| let val = gauge.get().to_bits(); | ||||||||||||||||||||||||
| Self { | ||||||||||||||||||||||||
| gauge, | ||||||||||||||||||||||||
| max_val: Arc::new(AtomicU64::new(val)), | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Observe a value, keeping the maximum since the last scrape. | ||||||||||||||||||||||||
| pub fn observe(&self, v: f64) { | ||||||||||||||||||||||||
| if !v.is_finite() { | ||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| let mut current = self.max_val.load(Ordering::Relaxed); | ||||||||||||||||||||||||
| loop { | ||||||||||||||||||||||||
| if v <= f64::from_bits(current) { | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| match self.max_val.compare_exchange_weak( | ||||||||||||||||||||||||
| current, | ||||||||||||||||||||||||
| v.to_bits(), | ||||||||||||||||||||||||
| Ordering::Relaxed, | ||||||||||||||||||||||||
| Ordering::Relaxed, | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| Ok(_) => { | ||||||||||||||||||||||||
| self.gauge.set(v); | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Err(actual) => current = actual, | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Get the current maximum value without resetting it. | ||||||||||||||||||||||||
| pub fn get(&self) -> f64 { | ||||||||||||||||||||||||
| let val = self.max_val.load(Ordering::Relaxed); | ||||||||||||||||||||||||
| f64::from_bits(val) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| fn take(&self) -> f64 { | ||||||||||||||||||||||||
| let val = self.max_val.swap(0f64.to_bits(), Ordering::Relaxed); | ||||||||||||||||||||||||
| f64::from_bits(val) | ||||||||||||||||||||||||
|
Comment on lines
+163
to
+164
|
||||||||||||||||||||||||
| let val = self.max_val.swap(0f64.to_bits(), Ordering::Relaxed); | |
| f64::from_bits(val) | |
| let prev = self | |
| .max_val | |
| .swap(f64::NEG_INFINITY.to_bits(), Ordering::Relaxed); | |
| let val = f64::from_bits(prev); | |
| if val == f64::NEG_INFINITY { | |
| 0.0 | |
| } else { | |
| val | |
| } |
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.
MaxGauge::wrapseedsmax_valfrom the wrappedGauge's current value (typically 0). That makes the max tracking incorrect for metrics that can legitimately be negative (e.g. observing -1.0 will never update the max if the seed is 0). Consider initializing the internal max to a sentinel like-inf/"no value yet" instead of the gauge's current value, and only exporting 0 when there have been no observations since the last scrape.