-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust): Add processor metrics for Rust consumer (#4737)
Adds metrics for `arroyo.consumer.poll.time`, `arroyo.consumer.paused.time` and `arroyo.consumer.processing.time`.
- Loading branch information
Showing
5 changed files
with
93 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::utils::metrics::{get_metrics, Metrics}; | ||
use core::fmt::Debug; | ||
use std::collections::BTreeMap; | ||
use std::mem; | ||
use std::sync::{Arc, Mutex}; | ||
use std::time::{Duration, Instant}; | ||
|
||
#[derive(Debug)] | ||
pub struct MetricsBuffer { | ||
metrics: Arc<Mutex<Box<dyn Metrics>>>, | ||
timers: BTreeMap<String, Duration>, | ||
last_flush: Instant, | ||
} | ||
|
||
impl MetricsBuffer { | ||
// A pretty shitty metrics buffer that only handles timing metrics | ||
// and flushes them every second. Needs to be flush()-ed on shutdown | ||
// Doesn't support tags | ||
// Basically the same as https://github.com/getsentry/arroyo/blob/83f5f54e59892ad0b62946ef35d2daec3b561b10/arroyo/processing/processor.py#L80-L112 | ||
// We may want to replace this with the statsdproxy aggregation step. | ||
pub fn new() -> Self { | ||
Self { | ||
metrics: get_metrics(), | ||
timers: BTreeMap::new(), | ||
last_flush: Instant::now(), | ||
} | ||
} | ||
|
||
pub fn incr_timing(&mut self, metric: &str, duration: Duration) { | ||
if let Some(value) = self.timers.get_mut(metric) { | ||
*value += duration; | ||
} else { | ||
self.timers.insert(metric.to_string(), duration); | ||
} | ||
self.throttled_record(); | ||
} | ||
|
||
pub fn flush(&mut self) { | ||
let timers = mem::take(&mut self.timers); | ||
for (metric, duration) in timers { | ||
self.metrics | ||
.timing(&metric, duration.as_millis() as u64, None); | ||
} | ||
self.last_flush = Instant::now(); | ||
} | ||
|
||
fn throttled_record(&mut self) { | ||
if self.last_flush.elapsed() > Duration::from_secs(1) { | ||
self.flush(); | ||
} | ||
} | ||
} | ||
|
||
impl Default for MetricsBuffer { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
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