Skip to content

Commit ec63f36

Browse files
committed
fix tests
1 parent 44f0baf commit ec63f36

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

relay-config/src/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ pub enum KafkaTopic {
775775
OutcomesBilling,
776776
/// Session health updates.
777777
Sessions,
778+
/// The default topic for metrics. We use this mainly for tests at the moment.
779+
MetricsDefault,
778780
/// Any metric that is extracted from sessions.
779781
MetricsSessions,
780782
/// Any metric that is extracted from transactions.
@@ -821,6 +823,7 @@ impl TopicAssignments {
821823
KafkaTopic::Outcomes => &self.outcomes,
822824
KafkaTopic::OutcomesBilling => self.outcomes_billing.as_ref().unwrap_or(&self.outcomes),
823825
KafkaTopic::Sessions => &self.sessions,
826+
KafkaTopic::MetricsDefault => &self.metrics,
824827
KafkaTopic::MetricsSessions => self.metrics_sessions.as_ref().unwrap_or(&self.metrics),
825828
KafkaTopic::MetricsTransactions => {
826829
self.metrics_transactions.as_ref().unwrap_or(&self.metrics)

relay-metrics/src/protocol.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl std::str::FromStr for MetricResourceIdentifier {
176176
let (raw_ty, rest) = name.split_once(':').ok_or(ParseMetricError(()))?;
177177
let ty = raw_ty.parse()?;
178178

179-
let (raw_namespace, rest) = rest.split_once('/').ok_or(ParseMetricError(()))?;
179+
let (raw_namespace, rest) = rest.split_once('/').unwrap_or(("custom", rest));
180180
let namespace = raw_namespace.to_owned();
181181

182182
let (name, unit) = parse_name_unit(rest).ok_or(ParseMetricError(()))?;
@@ -552,12 +552,12 @@ mod tests {
552552

553553
#[test]
554554
fn test_parse_counter() {
555-
let s = "transactions/foo:42|c";
555+
let s = "foo:42|c";
556556
let timestamp = UnixTimestamp::from_secs(4711);
557557
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
558558
insta::assert_debug_snapshot!(metric, @r###"
559559
Metric {
560-
name: "c:transactions/foo",
560+
name: "c:foo",
561561
unit: None,
562562
value: Counter(
563563
42.0,
@@ -570,12 +570,12 @@ mod tests {
570570

571571
#[test]
572572
fn test_parse_distribution() {
573-
let s = "transactions/foo:17.5|d";
573+
let s = "foo:17.5|d";
574574
let timestamp = UnixTimestamp::from_secs(4711);
575575
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
576576
insta::assert_debug_snapshot!(metric, @r###"
577577
Metric {
578-
name: "d:transactions/foo",
578+
name: "d:foo",
579579
unit: None,
580580
value: Distribution(
581581
17.5,
@@ -588,20 +588,20 @@ mod tests {
588588

589589
#[test]
590590
fn test_parse_histogram() {
591-
let s = "transactions/foo:17.5|h"; // common alias for distribution
591+
let s = "foo:17.5|h"; // common alias for distribution
592592
let timestamp = UnixTimestamp::from_secs(4711);
593593
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
594594
assert_eq!(metric.value, MetricValue::Distribution(17.5));
595595
}
596596

597597
#[test]
598598
fn test_parse_set() {
599-
let s = "transactions/foo:e2546e4c-ecd0-43ad-ae27-87960e57a658|s";
599+
let s = "foo:e2546e4c-ecd0-43ad-ae27-87960e57a658|s";
600600
let timestamp = UnixTimestamp::from_secs(4711);
601601
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
602602
insta::assert_debug_snapshot!(metric, @r###"
603603
Metric {
604-
name: "s:transactions/foo",
604+
name: "s:foo",
605605
unit: None,
606606
value: Set(
607607
4267882815,
@@ -614,12 +614,12 @@ mod tests {
614614

615615
#[test]
616616
fn test_parse_gauge() {
617-
let s = "transactions/foo:42|g";
617+
let s = "foo:42|g";
618618
let timestamp = UnixTimestamp::from_secs(4711);
619619
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
620620
insta::assert_debug_snapshot!(metric, @r###"
621621
Metric {
622-
name: "g:transactions/foo",
622+
name: "g:foo",
623623
unit: None,
624624
value: Gauge(
625625
42.0,
@@ -632,23 +632,23 @@ mod tests {
632632

633633
#[test]
634634
fn test_parse_unit() {
635-
let s = "transactions/foo@second:17.5|d";
635+
let s = "foo@second:17.5|d";
636636
let timestamp = UnixTimestamp::from_secs(4711);
637637
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
638638
assert_eq!(metric.unit, MetricUnit::Duration(DurationUnit::Second));
639639
}
640640

641641
#[test]
642642
fn test_parse_unit_regression() {
643-
let s = "transactions/foo@s:17.5|d";
643+
let s = "foo@s:17.5|d";
644644
let timestamp = UnixTimestamp::from_secs(4711);
645645
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
646646
assert_eq!(metric.unit, MetricUnit::Duration(DurationUnit::Second));
647647
}
648648

649649
#[test]
650650
fn test_parse_tags() {
651-
let s = "transactions/foo:17.5|d|#foo,bar:baz";
651+
let s = "foo:17.5|d|#foo,bar:baz";
652652
let timestamp = UnixTimestamp::from_secs(4711);
653653
let metric = Metric::parse(s.as_bytes(), timestamp).unwrap();
654654
insta::assert_debug_snapshot!(metric.tags, @r###"
@@ -745,7 +745,7 @@ mod tests {
745745

746746
#[test]
747747
fn test_parse_all() {
748-
let s = "transactions/foo:42|c\nbar:17|c";
748+
let s = "foo:42|c\nbar:17|c";
749749
let timestamp = UnixTimestamp::from_secs(4711);
750750

751751
let metrics: Vec<Metric> = Metric::parse_all(s.as_bytes(), timestamp)
@@ -757,7 +757,7 @@ mod tests {
757757

758758
#[test]
759759
fn test_parse_all_crlf() {
760-
let s = "transactions/foo:42|c\r\nbar:17|c";
760+
let s = "foo:42|c\r\nbar:17|c";
761761
let timestamp = UnixTimestamp::from_secs(4711);
762762

763763
let metrics: Vec<Metric> = Metric::parse_all(s.as_bytes(), timestamp)
@@ -769,7 +769,7 @@ mod tests {
769769

770770
#[test]
771771
fn test_parse_all_empty_lines() {
772-
let s = "transactions/foo:42|c\n\n\nbar:17|c";
772+
let s = "foo:42|c\n\n\nbar:17|c";
773773
let timestamp = UnixTimestamp::from_secs(4711);
774774

775775
let metric_count = Metric::parse_all(s.as_bytes(), timestamp).count();
@@ -778,7 +778,7 @@ mod tests {
778778

779779
#[test]
780780
fn test_parse_all_trailing() {
781-
let s = "transactions/foo:42|c\nbar:17|c\n";
781+
let s = "foo:42|c\nbar:17|c\n";
782782
let timestamp = UnixTimestamp::from_secs(4711);
783783

784784
let metric_count = Metric::parse_all(s.as_bytes(), timestamp).count();

relay-server/src/actors/store.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct Producers {
5757
attachments: Producer,
5858
transactions: Producer,
5959
sessions: Producer,
60+
metrics_default: Producer,
6061
metrics_sessions: Producer,
6162
metrics_transactions: Producer,
6263
profiles: Producer,
@@ -75,6 +76,7 @@ impl Producers {
7576
None
7677
}
7778
KafkaTopic::Sessions => Some(&self.sessions),
79+
KafkaTopic::MetricsDefault => Some(&self.metrics_default),
7880
KafkaTopic::MetricsSessions => Some(&self.metrics_sessions),
7981
KafkaTopic::MetricsTransactions => Some(&self.metrics_transactions),
8082
KafkaTopic::Profiles => Some(&self.profiles),
@@ -133,6 +135,11 @@ impl StoreForwarder {
133135
events: make_producer(&*config, &mut reused_producers, KafkaTopic::Events)?,
134136
transactions: make_producer(&*config, &mut reused_producers, KafkaTopic::Transactions)?,
135137
sessions: make_producer(&*config, &mut reused_producers, KafkaTopic::Sessions)?,
138+
metrics_default: make_producer(
139+
&*config,
140+
&mut reused_producers,
141+
KafkaTopic::MetricsDefault,
142+
)?,
136143
metrics_sessions: make_producer(
137144
&*config,
138145
&mut reused_producers,
@@ -392,13 +399,7 @@ impl StoreForwarder {
392399
Ok(MetricResourceIdentifier { namespace, .. }) if namespace == "sessions" => {
393400
KafkaTopic::MetricsSessions
394401
}
395-
_ => {
396-
relay_log::configure_scope(|scope| {
397-
scope.set_extra("metric_message.name", message.name.into());
398-
});
399-
relay_log::error!("Dropping unknown metric usecase");
400-
return Ok(());
401-
}
402+
_ => KafkaTopic::MetricsDefault,
402403
};
403404

404405
relay_log::trace!("Sending metric message to kafka");

tests/integration/test_metrics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_metrics(mini_sentry, relay):
4646
mini_sentry.add_basic_project_config(project_id)
4747

4848
timestamp = int(datetime.now(tz=timezone.utc).timestamp())
49-
metrics_payload = f"foo:42|c\ntransactions/bar:17|c"
49+
metrics_payload = f"foo:42|c\nbar:17|c"
5050
relay.send_metrics(project_id, metrics_payload, timestamp)
5151

5252
envelope = mini_sentry.captured_events.get(timeout=3)
@@ -111,7 +111,7 @@ def test_metrics_with_processing(mini_sentry, relay_with_processing, metrics_con
111111
mini_sentry.add_full_project_config(project_id)
112112

113113
timestamp = int(datetime.now(tz=timezone.utc).timestamp())
114-
metrics_payload = f"foo:42|c\ntransactions/bar@second:17|c"
114+
metrics_payload = f"foo:42|c\nbar@second:17|c"
115115
relay.send_metrics(project_id, metrics_payload, timestamp)
116116

117117
metrics = metrics_by_name(metrics_consumer, 2)

0 commit comments

Comments
 (0)