Skip to content

Commit c024ea2

Browse files
committed
ref(ddm): Remove all remainders of custom metrics
1 parent 69e2c14 commit c024ea2

File tree

31 files changed

+158
-1157
lines changed

31 files changed

+158
-1157
lines changed

relay-base-schema/src/metrics/mri.rs

+16-69
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ pub enum MetricNamespace {
112112
Transactions,
113113
/// Metrics extracted from spans.
114114
Spans,
115-
/// User-defined metrics directly sent by SDKs and applications.
116-
Custom,
117-
/// Metric stats.
118-
///
119-
/// Metrics about metrics.
120-
Stats,
121115
/// An unknown and unsupported metric.
122116
///
123117
/// Metrics that Relay either doesn't know or recognize the namespace of will be dropped before
@@ -132,30 +126,21 @@ pub enum MetricNamespace {
132126

133127
impl MetricNamespace {
134128
/// Returns all namespaces/variants of this enum.
135-
pub fn all() -> [Self; 6] {
129+
pub fn all() -> [Self; 4] {
136130
[
137131
Self::Sessions,
138132
Self::Transactions,
139133
Self::Spans,
140-
Self::Custom,
141-
Self::Stats,
142134
Self::Unsupported,
143135
]
144136
}
145137

146-
/// Returns `true` if metric stats are enabled for this namespace.
147-
pub fn has_metric_stats(&self) -> bool {
148-
matches!(self, Self::Custom)
149-
}
150-
151138
/// Returns the string representation for this metric type.
152139
pub fn as_str(&self) -> &'static str {
153140
match self {
154141
Self::Sessions => "sessions",
155142
Self::Transactions => "transactions",
156143
Self::Spans => "spans",
157-
Self::Custom => "custom",
158-
Self::Stats => "metric_stats",
159144
Self::Unsupported => "unsupported",
160145
}
161146
}
@@ -169,8 +154,6 @@ impl std::str::FromStr for MetricNamespace {
169154
"sessions" => Ok(Self::Sessions),
170155
"transactions" => Ok(Self::Transactions),
171156
"spans" => Ok(Self::Spans),
172-
"custom" => Ok(Self::Custom),
173-
"metric_stats" => Ok(Self::Stats),
174157
_ => Ok(Self::Unsupported),
175158
}
176159
}
@@ -269,7 +252,7 @@ impl<'a> MetricResourceIdentifier<'a> {
269252

270253
let (namespace, name) = match name_and_namespace.split_once('/') {
271254
Some((raw_namespace, name)) => (raw_namespace.parse()?, name),
272-
None => (MetricNamespace::Custom, name_and_namespace),
255+
None => return Err(ParseMetricError),
273256
};
274257

275258
let name = crate::metrics::try_normalize_metric_name(name).ok_or(ParseMetricError)?;
@@ -346,7 +329,7 @@ fn parse_name_unit(string: &str) -> Option<(&str, MetricUnit)> {
346329

347330
#[cfg(test)]
348331
mod tests {
349-
use crate::metrics::{CustomUnit, DurationUnit};
332+
use crate::metrics::DurationUnit;
350333

351334
use super::*;
352335

@@ -368,38 +351,24 @@ mod tests {
368351

369352
#[test]
370353
fn test_parse_mri_lenient() {
354+
assert!(MetricResourceIdentifier::parse("c:foo@none").is_err(),);
355+
assert!(MetricResourceIdentifier::parse("c:foo@something").is_err());
356+
assert!(MetricResourceIdentifier::parse("foo").is_err());
357+
371358
assert_eq!(
372-
MetricResourceIdentifier::parse("c:foo@none").unwrap(),
373-
MetricResourceIdentifier {
374-
ty: MetricType::Counter,
375-
namespace: MetricNamespace::Custom,
376-
name: "foo".into(),
377-
unit: MetricUnit::None,
378-
},
379-
);
380-
assert_eq!(
381-
MetricResourceIdentifier::parse("c:foo").unwrap(),
382-
MetricResourceIdentifier {
383-
ty: MetricType::Counter,
384-
namespace: MetricNamespace::Custom,
385-
name: "foo".into(),
386-
unit: MetricUnit::None,
387-
},
388-
);
389-
assert_eq!(
390-
MetricResourceIdentifier::parse("c:custom/foo").unwrap(),
359+
MetricResourceIdentifier::parse("c:transactions/foo").unwrap(),
391360
MetricResourceIdentifier {
392361
ty: MetricType::Counter,
393-
namespace: MetricNamespace::Custom,
362+
namespace: MetricNamespace::Transactions,
394363
name: "foo".into(),
395364
unit: MetricUnit::None,
396365
},
397366
);
398367
assert_eq!(
399-
MetricResourceIdentifier::parse("c:custom/foo@millisecond").unwrap(),
368+
MetricResourceIdentifier::parse("c:transactions/foo@millisecond").unwrap(),
400369
MetricResourceIdentifier {
401370
ty: MetricType::Counter,
402-
namespace: MetricNamespace::Custom,
371+
namespace: MetricNamespace::Transactions,
403372
name: "foo".into(),
404373
unit: MetricUnit::Duration(DurationUnit::MilliSecond),
405374
},
@@ -413,32 +382,10 @@ mod tests {
413382
unit: MetricUnit::None,
414383
},
415384
);
416-
assert_eq!(
417-
MetricResourceIdentifier::parse("c:foo@something").unwrap(),
418-
MetricResourceIdentifier {
419-
ty: MetricType::Counter,
420-
namespace: MetricNamespace::Custom,
421-
name: "foo".into(),
422-
unit: MetricUnit::Custom(CustomUnit::parse("something").unwrap()),
423-
},
424-
);
425-
assert!(MetricResourceIdentifier::parse("foo").is_err());
426385
}
427386

428387
#[test]
429388
fn test_invalid_names_should_normalize() {
430-
assert_eq!(
431-
MetricResourceIdentifier::parse("c:f?o").unwrap().name,
432-
"f_o"
433-
);
434-
assert_eq!(
435-
MetricResourceIdentifier::parse("c:f??o").unwrap().name,
436-
"f_o"
437-
);
438-
assert_eq!(
439-
MetricResourceIdentifier::parse("c:föo").unwrap().name,
440-
"f_o"
441-
);
442389
assert_eq!(
443390
MetricResourceIdentifier::parse("c:custom/f?o")
444391
.unwrap()
@@ -487,10 +434,10 @@ mod tests {
487434
#[test]
488435
fn test_normalize_dash_to_underscore() {
489436
assert_eq!(
490-
MetricResourceIdentifier::parse("d:foo.bar.blob-size@second").unwrap(),
437+
MetricResourceIdentifier::parse("d:transactions/foo.bar.blob-size@second").unwrap(),
491438
MetricResourceIdentifier {
492439
ty: MetricType::Distribution,
493-
namespace: MetricNamespace::Custom,
440+
namespace: MetricNamespace::Transactions,
494441
name: "foo.bar.blob_size".into(),
495442
unit: MetricUnit::Duration(DurationUnit::Second),
496443
},
@@ -506,7 +453,7 @@ mod tests {
506453
.unwrap(),
507454
MetricResourceIdentifier {
508455
ty: MetricType::Counter,
509-
namespace: MetricNamespace::Custom,
456+
namespace: MetricNamespace::Unsupported,
510457
name: "foo".into(),
511458
unit: MetricUnit::Duration(DurationUnit::MilliSecond),
512459
},
@@ -518,12 +465,12 @@ mod tests {
518465
assert_eq!(
519466
serde_json::to_string(&MetricResourceIdentifier {
520467
ty: MetricType::Counter,
521-
namespace: MetricNamespace::Custom,
468+
namespace: MetricNamespace::Transactions,
522469
name: "foo".into(),
523470
unit: MetricUnit::Duration(DurationUnit::MilliSecond),
524471
})
525472
.unwrap(),
526-
"\"c:custom/foo@millisecond\"".to_owned(),
473+
"\"c:transactions/foo@millisecond\"".to_owned(),
527474
);
528475
}
529476
}

relay-base-schema/src/metrics/name.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ impl MetricName {
2626
///
2727
/// let name = MetricName::from("cfoo");
2828
/// assert!(name.try_type().is_none());
29-
/// let name = MetricName::from("c:custom/foo@none");
29+
/// let name = MetricName::from("c:spans/foo@none");
3030
/// assert_eq!(name.try_type(), Some(MetricType::Counter));
31-
/// let name = MetricName::from("d:custom/foo@none");
31+
/// let name = MetricName::from("d:spans/foo@none");
3232
/// assert_eq!(name.try_type(), Some(MetricType::Distribution));
33-
/// let name = MetricName::from("s:custom/foo@none");
33+
/// let name = MetricName::from("s:spans/foo@none");
3434
/// assert_eq!(name.try_type(), Some(MetricType::Set));
35-
/// let name = MetricName::from("g:custom/foo@none");
35+
/// let name = MetricName::from("g:spans/foo@none");
3636
/// assert_eq!(name.try_type(), Some(MetricType::Gauge));
3737
/// ```
3838
pub fn try_type(&self) -> Option<MetricType> {
@@ -56,11 +56,11 @@ impl MetricName {
5656
///
5757
/// let name = MetricName::from("foo");
5858
/// assert_eq!(name.namespace(), MetricNamespace::Unsupported);
59-
/// let name = MetricName::from("c:custom_oops/foo@none");
59+
/// let name = MetricName::from("c:spans_oops/foo@none");
6060
/// assert_eq!(name.namespace(), MetricNamespace::Unsupported);
6161
///
62-
/// let name = MetricName::from("c:custom/foo@none");
63-
/// assert_eq!(name.namespace(), MetricNamespace::Custom);
62+
/// let name = MetricName::from("c:spans/foo@none");
63+
/// assert_eq!(name.namespace(), MetricNamespace::Spans);
6464
/// ```
6565
pub fn namespace(&self) -> MetricNamespace {
6666
self.try_namespace().unwrap_or(MetricNamespace::Unsupported)
@@ -77,11 +77,11 @@ impl MetricName {
7777
///
7878
/// let name = MetricName::from("foo");
7979
/// assert!(name.try_namespace().is_none());
80-
/// let name = MetricName::from("c:custom_oops/foo@none");
80+
/// let name = MetricName::from("c:spans_oops/foo@none");
8181
/// assert!(name.try_namespace().is_none());
8282
///
83-
/// let name = MetricName::from("c:custom/foo@none");
84-
/// assert_eq!(name.try_namespace(), Some(MetricNamespace::Custom));
83+
/// let name = MetricName::from("c:spans/foo@none");
84+
/// assert_eq!(name.try_namespace(), Some(MetricNamespace::Spans));
8585
/// ```
8686
pub fn try_namespace(&self) -> Option<MetricNamespace> {
8787
// A well formed MRI is always in the format `<type>:<namespace>/<name>[@<unit>]`,

relay-cardinality/benches/redis_impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Params {
106106
.map(|i| {
107107
Entry::new(
108108
EntryId(i),
109-
MetricNamespace::Custom,
109+
MetricNamespace::Spans,
110110
&self.names[i % self.names.len()],
111111
u32::MAX - (i as u32),
112112
)
@@ -128,7 +128,7 @@ impl Params {
128128
.map(|i| {
129129
Entry::new(
130130
EntryId(i),
131-
MetricNamespace::Custom,
131+
MetricNamespace::Spans,
132132
&self.names[i % self.names.len()],
133133
hash.fetch_sub(1, Ordering::SeqCst),
134134
)
@@ -142,7 +142,7 @@ impl Params {
142142
fn never_entry(&self) -> Entry<'_> {
143143
Entry::new(
144144
EntryId(usize::MAX),
145-
MetricNamespace::Custom,
145+
MetricNamespace::Spans,
146146
&self.names[0],
147147
0,
148148
)
@@ -154,7 +154,7 @@ impl Params {
154154
.map(|i| {
155155
Entry::new(
156156
EntryId(usize::MAX - i),
157-
MetricNamespace::Custom,
157+
MetricNamespace::Spans,
158158
&self.names[i % self.names.len()],
159159
i as u32,
160160
)

relay-cardinality/src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ mod tests {
106106
},
107107
limit: 1337,
108108
scope: CardinalityScope::Organization,
109-
namespace: Some(MetricNamespace::Custom),
109+
namespace: Some(MetricNamespace::Sessions),
110110
};
111111

112112
let j = serde_json::to_string(&limit).unwrap();
@@ -117,7 +117,7 @@ mod tests {
117117
"window":{"windowSeconds":3600,"granularitySeconds":200},
118118
"limit":1337,
119119
"scope":"organization",
120-
"namespace":"custom"
120+
"namespace":"sessions"
121121
}"#;
122122
assert_eq!(serde_json::from_str::<CardinalityLimit>(j).unwrap(), limit);
123123
}

relay-cardinality/src/limiter.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ mod tests {
589589
Item::new(0, MetricNamespace::Sessions),
590590
Item::new(1, MetricNamespace::Transactions),
591591
Item::new(2, MetricNamespace::Spans),
592-
Item::new(3, MetricNamespace::Custom),
593-
Item::new(4, MetricNamespace::Custom),
592+
Item::new(3, MetricNamespace::Unsupported),
593+
Item::new(4, MetricNamespace::Unsupported),
594594
Item::new(5, MetricNamespace::Transactions),
595595
Item::new(6, MetricNamespace::Spans),
596596
];
@@ -605,15 +605,15 @@ mod tests {
605605
vec![
606606
(Item::new(0, MetricNamespace::Sessions), &limits[0]),
607607
(Item::new(2, MetricNamespace::Spans), &limits[0]),
608-
(Item::new(4, MetricNamespace::Custom), &limits[0]),
608+
(Item::new(4, MetricNamespace::Unsupported), &limits[0]),
609609
(Item::new(6, MetricNamespace::Spans), &limits[0]),
610610
]
611611
);
612612
assert_eq!(
613613
split.accepted,
614614
vec![
615615
Item::new(1, MetricNamespace::Transactions),
616-
Item::new(3, MetricNamespace::Custom),
616+
Item::new(3, MetricNamespace::Unsupported),
617617
Item::new(5, MetricNamespace::Transactions),
618618
]
619619
);
@@ -671,12 +671,12 @@ mod tests {
671671
];
672672

673673
let items = vec![
674-
Item::new(0, MetricNamespace::Custom),
675-
Item::new(1, MetricNamespace::Custom),
676-
Item::new(2, MetricNamespace::Custom),
677-
Item::new(3, MetricNamespace::Custom),
678-
Item::new(4, MetricNamespace::Custom),
679-
Item::new(5, MetricNamespace::Custom),
674+
Item::new(0, MetricNamespace::Spans),
675+
Item::new(1, MetricNamespace::Spans),
676+
Item::new(2, MetricNamespace::Spans),
677+
Item::new(3, MetricNamespace::Spans),
678+
Item::new(4, MetricNamespace::Spans),
679+
Item::new(5, MetricNamespace::Spans),
680680
];
681681
let limited = limiter
682682
.check_cardinality_limits(build_scoping(), limits, items)
@@ -689,17 +689,17 @@ mod tests {
689689
assert_eq!(
690690
split.rejected,
691691
vec![
692-
(Item::new(0, MetricNamespace::Custom), &limits[0]),
693-
(Item::new(2, MetricNamespace::Custom), &limits[0]),
694-
(Item::new(4, MetricNamespace::Custom), &limits[0]),
692+
(Item::new(0, MetricNamespace::Spans), &limits[0]),
693+
(Item::new(2, MetricNamespace::Spans), &limits[0]),
694+
(Item::new(4, MetricNamespace::Spans), &limits[0]),
695695
]
696696
);
697697
assert_eq!(
698698
split.accepted,
699699
vec![
700-
Item::new(1, MetricNamespace::Custom),
701-
Item::new(3, MetricNamespace::Custom),
702-
Item::new(5, MetricNamespace::Custom),
700+
Item::new(1, MetricNamespace::Spans),
701+
Item::new(3, MetricNamespace::Spans),
702+
Item::new(5, MetricNamespace::Spans),
703703
]
704704
);
705705
}
@@ -795,7 +795,7 @@ mod tests {
795795
},
796796
];
797797
let scoping = build_scoping();
798-
let items = vec![Item::new(0, MetricNamespace::Custom)];
798+
let items = vec![Item::new(0, MetricNamespace::Spans)];
799799

800800
let limiter = CardinalityLimiter::new(CreateReports);
801801
let limited = limiter

0 commit comments

Comments
 (0)