Skip to content

Commit 0143189

Browse files
committed
Ensure that not supported metrics by export_metrics_map are not used
1 parent 18a2f8b commit 0143189

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

mithril-aggregator/src/metrics/service.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ build_metrics_service!(
7979

8080
impl MetricsService {
8181
/// Export metrics in map.
82+
// `get metric` returns a list of Metrics for CounterVec purposes for example.
83+
// We therefore add up the values ​​even though we will always only have one value with our Counter type metrics.
8284
pub fn export_metrics_map(&self) -> HashMap<String, u32> {
8385
self.registry
8486
.gather()
8587
.iter()
86-
.map(|metric| {
88+
.map(|metric_family| {
8789
(
88-
metric.get_name().to_string(),
89-
metric
90+
metric_family.get_name().to_string(),
91+
metric_family
9092
.get_metric()
9193
.iter()
9294
.map(|m| m.get_counter().get_value() as u32)
@@ -138,4 +140,16 @@ mod tests {
138140
let export = metrics_service.export_metrics_map();
139141
assert_eq!(0, export[&metric_a.name()]);
140142
}
143+
144+
#[test]
145+
fn metric_service_should_only_contain_counters_as_export_metrics_map_does_not_yet_support_other_types(
146+
) {
147+
let metrics_service = MetricsService::new(TestLogger::stdout()).unwrap();
148+
149+
for metric_family in metrics_service.registry.gather() {
150+
for metric in metric_family.get_metric() {
151+
assert!(metric.has_counter());
152+
}
153+
}
154+
}
141155
}

0 commit comments

Comments
 (0)