-
Notifications
You must be signed in to change notification settings - Fork 10
/
recorder.rs
75 lines (63 loc) · 2.3 KB
/
recorder.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::sync::Arc;
use metrics::{GaugeValue, Key, Unit};
use elfo_core::scope::{self, Scope};
use crate::storage::Storage;
pub(crate) struct Recorder {
storage: Arc<Storage>,
}
impl Recorder {
pub(crate) fn new(storage: Arc<Storage>) -> Self {
Self { storage }
}
fn with_params(&self, f: impl Fn(&Storage, &Scope, bool)) {
scope::try_with(|scope| {
let perm = scope.permissions();
if perm.is_telemetry_per_actor_group_enabled() {
f(&self.storage, scope, false)
}
if perm.is_telemetry_per_actor_key_enabled() && !scope.meta().key.is_empty() {
f(&self.storage, scope, true)
}
});
}
}
impl metrics::Recorder for Recorder {
fn register_counter(&self, key: &Key, _unit: Option<Unit>, description: Option<&'static str>) {
self.storage.add_description_if_missing(key, description);
self.with_params(|storage, scope, with_actor_key| {
storage.touch_counter(scope, key, with_actor_key)
});
}
fn register_gauge(&self, key: &Key, _unit: Option<Unit>, description: Option<&'static str>) {
self.storage.add_description_if_missing(key, description);
self.with_params(|storage, scope, with_actor_key| {
storage.touch_gauge(scope, key, with_actor_key)
});
}
fn register_histogram(
&self,
key: &Key,
_unit: Option<Unit>,
description: Option<&'static str>,
) {
self.storage.add_description_if_missing(key, description);
self.with_params(|storage, scope, with_actor_key| {
storage.touch_histogram(scope, key, with_actor_key)
});
}
fn increment_counter(&self, key: &Key, value: u64) {
self.with_params(|storage, scope, with_actor_key| {
storage.increment_counter(scope, key, value, with_actor_key)
});
}
fn update_gauge(&self, key: &Key, value: GaugeValue) {
self.with_params(|storage, scope, with_actor_key| {
storage.update_gauge(scope, key, value.clone(), with_actor_key)
});
}
fn record_histogram(&self, key: &Key, value: f64) {
self.with_params(|storage, scope, with_actor_key| {
storage.record_histogram(scope, key, value, with_actor_key)
});
}
}