Skip to content

fix(profiling): Classify profile chunks for rate limits and outcomes #4595

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

Merged
merged 3 commits into from
Mar 21, 2025

Conversation

Dav1dde
Copy link
Member

@Dav1dde Dav1dde commented Mar 20, 2025

This separates profile chunks into two separate categories. The category is determined by the platform contained within the item payload.

This does have several downsides:

  • No outcomes are emitted until the platform can be determined.
  • Rate limits happen only in processing (this is the only code which currently extracts the platform).

The plan is to hoist the platform into an item header, provided by the SDK directly. Once this happened we can reject all profile chunks without that necessary platform item and we can start rate limiting in the fast path.

Additionally we'll change Relay to make the executive decision whether a profile chunk is frontend/backend, this means we no longer need to make that decision in multiple places (they cannot diverge).

We will also need to consider how often the platforms change, we can extend Relay in a way where unknown platforms are just forwarded to processing but for the sake of rate limiting considered as the default category. Or just make the assignment configurable via global config.

The test test_profile_chunk_outcomes_rate_limited_via_profile_duration_rate_limit was never correct, the duration quota never worked it always just worked because it also contained the chunk category, but that is equivalent to the test above.

Fixes: https://github.com/getsentry/team-ingest/issues/679

@Dav1dde Dav1dde requested a review from a team as a code owner March 20, 2025 14:36
@Dav1dde Dav1dde force-pushed the dav1d/ratelimit-profile-chunks branch 3 times, most recently from f6de8a0 to 65c2067 Compare March 20, 2025 17:13
@Dav1dde Dav1dde self-assigned this Mar 20, 2025
@Dav1dde Dav1dde force-pushed the dav1d/ratelimit-profile-chunks branch from 65c2067 to d53c559 Compare March 20, 2025 17:35
@Dav1dde Dav1dde force-pushed the dav1d/ratelimit-profile-chunks branch from d53c559 to 4df7283 Compare March 20, 2025 17:36
Copy link
Contributor

@loewenheim loewenheim left a comment

Choose a reason for hiding this comment

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

Small typo, looks good otherwise

Co-authored-by: Sebastian Zivota <loewenheim@users.noreply.github.com>
Comment on lines +315 to 320
pub fn profile_type(&self) -> ProfileType {
match self.profile.platform.as_str() {
"cocoa" | "android" | "javascript" => ProfileType::Ui,
_ => ProfileType::Backend,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

/// The profile type is currently determined based on the contained profile
/// platform. It determines the data category this profile chunk belongs to.
///
/// This needs to be synchronized with the implementation in Sentry:
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can add the profile_type in the payload before we send it, this would become the source of truth.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use add it to the Kafka message https://github.com/getsentry/relay/blob/master/relay-server/src/services/store.rs#L1035-L1041 and the worker will handle it, no need to deserialize/serialize again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that works, let's figure that out in a follow up where we wanna put it (payload / kafka header) and how it should look?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would add it to the payload and not the header, it's easier to manipulate later on.

ItemType::ProfileChunk => match item.profile_type() {
Some(ProfileType::Backend) => !self.profile_chunks.is_active(),
Some(ProfileType::Ui) => !self.profile_chunks_ui.is_active(),
None => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this reject or accept profiles when we don't have a type?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will accept when there is no type.

@phacops
Copy link
Contributor

phacops commented Mar 20, 2025

We started adding a platform field to SDKs, Relay should then classify the chunk based on this, add the type to the payload before we push to Kafka and become the source of truth.

We will also need to consider how often the platforms change

Platforms are not added very often, UI platforms even less often and rejecting the chunk for unknown/empty platforms is a good default.

@Dav1dde Dav1dde enabled auto-merge (squash) March 21, 2025 08:44
@Dav1dde Dav1dde merged commit cd67f90 into master Mar 21, 2025
25 checks passed
@Dav1dde Dav1dde deleted the dav1d/ratelimit-profile-chunks branch March 21, 2025 08:47
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.

5 participants