diff --git a/relay-config/src/config.rs b/relay-config/src/config.rs index d93ec83d1b3..13010fbcc41 100644 --- a/relay-config/src/config.rs +++ b/relay-config/src/config.rs @@ -775,6 +775,8 @@ pub enum KafkaTopic { OutcomesBilling, /// Session health updates. Sessions, + /// The default topic for metrics. We use this mainly for tests at the moment. + MetricsDefault, /// Any metric that is extracted from sessions. MetricsSessions, /// Any metric that is extracted from transactions. @@ -821,6 +823,7 @@ impl TopicAssignments { KafkaTopic::Outcomes => &self.outcomes, KafkaTopic::OutcomesBilling => self.outcomes_billing.as_ref().unwrap_or(&self.outcomes), KafkaTopic::Sessions => &self.sessions, + KafkaTopic::MetricsDefault => &self.metrics, KafkaTopic::MetricsSessions => self.metrics_sessions.as_ref().unwrap_or(&self.metrics), KafkaTopic::MetricsTransactions => { self.metrics_transactions.as_ref().unwrap_or(&self.metrics) diff --git a/relay-metrics/src/protocol.rs b/relay-metrics/src/protocol.rs index 4a1d37c6a1b..037c9d77a78 100644 --- a/relay-metrics/src/protocol.rs +++ b/relay-metrics/src/protocol.rs @@ -176,7 +176,7 @@ impl std::str::FromStr for MetricResourceIdentifier { let (raw_ty, rest) = name.split_once(':').ok_or(ParseMetricError(()))?; let ty = raw_ty.parse()?; - let (raw_namespace, rest) = rest.split_once('/').ok_or(ParseMetricError(()))?; + let (raw_namespace, rest) = rest.split_once('/').unwrap_or(("custom", rest)); let namespace = raw_namespace.to_owned(); let (name, unit) = parse_name_unit(rest).ok_or(ParseMetricError(()))?; @@ -552,12 +552,12 @@ mod tests { #[test] fn test_parse_counter() { - let s = "transactions/foo:42|c"; + let s = "foo:42|c"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); insta::assert_debug_snapshot!(metric, @r###" Metric { - name: "c:transactions/foo", + name: "c:foo", unit: None, value: Counter( 42.0, @@ -570,12 +570,12 @@ mod tests { #[test] fn test_parse_distribution() { - let s = "transactions/foo:17.5|d"; + let s = "foo:17.5|d"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); insta::assert_debug_snapshot!(metric, @r###" Metric { - name: "d:transactions/foo", + name: "d:foo", unit: None, value: Distribution( 17.5, @@ -588,7 +588,7 @@ mod tests { #[test] fn test_parse_histogram() { - let s = "transactions/foo:17.5|h"; // common alias for distribution + let s = "foo:17.5|h"; // common alias for distribution let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); assert_eq!(metric.value, MetricValue::Distribution(17.5)); @@ -596,12 +596,12 @@ mod tests { #[test] fn test_parse_set() { - let s = "transactions/foo:e2546e4c-ecd0-43ad-ae27-87960e57a658|s"; + let s = "foo:e2546e4c-ecd0-43ad-ae27-87960e57a658|s"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); insta::assert_debug_snapshot!(metric, @r###" Metric { - name: "s:transactions/foo", + name: "s:foo", unit: None, value: Set( 4267882815, @@ -614,12 +614,12 @@ mod tests { #[test] fn test_parse_gauge() { - let s = "transactions/foo:42|g"; + let s = "foo:42|g"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); insta::assert_debug_snapshot!(metric, @r###" Metric { - name: "g:transactions/foo", + name: "g:foo", unit: None, value: Gauge( 42.0, @@ -632,7 +632,7 @@ mod tests { #[test] fn test_parse_unit() { - let s = "transactions/foo@second:17.5|d"; + let s = "foo@second:17.5|d"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); assert_eq!(metric.unit, MetricUnit::Duration(DurationUnit::Second)); @@ -640,7 +640,7 @@ mod tests { #[test] fn test_parse_unit_regression() { - let s = "transactions/foo@s:17.5|d"; + let s = "foo@s:17.5|d"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); assert_eq!(metric.unit, MetricUnit::Duration(DurationUnit::Second)); @@ -648,7 +648,7 @@ mod tests { #[test] fn test_parse_tags() { - let s = "transactions/foo:17.5|d|#foo,bar:baz"; + let s = "foo:17.5|d|#foo,bar:baz"; let timestamp = UnixTimestamp::from_secs(4711); let metric = Metric::parse(s.as_bytes(), timestamp).unwrap(); insta::assert_debug_snapshot!(metric.tags, @r###" @@ -745,7 +745,7 @@ mod tests { #[test] fn test_parse_all() { - let s = "transactions/foo:42|c\nbar:17|c"; + let s = "foo:42|c\nbar:17|c"; let timestamp = UnixTimestamp::from_secs(4711); let metrics: Vec = Metric::parse_all(s.as_bytes(), timestamp) @@ -757,7 +757,7 @@ mod tests { #[test] fn test_parse_all_crlf() { - let s = "transactions/foo:42|c\r\nbar:17|c"; + let s = "foo:42|c\r\nbar:17|c"; let timestamp = UnixTimestamp::from_secs(4711); let metrics: Vec = Metric::parse_all(s.as_bytes(), timestamp) @@ -769,7 +769,7 @@ mod tests { #[test] fn test_parse_all_empty_lines() { - let s = "transactions/foo:42|c\n\n\nbar:17|c"; + let s = "foo:42|c\n\n\nbar:17|c"; let timestamp = UnixTimestamp::from_secs(4711); let metric_count = Metric::parse_all(s.as_bytes(), timestamp).count(); @@ -778,7 +778,7 @@ mod tests { #[test] fn test_parse_all_trailing() { - let s = "transactions/foo:42|c\nbar:17|c\n"; + let s = "foo:42|c\nbar:17|c\n"; let timestamp = UnixTimestamp::from_secs(4711); let metric_count = Metric::parse_all(s.as_bytes(), timestamp).count(); diff --git a/relay-server/src/actors/store.rs b/relay-server/src/actors/store.rs index 234357fa7aa..1724c124c9d 100644 --- a/relay-server/src/actors/store.rs +++ b/relay-server/src/actors/store.rs @@ -57,6 +57,7 @@ struct Producers { attachments: Producer, transactions: Producer, sessions: Producer, + metrics_default: Producer, metrics_sessions: Producer, metrics_transactions: Producer, profiles: Producer, @@ -75,6 +76,7 @@ impl Producers { None } KafkaTopic::Sessions => Some(&self.sessions), + KafkaTopic::MetricsDefault => Some(&self.metrics_default), KafkaTopic::MetricsSessions => Some(&self.metrics_sessions), KafkaTopic::MetricsTransactions => Some(&self.metrics_transactions), KafkaTopic::Profiles => Some(&self.profiles), @@ -133,6 +135,11 @@ impl StoreForwarder { events: make_producer(&*config, &mut reused_producers, KafkaTopic::Events)?, transactions: make_producer(&*config, &mut reused_producers, KafkaTopic::Transactions)?, sessions: make_producer(&*config, &mut reused_producers, KafkaTopic::Sessions)?, + metrics_default: make_producer( + &*config, + &mut reused_producers, + KafkaTopic::MetricsDefault, + )?, metrics_sessions: make_producer( &*config, &mut reused_producers, @@ -392,13 +399,7 @@ impl StoreForwarder { Ok(MetricResourceIdentifier { namespace, .. }) if namespace == "sessions" => { KafkaTopic::MetricsSessions } - _ => { - relay_log::configure_scope(|scope| { - scope.set_extra("metric_message.name", message.name.into()); - }); - relay_log::error!("Dropping unknown metric usecase"); - return Ok(()); - } + _ => KafkaTopic::MetricsDefault, }; relay_log::trace!("Sending metric message to kafka"); diff --git a/tests/integration/test_metrics.py b/tests/integration/test_metrics.py index d172e076902..d737348e346 100644 --- a/tests/integration/test_metrics.py +++ b/tests/integration/test_metrics.py @@ -46,7 +46,7 @@ def test_metrics(mini_sentry, relay): mini_sentry.add_basic_project_config(project_id) timestamp = int(datetime.now(tz=timezone.utc).timestamp()) - metrics_payload = f"foo:42|c\ntransactions/bar:17|c" + metrics_payload = f"foo:42|c\nbar:17|c" relay.send_metrics(project_id, metrics_payload, timestamp) envelope = mini_sentry.captured_events.get(timeout=3) @@ -111,7 +111,7 @@ def test_metrics_with_processing(mini_sentry, relay_with_processing, metrics_con mini_sentry.add_full_project_config(project_id) timestamp = int(datetime.now(tz=timezone.utc).timestamp()) - metrics_payload = f"foo:42|c\ntransactions/bar@second:17|c" + metrics_payload = f"foo:42|c\nbar@second:17|c" relay.send_metrics(project_id, metrics_payload, timestamp) metrics = metrics_by_name(metrics_consumer, 2)