Skip to content

Commit e649d92

Browse files
committed
download: Add cache hit metrics
1 parent b712ce7 commit e649d92

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/controllers/version/downloads.rs

+4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ pub fn download(req: &mut dyn RequestExt) -> EndpointResult {
2222

2323
let cache_key = (crate_name.to_string(), version.to_string());
2424
if let Some(version_id) = app.version_id_cacher.get(&cache_key) {
25+
app.instance_metrics.version_id_cache_hits.inc();
26+
2527
// The increment does not happen instantly, but it's deferred to be executed in a batch
2628
// along with other downloads. See crate::downloads_counter for the implementation.
2729
app.downloads_counter.increment(version_id);
2830
} else {
31+
app.instance_metrics.version_id_cache_misses.inc();
32+
2933
// When no database connection is ready unconditional redirects will be performed. This could
3034
// happen if the pool is not healthy or if an operator manually configured the application to
3135
// always perform unconditional redirects (for example as part of the mitigations for an

src/metrics/instance.rs

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ metrics! {
5050
pub downloads_select_query_execution_time: Histogram,
5151
/// Number of download requests that are not counted yet.
5252
downloads_not_counted_total: IntGauge,
53+
54+
/// Number of version ID cache hits on the download endpoint.
55+
pub version_id_cache_hits: IntCounter,
56+
/// Number of version ID cache misses on the download endpoint.
57+
pub version_id_cache_misses: IntCounter,
5358
}
5459

5560
// All instance metrics will be prefixed with this namespace.

0 commit comments

Comments
 (0)