Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Oct 7, 2024
1 parent 447f8f6 commit 9d5fc17
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions relay-server/src/services/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,34 +1316,18 @@ impl EnvelopeProcessorService {
fn enforce_quotas<G>(
&self,
state: &mut ProcessEnvelopeState<G>,
) -> Result<(), ProcessingError> {
self.enforce_cached_quotas(state)?;
self.enforce_consistent_quotas(state)?;
Ok(())
}

#[cfg(feature = "processing")]
fn enforce_cached_quotas<G>(
&self,
state: &mut ProcessEnvelopeState<G>,
) -> Result<(), ProcessingError> {
let global_config = self.inner.global_config.current();
let _ = RateLimiter::Cached.enforce(&global_config, state)?;

Ok(())
}

#[cfg(feature = "processing")]
fn enforce_consistent_quotas<G>(
&self,
state: &mut ProcessEnvelopeState<G>,
) -> Result<(), ProcessingError> {
let global_config = self.inner.global_config.current();
let rate_limiter = match self.inner.rate_limiter.as_ref() {
Some(rate_limiter) => rate_limiter,
None => return Ok(()),
};

// Cached quotas first, they are quick to evaluate and some quotas (indexed) are not
// applied in the fast path, all cached quotas can be applied here.
let _ = RateLimiter::Cached.enforce(&global_config, state)?;

// Enforce all quotas consistently with Redis.
let limits = RateLimiter::Consistent(rate_limiter).enforce(&global_config, state)?;

// Update cached rate limits with the freshly computed ones.
Expand Down Expand Up @@ -1747,13 +1731,6 @@ impl EnvelopeProcessorService {
// Always extract metrics in processing Relays for sampled items.
self.extract_transaction_metrics(state, SamplingDecision::Keep, profile_id)?;

// Enforce cached quotas here, because it is relatively cheap and can prevent
// us from extracting spans when it's not necessary.
//
// But do it *after* metric extraction to make sure we do not drop due to an indexed
// quota and never extract any metrics.
self.enforce_cached_quotas(state)?;

if state
.project_info
.has_feature(Feature::ExtractSpansFromEvent)
Expand Down

0 comments on commit 9d5fc17

Please sign in to comment.