Skip to content

Commit 25f7bb6

Browse files
committed
measure how long it takes to execute the SELECT in the download endpoint
1 parent 81c848b commit 25f7bb6

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/controllers/version/downloads.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ use chrono::{Duration, NaiveDate, Utc};
1414
/// This returns a URL to the location where the crate is stored.
1515
pub fn download(req: &mut dyn RequestExt) -> EndpointResult {
1616
let app = req.app().clone();
17-
let recorder = req.timing_recorder();
1817

1918
let mut crate_name = req.params()["crate_id"].clone();
2019
let version = req.params()["version"].as_str();
2120

2221
let mut log_metadata = None;
23-
match recorder.record("get_conn", || req.db_conn()) {
22+
match req.db_conn() {
2423
Ok(conn) => {
2524
use self::versions::dsl::*;
2625

2726
// Returns the crate name as stored in the database, or an error if we could
2827
// not load the version ID from the database.
29-
let (version_id, canonical_crate_name) = recorder.record("get_version", || {
30-
versions
31-
.inner_join(crates::table)
32-
.select((id, crates::name))
33-
.filter(Crate::with_name(&crate_name))
34-
.filter(num.eq(version))
35-
.first::<(i32, String)>(&*conn)
36-
})?;
28+
let (version_id, canonical_crate_name) = app
29+
.instance_metrics
30+
.downloads_select_query_execution_time
31+
.observe_closure_duration(|| {
32+
versions
33+
.inner_join(crates::table)
34+
.select((id, crates::name))
35+
.filter(Crate::with_name(&crate_name))
36+
.filter(num.eq(version))
37+
.first::<(i32, String)>(&*conn)
38+
})?;
3739

3840
if canonical_crate_name != crate_name {
3941
app.instance_metrics

src/metrics/instance.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use crate::util::errors::AppResult;
2121
use crate::{app::App, db::DieselPool};
2222
use prometheus::{
23-
proto::MetricFamily, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec,
23+
proto::MetricFamily, Histogram, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec,
2424
};
2525

2626
metrics! {
@@ -46,6 +46,8 @@ metrics! {
4646
pub downloads_unconditional_redirects_total: IntCounter,
4747
/// Number of download requests with a non-canonical crate name.
4848
pub downloads_non_canonical_crate_name_total: IntCounter,
49+
/// How long it takes to execute the SELECT query in the download endpoint.
50+
pub downloads_select_query_execution_time: Histogram,
4951
/// Number of download requests that are not counted yet.
5052
downloads_not_counted_total: IntGauge,
5153
}

0 commit comments

Comments
 (0)