@@ -12,8 +12,13 @@ use slog::{info, Logger};
12
12
/// Message sent to the event store to report a metric value.
13
13
#[ derive( Serialize , Deserialize ) ]
14
14
struct MetricEventMessage {
15
- counter : i64 ,
16
- duration : Duration ,
15
+ /// Name of the metric.
16
+ name : String ,
17
+ /// Value of the metric.
18
+ value : i64 ,
19
+ /// Period of time during which the metric was collected.
20
+ period : Duration ,
21
+ /// Date at which the metric was collected.
17
22
date : DateTime < Utc > ,
18
23
}
19
24
/// Reporter of usage metrics of the application.
@@ -66,10 +71,11 @@ impl UsageReporter {
66
71
. transmitter_service
67
72
. send_event_message :: < MetricEventMessage > (
68
73
"Metrics" ,
69
- & name,
74
+ & name. clone ( ) ,
70
75
& MetricEventMessage {
71
- counter : value,
72
- duration : * duration,
76
+ name,
77
+ value,
78
+ period : * duration,
73
79
date,
74
80
} ,
75
81
vec ! [ ] ,
@@ -132,7 +138,7 @@ mod tests {
132
138
fn extract_metric_value ( message : & EventMessage ) -> ( String , i64 ) {
133
139
let metric_delta: MetricEventMessage =
134
140
serde_json:: from_value ( message. content . clone ( ) ) . unwrap ( ) ;
135
- ( message. action . clone ( ) , metric_delta. counter )
141
+ ( message. action . clone ( ) , metric_delta. value )
136
142
}
137
143
138
144
#[ test]
@@ -159,8 +165,8 @@ mod tests {
159
165
assert_eq ! ( message. action, metric. name( ) ) ;
160
166
let message_content: MetricEventMessage =
161
167
serde_json:: from_value ( message. content . clone ( ) ) . unwrap ( ) ;
162
- assert_eq ! ( 3 , message_content. counter ) ;
163
- assert_eq ! ( Duration :: from_secs( 10 ) , message_content. duration ) ;
168
+ assert_eq ! ( 3 , message_content. value ) ;
169
+ assert_eq ! ( Duration :: from_secs( 10 ) , message_content. period ) ;
164
170
}
165
171
166
172
#[ test]
@@ -225,14 +231,14 @@ mod tests {
225
231
}
226
232
227
233
mod metric_delta {
234
+ use super :: * ;
235
+
228
236
fn build_hashmap < T : Copy > ( values : & [ ( & str , T ) ] ) -> HashMap < String , T > {
229
- let mut metrics = HashMap :: new ( ) ;
230
- for ( name, value) in values {
231
- metrics. insert ( name. to_string ( ) , * value) ;
232
- }
233
- metrics
237
+ values
238
+ . iter ( )
239
+ . map ( |( name, value) | ( name. to_string ( ) , * value) )
240
+ . collect ( )
234
241
}
235
- use super :: * ;
236
242
237
243
#[ test]
238
244
fn should_not_contain_metric_that_not_change ( ) {
0 commit comments