File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
mithril-aggregator/src/metrics Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -79,14 +79,16 @@ build_metrics_service!(
79
79
80
80
impl MetricsService {
81
81
/// 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.
82
84
pub fn export_metrics_map ( & self ) -> HashMap < String , u32 > {
83
85
self . registry
84
86
. gather ( )
85
87
. iter ( )
86
- . map ( |metric | {
88
+ . map ( |metric_family | {
87
89
(
88
- metric . get_name ( ) . to_string ( ) ,
89
- metric
90
+ metric_family . get_name ( ) . to_string ( ) ,
91
+ metric_family
90
92
. get_metric ( )
91
93
. iter ( )
92
94
. map ( |m| m. get_counter ( ) . get_value ( ) as u32 )
@@ -138,4 +140,16 @@ mod tests {
138
140
let export = metrics_service. export_metrics_map ( ) ;
139
141
assert_eq ! ( 0 , export[ & metric_a. name( ) ] ) ;
140
142
}
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
+ }
141
155
}
You can’t perform that action at this time.
0 commit comments