Skip to content

Commit e3ea7fd

Browse files
committed
Auto merge of #605 - Mark-Simulacrum:endpoint-time-metric, r=Mark-Simulacrum
Record endpoint time for record_progress
2 parents 096a224 + 0e256e5 commit e3ea7fd

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/server/metrics.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ use crate::server::agents::Agent;
55
use chrono::{DateTime, Utc};
66
use prometheus::proto::{Metric, MetricFamily};
77
use prometheus::{
8-
IntCounterVec, IntGauge, IntGaugeVec, __register_counter_vec, __register_gauge,
8+
HistogramVec, IntCounterVec, IntGauge, IntGaugeVec, __register_counter_vec, __register_gauge,
99
__register_gauge_vec,
1010
};
1111

1212
const JOBS_METRIC: &str = "crater_completed_jobs_total";
1313
const AGENT_WORK_METRIC: &str = "crater_agent_supposed_to_work";
1414
const AGENT_FAILED: &str = "crater_agent_failure";
1515
const LAST_CRATES_UPDATE_METRIC: &str = "crater_last_crates_update";
16+
const ENDPOINT_TIME: &str = "crater_endpoint_time_seconds";
1617

1718
#[derive(Clone)]
1819
pub struct Metrics {
1920
crater_completed_jobs_total: IntCounterVec,
2021
crater_agent_failure: IntCounterVec,
2122
crater_work_status: IntGaugeVec,
2223
crater_last_crates_update: IntGauge,
24+
pub crater_endpoint_time: HistogramVec,
2325
}
2426

2527
impl Metrics {
@@ -35,12 +37,20 @@ impl Metrics {
3537
let crates_update_opts =
3638
prometheus::opts!(LAST_CRATES_UPDATE_METRIC, "last update of crates lists");
3739
let crater_last_crates_update = prometheus::register_int_gauge!(crates_update_opts)?;
40+
let crater_endpoint_time = prometheus::register_histogram_vec!(
41+
prometheus::HistogramOpts::new(ENDPOINT_TIME, "duration of endpoint requests")
42+
// Exponential buckets, with 5ms as start and top bucket ending at
43+
// approximately 5 seconds.
44+
.buckets(prometheus::exponential_buckets(0.005, 1.5, 17).unwrap()),
45+
&["endpoint"]
46+
)?;
3847

3948
Ok(Metrics {
4049
crater_completed_jobs_total,
4150
crater_agent_failure,
4251
crater_work_status,
4352
crater_last_crates_update,
53+
crater_endpoint_time,
4454
})
4555
}
4656

src/server/routes/agent.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ fn endpoint_record_progress(
159159
mutex: Arc<Mutex<Data>>,
160160
auth: AuthDetails,
161161
) -> Fallible<Response<Body>> {
162+
let start = std::time::Instant::now();
162163
let data = mutex.lock().unwrap();
163164
let ex = Experiment::get(&data.db, &result.experiment_name)?
164165
.ok_or_else(|| err_msg("no experiment run by this agent"))?;
@@ -169,7 +170,12 @@ fn endpoint_record_progress(
169170
let db = DatabaseDB::new(&data.db);
170171
db.store(&ex, &result.data, EncodingType::Gzip)?;
171172

172-
Ok(ApiResponse::Success { result: true }.into_response()?)
173+
let ret = Ok(ApiResponse::Success { result: true }.into_response()?);
174+
data.metrics
175+
.crater_endpoint_time
176+
.with_label_values(&["record_progress"])
177+
.observe(start.elapsed().as_secs_f64());
178+
ret
173179
}
174180

175181
fn endpoint_heartbeat(data: Arc<Data>, auth: AuthDetails) -> Fallible<Response<Body>> {

0 commit comments

Comments
 (0)