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(profiling): Add a profile data category and count profiles in an envelope to apply rate limits #1259

Merged
merged 4 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Add the client and version as `sdk` tag to extracted session metrics in the format `name/version`. ([#1248](https://github.com/getsentry/relay/pull/1248))
- Expose `shutdown_timeout` in `OverridableConfig` ([#1247](https://github.com/getsentry/relay/pull/1247))
- Raise a new InvalidCompression Outcome for invalid Unreal compression. ([#1237](https://github.com/getsentry/relay/pull/1237))
- Add a profile data category and count profiles in an envelope to apply rate limits. ([#1259](https://github.com/getsentry/relay/pull/1259))

## 22.4.0

Expand Down
1 change: 1 addition & 0 deletions py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Add protocol support for custom units on transaction measurements. ([#1256](https://github.com/getsentry/relay/pull/1256))
- Add a profile data category and count profiles in an envelope to apply rate limits. ([#1259](https://github.com/getsentry/relay/pull/1259))

## 0.8.10

Expand Down
4 changes: 4 additions & 0 deletions relay-common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub enum DataCategory {
Attachment = 4,
/// Session updates. Quantity is the number of updates in the batch.
Session = 5,
/// A profile
Profile = 6,
/// Any other data category not known by this Relay.
#[serde(other)]
Unknown = -1,
Expand All @@ -122,6 +124,7 @@ impl DataCategory {
"security" => Self::Security,
"attachment" => Self::Attachment,
"session" => Self::Session,
"profile" => Self::Profile,
_ => Self::Unknown,
}
}
Expand All @@ -135,6 +138,7 @@ impl DataCategory {
Self::Security => "security",
Self::Attachment => "attachment",
Self::Session => "session",
Self::Profile => "profile",
Self::Unknown => "unknown",
}
}
Expand Down
3 changes: 2 additions & 1 deletion relay-quotas/src/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ impl CategoryUnit {
DataCategory::Default
| DataCategory::Error
| DataCategory::Transaction
| DataCategory::Security => Some(Self::Count),
| DataCategory::Security
| DataCategory::Profile => Some(Self::Count),
DataCategory::Attachment => Some(Self::Bytes),
DataCategory::Session => Some(Self::Batched),
DataCategory::Unknown => None,
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl Item {
ItemType::Metrics => false,
ItemType::MetricBuckets => false,
ItemType::ClientReport => false,
ItemType::Profile => false,
ItemType::Profile => true,

// Since this Relay cannot interpret the semantics of this item, it does not know
// whether it requires an event or not. Depending on the strategy, this can cause two
Expand Down
17 changes: 17 additions & 0 deletions relay-server/src/utils/rate_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ pub struct EnvelopeSummary {
/// The number of all session updates.
pub session_quantity: usize,

/// The number of profiles.
pub profile_quantity: usize,

/// Indicates that the envelope contains regular attachments that do not create event payloads.
pub has_plain_attachments: bool,
}
Expand Down Expand Up @@ -156,6 +159,7 @@ impl EnvelopeSummary {
match item.ty() {
ItemType::Attachment => summary.attachment_quantity += item.len().max(1),
ItemType::Session => summary.session_quantity += 1,
ItemType::Profile => summary.profile_quantity += 1,
_ => (),
}
}
Expand Down Expand Up @@ -228,6 +232,8 @@ pub struct Enforcement {
attachments: CategoryLimit,
/// The combined session item rate limit.
sessions: CategoryLimit,
/// The combined profile item rate limit.
profiles: CategoryLimit,
}

impl Enforcement {
Expand Down Expand Up @@ -402,6 +408,17 @@ where
rate_limits.merge(session_limits);
}

if summary.profile_quantity > 0 {
let item_scoping = scoping.item(DataCategory::Profile);
let profile_limits = (self.check)(item_scoping, summary.profile_quantity)?;
enforcement.profiles = CategoryLimit::new(
DataCategory::Profile,
summary.profile_quantity,
profile_limits.longest(),
);
rate_limits.merge(profile_limits);
}

Ok((enforcement, rate_limits))
}

Expand Down