Skip to content

Commit

Permalink
chore(capture-rs): add capture_billing_limits_loaded_tokens metric (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello authored Jul 2, 2024
1 parent 90cac52 commit b16c3d8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rust/capture/src/limiters/billing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use metrics::gauge;
use std::{collections::HashSet, ops::Sub, sync::Arc};

use crate::redis::Client;
Expand Down Expand Up @@ -86,9 +87,9 @@ impl BillingLimiter {
#[instrument(skip_all)]
async fn fetch_limited(
client: &Arc<dyn Client + Send + Sync>,
resource: QuotaResource,
resource: &QuotaResource,
) -> anyhow::Result<Vec<String>> {
let now = time::OffsetDateTime::now_utc().unix_timestamp();
let now = OffsetDateTime::now_utc().unix_timestamp();

client
.zrangebyscore(
Expand Down Expand Up @@ -130,12 +131,17 @@ impl BillingLimiter {
// On prod atm we call this around 15 times per second at peak times, and it usually
// completes in <1ms.

let set = Self::fetch_limited(&self.redis, resource).await;
let set = Self::fetch_limited(&self.redis, &resource).await;

tracing::debug!("fetched set from redis, caching");

if let Ok(set) = set {
let set = HashSet::from_iter(set.iter().cloned());
gauge!(
"capture_billing_limits_loaded_tokens",
"resource" => resource.as_str(),
)
.set(set.len() as f64);

let mut limited = self.limited.write().await;
*limited = set;
Expand Down

0 comments on commit b16c3d8

Please sign in to comment.