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

feat(server): Expose rate limits for metrics #3347

Merged
merged 14 commits into from
Mar 28, 2024
Prev Previous commit
Next Next commit
fix: Ensure namespaces are only matched on metrics
  • Loading branch information
jan-auer committed Mar 27, 2024
commit 5395933efcce44a5f0a88115c9809aeb589f2aa9
8 changes: 6 additions & 2 deletions relay-quotas/src/rate_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt;
use std::str::FromStr;
use std::time::{Duration, Instant};

use relay_base_schema::data_category::DataCategory;
use relay_base_schema::metrics::MetricNamespace;
use relay_base_schema::project::{ProjectId, ProjectKey};
use smallvec::SmallVec;
Expand Down Expand Up @@ -157,7 +158,10 @@ pub struct RateLimit {
/// A marker when this rate limit expires.
pub retry_after: RetryAfter,

/// The namespace of this rate limit.
/// The metric namespace of this rate limit.
///
/// Ignored on all data categories except for [`DataCategory::MetricBucket`]. If empty, this
/// rate limit applies to metrics of all namespaces.
pub namespace: SmallVec<[MetricNamespace; 1]>,
jan-auer marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -182,7 +186,7 @@ impl RateLimit {

/// Returns `true` if the rate limit namespace matches the namespace of the item.
fn matches_namespace(&self, scoping: ItemScoping<'_>) -> bool {
if self.namespace.is_empty() {
if self.namespace.is_empty() || scoping.category != DataCategory::MetricBucket {
true
} else if let Some(namespace) = scoping.namespace {
self.namespace.contains(&namespace)
Expand Down
Loading