Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional metrics #321

Merged
merged 8 commits into from
May 17, 2024
Merged

Additional metrics #321

merged 8 commits into from
May 17, 2024

Conversation

adam-cattermole
Copy link
Member

@adam-cattermole adam-cattermole commented May 10, 2024

Changes

  • Added liveness_latency histogram metric, cache_size gauge and batcher_size gauge
  • Made the datastore_partitioned metric always present
  • Ensured that we only record datastore_latency metrics if the timing data is present
  • For redis_cached we aggregate the datastore span calls by the batcher flushes
  • Refactored to store the metrics layer consumer function in a Box, enabling different consumer functions to be provided
  • Added a batcher_flush_size histogram
  • Added an eviction_listener to the cache to allow us to decrement the cache_size as well as to monitor the evicted_pending_writes in a histogram
  • Still thinking on the implementation.. but added a counter_overshoot histogram for when we add_from_authority and which pushes us over the counter max val

@adam-cattermole adam-cattermole force-pushed the additional-metrics branch 4 times, most recently from 6f0f7a3 to 629c025 Compare May 10, 2024 12:40
@adam-cattermole adam-cattermole marked this pull request as ready for review May 13, 2024 10:19
@adam-cattermole adam-cattermole marked this pull request as draft May 13, 2024 12:53
@adam-cattermole adam-cattermole force-pushed the additional-metrics branch 2 times, most recently from d1d0b07 to 055eef4 Compare May 14, 2024 12:54
@adam-cattermole adam-cattermole marked this pull request as ready for review May 15, 2024 11:57
@alexsnaps
Copy link
Member

diff --git a/limitador-server/src/metrics.rs b/limitador-server/src/metrics.rs
index b09444b..d41df57 100644
--- a/limitador-server/src/metrics.rs
+++ b/limitador-server/src/metrics.rs
@@ -1,6 +1,5 @@
 use std::collections::HashMap;
 use std::ops;
-use std::sync::Arc;
 use std::time::{Duration, Instant};
 use tracing::span::{Attributes, Id};
 use tracing::Subscriber;
@@ -73,12 +72,12 @@ impl SpanState {
 }
 
 pub struct MetricsGroup {
-    consumer: Arc<fn(Timings)>,
+    consumer: Box<fn(Timings)>,
     records: Vec<String>,
 }
 
 impl MetricsGroup {
-    pub fn new(consumer: Arc<fn(Timings)>, records: Vec<String>) -> Self {
+    pub fn new(consumer: Box<fn(Timings)>, records: Vec<String>) -> Self {
         Self { consumer, records }
     }
 }
@@ -99,7 +98,7 @@ impl MetricsLayer {
         let rec = records.iter().map(|r| r.to_string()).collect();
         self.groups
             .entry(aggregate.to_string())
-            .or_insert(MetricsGroup::new(Arc::new(consumer), rec));
+            .or_insert(MetricsGroup::new(Box::new(consumer), rec));
         self
     }
 }

Works on my computer™ 😉

@adam-cattermole adam-cattermole force-pushed the additional-metrics branch 2 times, most recently from e3ea79d to 2506b87 Compare May 16, 2024 09:22
@adam-cattermole
Copy link
Member Author

Addressed that now @alexsnaps - I think I must have been confusing things with the original implementation where I was having difficulty with the boxed function

_removal_cause: RemovalCause,
) {
gauge!("cache_size").decrement(1);
if let Ok(writes) = value.pending_writes() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't call that pending_writes... while the value got evicted from the cache, it's still in the queue! But now, when it'll get consumed, it won't have pending writes anymore... You can "just" call no_pending_writes on it. if it had none, then you can ignore this eviction, but if we start evicting entries with pending writes, it probably means you need to review your cache size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right gotcha, so instead of a histogram of the number of pending writes it'll be a (metrics) counter that increments in the case that we evict an entry with no_pending_writes().not()

@adam-cattermole adam-cattermole merged commit d6fa117 into main May 17, 2024
18 checks passed
@adam-cattermole adam-cattermole deleted the additional-metrics branch May 17, 2024 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants