@@ -12,8 +12,13 @@ use slog::{info, Logger};
1212/// Message sent to the event store to report a metric value.
1313#[ derive( Serialize , Deserialize ) ]
1414struct 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.
1722 date : DateTime < Utc > ,
1823}
1924/// Reporter of usage metrics of the application.
@@ -66,10 +71,11 @@ impl UsageReporter {
6671 . transmitter_service
6772 . send_event_message :: < MetricEventMessage > (
6873 "Metrics" ,
69- & name,
74+ & name. clone ( ) ,
7075 & MetricEventMessage {
71- counter : value,
72- duration : * duration,
76+ name,
77+ value,
78+ period : * duration,
7379 date,
7480 } ,
7581 vec ! [ ] ,
@@ -132,7 +138,7 @@ mod tests {
132138 fn extract_metric_value ( message : & EventMessage ) -> ( String , i64 ) {
133139 let metric_delta: MetricEventMessage =
134140 serde_json:: from_value ( message. content . clone ( ) ) . unwrap ( ) ;
135- ( message. action . clone ( ) , metric_delta. counter )
141+ ( message. action . clone ( ) , metric_delta. value )
136142 }
137143
138144 #[ test]
@@ -159,8 +165,8 @@ mod tests {
159165 assert_eq ! ( message. action, metric. name( ) ) ;
160166 let message_content: MetricEventMessage =
161167 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 ) ;
164170 }
165171
166172 #[ test]
@@ -225,14 +231,14 @@ mod tests {
225231 }
226232
227233 mod metric_delta {
234+ use super :: * ;
235+
228236 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+ . into_iter ( )
239+ . map ( |( name, value) | ( name. to_string ( ) , * value) )
240+ . collect ( )
234241 }
235- use super :: * ;
236242
237243 #[ test]
238244 fn should_not_contain_metric_that_not_change ( ) {
0 commit comments