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(spans): Rate limit span metrics #3255

Merged
merged 48 commits into from
Mar 19, 2024
Merged

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Mar 12, 2024

Like we do for transaction metrics, limit span metrics when there is a quota defined for DataCategory::Spans.

Fixes: #3260

@jjbayer jjbayer self-assigned this Mar 13, 2024
*profiles += other.profiles;
*buckets = other.buckets;
*buckets += other.buckets;
Copy link
Member Author

Choose a reason for hiding this comment

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

I messed this up in the PR that was supposed to fix it.

count,
over_accept_once,
)
.ok() // don't limit if there was a redis error
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an important change: Previously, we would drop everything if there was a redis error. I changed this to accept everything instead, for two reasons:

  1. It is more correct IMO (we should not drop customer data if the current budget is unknown).
  2. It simplifies the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: adding point 1 as a comment in the code is valuable (same for spans below).

relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/rate_limits.rs Outdated Show resolved Hide resolved
@jjbayer jjbayer changed the title Feat/spans rate limit metrics feat(spans): Rate limit span metrics Mar 13, 2024
@jjbayer jjbayer marked this pull request as ready for review March 13, 2024 14:02
@jjbayer jjbayer requested a review from a team as a code owner March 13, 2024 14:02
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

LGTM.

I think the code around rate limiting is more complex than it should and we should, but this is not actionable for this PR.

count,
over_accept_once,
)
.ok() // don't limit if there was a redis error
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: adding point 1 as a comment in the code is valuable (same for spans below).

Comment on lines 26 to 27
/// The number of transactions contributing to these metrics.
transaction_count: usize,

/// The number of profiles contained in these metrics.
profile_count: usize,
counts: TotalEntityCounts,
Copy link
Contributor

Choose a reason for hiding this comment

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

counts also counts spans now, so something like:

-/// The number of transactions contributing to these metrics.
+/// The number of performance items (transactions, spans) contributing to these metrics.

(can't make a suggestion on a life outside of the diff)

}
};

if mri.namespace != MetricNamespace::Transactions {
return None;
if mri.namespace == MetricNamespace::Transactions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make match mri.namespace instead?

Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

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

Request changes because I think there is a logic bug in the MangedEnvelope::reject

relay-server/src/services/processor.rs Outdated Show resolved Hide resolved
relay-server/src/services/processor.rs Outdated Show resolved Hide resolved
relay-server/src/services/processor.rs Outdated Show resolved Hide resolved
relay-server/src/utils/rate_limits.rs Outdated Show resolved Hide resolved
relay-server/src/utils/rate_limits.rs Show resolved Hide resolved
Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

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

Oops forgot a file

relay-server/src/utils/metrics_rate_limits.rs Show resolved Hide resolved
@@ -45,30 +37,34 @@ const PROFILE_TAG: &str = "has_profile";
/// Additionally tracks whether the transactions also contained profiling information.
///
/// Returns `None` if the metric was not extracted from transactions.
fn count_metric_bucket(metric: BucketView<'_>, mode: ExtractionMode) -> Option<TransactionCount> {
fn count_metric_bucket(metric: BucketView<'_>, mode: ExtractionMode) -> BucketSummary {
Copy link
Member

Choose a reason for hiding this comment

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

Probably can get a better name now, something something summary?

Copy link
Member Author

Choose a reason for hiding this comment

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

How about BucketSummary::new?

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to summarize_bucket to keep the diff small.

relay-server/src/utils/metrics_rate_limits.rs Show resolved Hide resolved
.iter()
.map(|metric| count_metric_bucket(BucketView::new(metric), mode))
let buckets: Vec<_> = buckets
.into_iter()
Copy link
Member

Choose a reason for hiding this comment

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

Simplifies code, but this results in an additional allocation, which is probably fine, just wanna bring it up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it? into_iter() takes ownership of the existing vector AFAIK.

Copy link
Member

Choose a reason for hiding this comment

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

into_iter() takes ownership, but each element of the vector changes size -> needs an allocation, later we extract the buckets again -> another allocation. Instead of just having 1 allocation for the extra data.

relay-server/src/utils/metrics_rate_limits.rs Outdated Show resolved Hide resolved
tests/integration/fixtures/mini_sentry.py Show resolved Hide resolved
///
/// We do not explicitly check the rate limiter for profiles, so there is no need to
/// distinguish between `None` and `Some(0)`.
profiles: usize,
Copy link
Member

Choose a reason for hiding this comment

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

baby nit: Maybe have the profiles part of the transaction count transactions: Option<TransactionCountWithProfiles>?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that would work

relay-server/src/utils/metrics_rate_limits.rs Show resolved Hide resolved
Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

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

:shipit:

@jjbayer jjbayer enabled auto-merge (squash) March 19, 2024 09:33
@jjbayer jjbayer merged commit 20da785 into master Mar 19, 2024
20 checks passed
@jjbayer jjbayer deleted the feat/spans-rate-limit-metrics branch March 19, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rate limit span metrics
3 participants