@@ -3,7 +3,6 @@ use crate::experiments::{Assignee, Experiment};
3
3
use crate :: prelude:: * ;
4
4
use crate :: server:: agents:: Agent ;
5
5
use chrono:: { DateTime , Utc } ;
6
- use prometheus:: proto:: { Metric , MetricFamily } ;
7
6
use prometheus:: { HistogramVec , IntCounter , IntCounterVec , IntGauge , IntGaugeVec } ;
8
7
9
8
const JOBS_METRIC : & str = "crater_completed_jobs_total" ;
@@ -26,7 +25,7 @@ impl Metrics {
26
25
pub fn new ( ) -> Fallible < Self > {
27
26
let jobs_opts = prometheus:: opts!( JOBS_METRIC , "total completed jobs" ) ;
28
27
let crater_completed_jobs_total =
29
- prometheus:: register_int_counter_vec!( jobs_opts, & [ "agent" , " experiment"] ) ?;
28
+ prometheus:: register_int_counter_vec!( jobs_opts, & [ "experiment" ] ) ?;
30
29
let crater_bounced_record_progress = prometheus:: register_int_counter!(
31
30
"crater_bounced_record_progress" ,
32
31
"hits with full record progress queue"
@@ -63,39 +62,15 @@ impl Metrics {
63
62
. inc_by ( 1 ) ;
64
63
}
65
64
66
- pub fn record_completed_jobs ( & self , agent : & str , experiment : & str , amount : u64 ) {
65
+ pub fn record_completed_jobs ( & self , experiment : & str , amount : u64 ) {
67
66
self . crater_completed_jobs_total
68
- . with_label_values ( & [ agent , experiment] )
67
+ . with_label_values ( & [ experiment] )
69
68
. inc_by ( amount) ;
70
69
}
71
70
72
- fn get_metric_by_name ( name : & str ) -> Option < MetricFamily > {
73
- let families = prometheus:: gather ( ) ;
74
- families. into_iter ( ) . find ( |fam| fam. get_name ( ) == name)
75
- }
76
-
77
- fn get_label_by_name < ' a > ( metric : & ' a Metric , label : & str ) -> Option < & ' a str > {
78
- metric
79
- . get_label ( )
80
- . iter ( )
81
- . find ( |lab| lab. get_name ( ) == label)
82
- . map ( |lab| lab. get_value ( ) )
83
- }
84
-
85
71
fn remove_experiment_jobs ( & self , experiment : & str ) -> Fallible < ( ) > {
86
- if let Some ( metric) = Self :: get_metric_by_name ( JOBS_METRIC ) {
87
- let agents = metric
88
- . get_metric ( )
89
- . iter ( )
90
- . filter ( |met| Self :: get_label_by_name ( met, "experiment" ) . unwrap ( ) == experiment)
91
- . map ( |met| Self :: get_label_by_name ( met, "agent" ) . unwrap ( ) )
92
- . collect :: < Vec < & str > > ( ) ;
93
-
94
- for agent in agents. iter ( ) {
95
- self . crater_completed_jobs_total
96
- . remove_label_values ( & [ agent, experiment] ) ?;
97
- }
98
- }
72
+ self . crater_completed_jobs_total
73
+ . remove_label_values ( & [ experiment] ) ?;
99
74
100
75
Ok ( ( ) )
101
76
}
@@ -143,12 +118,27 @@ mod tests {
143
118
use crate :: server:: tokens:: Tokens ;
144
119
use chrono:: Utc ;
145
120
use lazy_static:: lazy_static;
146
- use prometheus:: proto:: MetricFamily ;
121
+ use prometheus:: proto:: { Metric , MetricFamily } ;
147
122
148
123
lazy_static ! {
149
124
static ref METRICS : Metrics = Metrics :: new( ) . unwrap( ) ;
150
125
}
151
126
127
+ impl Metrics {
128
+ fn get_metric_by_name ( name : & str ) -> Option < MetricFamily > {
129
+ let families = prometheus:: gather ( ) ;
130
+ families. into_iter ( ) . find ( |fam| fam. get_name ( ) == name)
131
+ }
132
+
133
+ fn get_label_by_name < ' a > ( metric : & ' a Metric , label : & str ) -> Option < & ' a str > {
134
+ metric
135
+ . get_label ( )
136
+ . iter ( )
137
+ . find ( |lab| lab. get_name ( ) == label)
138
+ . map ( |lab| lab. get_value ( ) )
139
+ }
140
+ }
141
+
152
142
fn test_experiment_presence ( metric : & MetricFamily , experiment : & str ) -> bool {
153
143
metric
154
144
. get_metric ( )
@@ -160,12 +150,9 @@ mod tests {
160
150
fn test_on_complete_experiment ( ) {
161
151
let ex1 = "pr-0" ;
162
152
let ex2 = "pr-1" ;
163
- let agent1 = "agent-1" ;
164
- let agent2 = "agent-2" ;
165
153
166
- METRICS . record_completed_jobs ( agent1, ex1, 1 ) ;
167
- METRICS . record_completed_jobs ( agent2, ex1, 1 ) ;
168
- METRICS . record_completed_jobs ( agent2, ex2, 1 ) ;
154
+ METRICS . record_completed_jobs ( ex1, 1 ) ;
155
+ METRICS . record_completed_jobs ( ex2, 1 ) ;
169
156
170
157
//test metrics are correctly registered
171
158
let jobs = Metrics :: get_metric_by_name ( JOBS_METRIC ) . unwrap ( ) ;
0 commit comments