From 710402179c70e183fccf214ad5bc8548879b90bd Mon Sep 17 00:00:00 2001 From: David Herberth Date: Thu, 11 Apr 2024 15:34:06 +0200 Subject: [PATCH] feat(metric-stats): Add cardinality limited outcome id (#3389) Adds the new outcome id `6` `cardinality_limited` to the outcomes enum. The outcome will already be emitted for the `METRIC_BUCKET` data category with this change, but the main purpose is to use the outcome for metric stats. --- CHANGELOG.md | 1 + relay-server/src/services/outcome.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d925e90e3..eb63560a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Allow IP addresses in metrics domain tag. ([#3365](https://github.com/getsentry/relay/pull/3365)) - Support the full unicode character set via UTF-8 encoding for metric tags submitted via the statsd format. Certain restricted characters require escape sequences, see [docs](https://develop.sentry.dev/sdk/metrics/#normalization) for the precise rules. ([#3358](https://github.com/getsentry/relay/pull/3358)) - Stop extracting count_per_segment and count_per_op metrics. ([#3380](https://github.com/getsentry/relay/pull/3380)) +- Add `cardinality_limited` outcome with id `6`. ([#3389](https://github.com/getsentry/relay/pull/3389)) - Extract `cache.item_size` and `cache.hit` metrics. ([#3371]https://github.com/getsentry/relay/pull/3371) **Internal**: diff --git a/relay-server/src/services/outcome.rs b/relay-server/src/services/outcome.rs index ab24adf486..a0bc89bcc7 100644 --- a/relay-server/src/services/outcome.rs +++ b/relay-server/src/services/outcome.rs @@ -80,6 +80,7 @@ impl OutcomeId { const INVALID: OutcomeId = OutcomeId(3); const ABUSE: OutcomeId = OutcomeId(4); const CLIENT_DISCARD: OutcomeId = OutcomeId(5); + const CARDINALITY_LIMITED: OutcomeId = OutcomeId(6); pub fn as_u8(self) -> u8 { self.0 @@ -102,6 +103,7 @@ trait TrackOutcomeLike { OutcomeId::INVALID => "invalid", OutcomeId::ABUSE => "abuse", OutcomeId::CLIENT_DISCARD => "client_discard", + OutcomeId::CARDINALITY_LIMITED => "cardinality_limited", _ => "", } } @@ -188,7 +190,7 @@ impl Outcome { Outcome::Filtered(_) | Outcome::FilteredSampling(_) => OutcomeId::FILTERED, Outcome::RateLimited(_) => OutcomeId::RATE_LIMITED, #[cfg(feature = "processing")] - Outcome::CardinalityLimited => OutcomeId::RATE_LIMITED, + Outcome::CardinalityLimited => OutcomeId::CARDINALITY_LIMITED, Outcome::Invalid(_) => OutcomeId::INVALID, Outcome::Abuse => OutcomeId::ABUSE, Outcome::ClientDiscard(_) => OutcomeId::CLIENT_DISCARD, @@ -197,17 +199,16 @@ impl Outcome { } /// Returns the `reason` code field of this outcome. - pub fn to_reason(&self) -> Option> { + pub fn to_reason(&self) -> Option> { match self { Outcome::Invalid(discard_reason) => Some(Cow::Borrowed(discard_reason.name())), Outcome::Filtered(filter_key) => Some(filter_key.clone().name()), Outcome::FilteredSampling(rule_ids) => Some(Cow::Owned(format!("Sampled:{rule_ids}"))), - //TODO can we do better ? (not re copying the string ) - Outcome::RateLimited(code_opt) => code_opt - .as_ref() - .map(|code| Cow::Owned(code.as_str().into())), + Outcome::RateLimited(code_opt) => { + code_opt.as_ref().map(|code| Cow::Borrowed(code.as_str())) + } #[cfg(feature = "processing")] - Outcome::CardinalityLimited => Some(Cow::Borrowed("cardinality_limited")), + Outcome::CardinalityLimited => None, Outcome::ClientDiscard(ref discard_reason) => Some(Cow::Borrowed(discard_reason)), Outcome::Abuse => None, Outcome::Accepted => None,