Skip to content

Commit

Permalink
Fix metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinquaXD committed Oct 26, 2024
1 parent 857a42d commit 9c7c4d3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions crates/shared/src/request_sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ where

fn collect_garbage(cache: &Cache<Request, Fut>, label: &str) {
let mut cache = cache.lock().unwrap();
let len_before = cache.len() as u64;
cache.retain(|_request, weak| weak.upgrade().is_some());
Metrics::get()
.request_sharing_cached_items
.with_label_values(&[label])
.sub(len_before - cache.len() as u64);
.set(cache.len() as u64);
}

fn spawn_gc(cache: Cache<Request, Fut>, label: String) {
Expand All @@ -76,11 +75,10 @@ where

impl<A, B: Future> Drop for RequestSharing<A, B> {
fn drop(&mut self) {
let cache = self.in_flight.lock().unwrap();
Metrics::get()
.request_sharing_cached_items
.with_label_values(&[&self.request_label])
.sub(cache.len() as u64);
.set(0);
}
}

Expand Down Expand Up @@ -130,7 +128,7 @@ where
Metrics::get()
.request_sharing_cached_items
.with_label_values(&[&self.request_label])
.inc();
.set(in_flight.len() as u64);
shared
}
}
Expand Down

0 comments on commit 9c7c4d3

Please sign in to comment.