Skip to content

Commit 0d70386

Browse files
committed
Add prometheus counter for cache misses
1 parent df2ed74 commit 0d70386

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

src/app.rs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::cli::CommandLineArgs;
44
use crate::error::ActiveStorageError;
55
use crate::filter_pipeline;
6-
use crate::metrics::{metrics_handler, track_metrics};
6+
use crate::metrics::{metrics_handler, track_metrics, LOCAL_CACHE_MISSES};
77
use crate::models;
88
use crate::operation;
99
use crate::operations;
@@ -160,37 +160,6 @@ async fn schema() -> &'static str {
160160
"Hello, world!"
161161
}
162162

163-
// /// Download an object from S3
164-
// ///
165-
// /// Requests a byte range if `offset` or `size` is specified in the request.
166-
// ///
167-
// /// # Arguments
168-
// ///
169-
// /// * `client`: S3 client object
170-
// /// * `request_data`: RequestData object for the request
171-
// #[tracing::instrument(
172-
// level = "DEBUG",
173-
// skip(client, request_data, resource_manager, mem_permits)
174-
// )]
175-
// async fn download_object<'a>(
176-
// client: &s3_client::S3Client,
177-
// request_data: &models::RequestData,
178-
// resource_manager: &'a ResourceManager,
179-
// mem_permits: &mut Option<SemaphorePermit<'a>>,
180-
// ) -> Result<Bytes, ActiveStorageError> {
181-
// let range = s3_client::get_range(request_data.offset, request_data.size);
182-
// let _conn_permits = resource_manager.s3_connection().await?;
183-
// client
184-
// .download_object(
185-
// &request_data.bucket,
186-
// &request_data.object,
187-
// range,
188-
// resource_manager,
189-
// mem_permits,
190-
// )
191-
// .await
192-
// }
193-
194163
/// Download an object from S3
195164
///
196165
/// Requests a byte range if `offset` or `size` is specified in the request.
@@ -219,9 +188,10 @@ async fn download_object<'a>(
219188
) -> Result<Bytes, ActiveStorageError> {
220189
let range = s3_client::get_range(request_data.offset, request_data.size);
221190
// let _conn_permits = resource_manager.s3_connection().await?;
222-
// println!("{:?},{:?}", client, request_data);
223-
// TODO: Add cache hit / miss statistics?
224-
println!("Downloading object");
191+
192+
// Increment the prometheus metric for cache misses
193+
LOCAL_CACHE_MISSES.with_label_values(&["disk"]).inc();
194+
225195
client
226196
.download_object(
227197
&request_data.bucket,

src/metrics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ lazy_static! {
2525
},
2626
&["status_code", "http_method", "path"],
2727
).expect("Prometheus metric options should be valid");
28+
// Disk cache hit counter
29+
pub static ref LOCAL_CACHE_MISSES: IntCounterVec = IntCounterVec::new(
30+
Opts::new("cache_miss", "The number of times the requested chunk was not available in then local chunk cache"),
31+
&["cache"]
32+
).expect("Prometheus metric options should be valid");
2833
}
2934

3035
/// Registers various prometheus metrics with the global registry
@@ -39,6 +44,9 @@ pub fn register_metrics() {
3944
registry
4045
.register(Box::new(RESPONSE_TIME_COLLECTOR.clone()))
4146
.expect("Prometheus metrics registration should not fail during initialization");
47+
registry
48+
.register(Box::new(LOCAL_CACHE_MISSES.clone()))
49+
.expect("Prometheus metrics registration should not fail during initialization");
4250
}
4351

4452
/// Returns currently gathered prometheus metrics

0 commit comments

Comments
 (0)