Skip to content

ref(ddm): Remove all remainders of custom metrics #4564

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
85 changes: 16 additions & 69 deletions relay-base-schema/src/metrics/mri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ pub enum MetricNamespace {
Transactions,
/// Metrics extracted from spans.
Spans,
/// User-defined metrics directly sent by SDKs and applications.
Custom,
/// Metric stats.
///
/// Metrics about metrics.
Stats,
/// An unknown and unsupported metric.
///
/// Metrics that Relay either doesn't know or recognize the namespace of will be dropped before
Expand All @@ -132,30 +126,21 @@ pub enum MetricNamespace {

impl MetricNamespace {
/// Returns all namespaces/variants of this enum.
pub fn all() -> [Self; 6] {
pub fn all() -> [Self; 4] {
[
Self::Sessions,
Self::Transactions,
Self::Spans,
Self::Custom,
Self::Stats,
Self::Unsupported,
]
}

/// Returns `true` if metric stats are enabled for this namespace.
pub fn has_metric_stats(&self) -> bool {
matches!(self, Self::Custom)
}

/// Returns the string representation for this metric type.
pub fn as_str(&self) -> &'static str {
match self {
Self::Sessions => "sessions",
Self::Transactions => "transactions",
Self::Spans => "spans",
Self::Custom => "custom",
Self::Stats => "metric_stats",
Self::Unsupported => "unsupported",
}
}
Expand All @@ -169,8 +154,6 @@ impl std::str::FromStr for MetricNamespace {
"sessions" => Ok(Self::Sessions),
"transactions" => Ok(Self::Transactions),
"spans" => Ok(Self::Spans),
"custom" => Ok(Self::Custom),
"metric_stats" => Ok(Self::Stats),
_ => Ok(Self::Unsupported),
}
}
Expand Down Expand Up @@ -269,7 +252,7 @@ impl<'a> MetricResourceIdentifier<'a> {

let (namespace, name) = match name_and_namespace.split_once('/') {
Some((raw_namespace, name)) => (raw_namespace.parse()?, name),
None => (MetricNamespace::Custom, name_and_namespace),
None => return Err(ParseMetricError),
};

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

#[cfg(test)]
mod tests {
use crate::metrics::{CustomUnit, DurationUnit};
use crate::metrics::DurationUnit;

use super::*;

Expand All @@ -368,38 +351,24 @@ mod tests {

#[test]
fn test_parse_mri_lenient() {
assert!(MetricResourceIdentifier::parse("c:foo@none").is_err(),);
assert!(MetricResourceIdentifier::parse("c:foo@something").is_err());
assert!(MetricResourceIdentifier::parse("foo").is_err());

assert_eq!(
MetricResourceIdentifier::parse("c:foo@none").unwrap(),
MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
name: "foo".into(),
unit: MetricUnit::None,
},
);
assert_eq!(
MetricResourceIdentifier::parse("c:foo").unwrap(),
MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
name: "foo".into(),
unit: MetricUnit::None,
},
);
assert_eq!(
MetricResourceIdentifier::parse("c:custom/foo").unwrap(),
MetricResourceIdentifier::parse("c:transactions/foo").unwrap(),
MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
namespace: MetricNamespace::Transactions,
name: "foo".into(),
unit: MetricUnit::None,
},
);
assert_eq!(
MetricResourceIdentifier::parse("c:custom/foo@millisecond").unwrap(),
MetricResourceIdentifier::parse("c:transactions/foo@millisecond").unwrap(),
MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
namespace: MetricNamespace::Transactions,
name: "foo".into(),
unit: MetricUnit::Duration(DurationUnit::MilliSecond),
},
Expand All @@ -413,32 +382,10 @@ mod tests {
unit: MetricUnit::None,
},
);
assert_eq!(
MetricResourceIdentifier::parse("c:foo@something").unwrap(),
MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
name: "foo".into(),
unit: MetricUnit::Custom(CustomUnit::parse("something").unwrap()),
},
);
assert!(MetricResourceIdentifier::parse("foo").is_err());
}

#[test]
fn test_invalid_names_should_normalize() {
assert_eq!(
MetricResourceIdentifier::parse("c:f?o").unwrap().name,
"f_o"
);
assert_eq!(
MetricResourceIdentifier::parse("c:f??o").unwrap().name,
"f_o"
);
assert_eq!(
MetricResourceIdentifier::parse("c:föo").unwrap().name,
"f_o"
);
assert_eq!(
MetricResourceIdentifier::parse("c:custom/f?o")
.unwrap()
Expand Down Expand Up @@ -487,10 +434,10 @@ mod tests {
#[test]
fn test_normalize_dash_to_underscore() {
assert_eq!(
MetricResourceIdentifier::parse("d:foo.bar.blob-size@second").unwrap(),
MetricResourceIdentifier::parse("d:transactions/foo.bar.blob-size@second").unwrap(),
MetricResourceIdentifier {
ty: MetricType::Distribution,
namespace: MetricNamespace::Custom,
namespace: MetricNamespace::Transactions,
name: "foo.bar.blob_size".into(),
unit: MetricUnit::Duration(DurationUnit::Second),
},
Expand All @@ -506,7 +453,7 @@ mod tests {
.unwrap(),
MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
namespace: MetricNamespace::Unsupported,
name: "foo".into(),
unit: MetricUnit::Duration(DurationUnit::MilliSecond),
},
Expand All @@ -518,12 +465,12 @@ mod tests {
assert_eq!(
serde_json::to_string(&MetricResourceIdentifier {
ty: MetricType::Counter,
namespace: MetricNamespace::Custom,
namespace: MetricNamespace::Transactions,
name: "foo".into(),
unit: MetricUnit::Duration(DurationUnit::MilliSecond),
})
.unwrap(),
"\"c:custom/foo@millisecond\"".to_owned(),
"\"c:transactions/foo@millisecond\"".to_owned(),
);
}
}
20 changes: 10 additions & 10 deletions relay-base-schema/src/metrics/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ impl MetricName {
///
/// let name = MetricName::from("cfoo");
/// assert!(name.try_type().is_none());
/// let name = MetricName::from("c:custom/foo@none");
/// let name = MetricName::from("c:spans/foo@none");
/// assert_eq!(name.try_type(), Some(MetricType::Counter));
/// let name = MetricName::from("d:custom/foo@none");
/// let name = MetricName::from("d:spans/foo@none");
/// assert_eq!(name.try_type(), Some(MetricType::Distribution));
/// let name = MetricName::from("s:custom/foo@none");
/// let name = MetricName::from("s:spans/foo@none");
/// assert_eq!(name.try_type(), Some(MetricType::Set));
/// let name = MetricName::from("g:custom/foo@none");
/// let name = MetricName::from("g:spans/foo@none");
/// assert_eq!(name.try_type(), Some(MetricType::Gauge));
/// ```
pub fn try_type(&self) -> Option<MetricType> {
Expand All @@ -56,11 +56,11 @@ impl MetricName {
///
/// let name = MetricName::from("foo");
/// assert_eq!(name.namespace(), MetricNamespace::Unsupported);
/// let name = MetricName::from("c:custom_oops/foo@none");
/// let name = MetricName::from("c:spans_oops/foo@none");
/// assert_eq!(name.namespace(), MetricNamespace::Unsupported);
///
/// let name = MetricName::from("c:custom/foo@none");
/// assert_eq!(name.namespace(), MetricNamespace::Custom);
/// let name = MetricName::from("c:spans/foo@none");
/// assert_eq!(name.namespace(), MetricNamespace::Spans);
/// ```
pub fn namespace(&self) -> MetricNamespace {
self.try_namespace().unwrap_or(MetricNamespace::Unsupported)
Expand All @@ -77,11 +77,11 @@ impl MetricName {
///
/// let name = MetricName::from("foo");
/// assert!(name.try_namespace().is_none());
/// let name = MetricName::from("c:custom_oops/foo@none");
/// let name = MetricName::from("c:spans_oops/foo@none");
/// assert!(name.try_namespace().is_none());
///
/// let name = MetricName::from("c:custom/foo@none");
/// assert_eq!(name.try_namespace(), Some(MetricNamespace::Custom));
/// let name = MetricName::from("c:spans/foo@none");
/// assert_eq!(name.try_namespace(), Some(MetricNamespace::Spans));
/// ```
pub fn try_namespace(&self) -> Option<MetricNamespace> {
// A well formed MRI is always in the format `<type>:<namespace>/<name>[@<unit>]`,
Expand Down
8 changes: 4 additions & 4 deletions relay-cardinality/benches/redis_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Params {
.map(|i| {
Entry::new(
EntryId(i),
MetricNamespace::Custom,
MetricNamespace::Spans,
&self.names[i % self.names.len()],
u32::MAX - (i as u32),
)
Expand All @@ -128,7 +128,7 @@ impl Params {
.map(|i| {
Entry::new(
EntryId(i),
MetricNamespace::Custom,
MetricNamespace::Spans,
&self.names[i % self.names.len()],
hash.fetch_sub(1, Ordering::SeqCst),
)
Expand All @@ -142,7 +142,7 @@ impl Params {
fn never_entry(&self) -> Entry<'_> {
Entry::new(
EntryId(usize::MAX),
MetricNamespace::Custom,
MetricNamespace::Spans,
&self.names[0],
0,
)
Expand All @@ -154,7 +154,7 @@ impl Params {
.map(|i| {
Entry::new(
EntryId(usize::MAX - i),
MetricNamespace::Custom,
MetricNamespace::Spans,
&self.names[i % self.names.len()],
i as u32,
)
Expand Down
4 changes: 2 additions & 2 deletions relay-cardinality/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {
},
limit: 1337,
scope: CardinalityScope::Organization,
namespace: Some(MetricNamespace::Custom),
namespace: Some(MetricNamespace::Sessions),
};

let j = serde_json::to_string(&limit).unwrap();
Expand All @@ -117,7 +117,7 @@ mod tests {
"window":{"windowSeconds":3600,"granularitySeconds":200},
"limit":1337,
"scope":"organization",
"namespace":"custom"
"namespace":"sessions"
}"#;
assert_eq!(serde_json::from_str::<CardinalityLimit>(j).unwrap(), limit);
}
Expand Down
34 changes: 17 additions & 17 deletions relay-cardinality/src/limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ mod tests {
Item::new(0, MetricNamespace::Sessions),
Item::new(1, MetricNamespace::Transactions),
Item::new(2, MetricNamespace::Spans),
Item::new(3, MetricNamespace::Custom),
Item::new(4, MetricNamespace::Custom),
Item::new(3, MetricNamespace::Unsupported),
Item::new(4, MetricNamespace::Unsupported),
Item::new(5, MetricNamespace::Transactions),
Item::new(6, MetricNamespace::Spans),
];
Expand All @@ -605,15 +605,15 @@ mod tests {
vec![
(Item::new(0, MetricNamespace::Sessions), &limits[0]),
(Item::new(2, MetricNamespace::Spans), &limits[0]),
(Item::new(4, MetricNamespace::Custom), &limits[0]),
(Item::new(4, MetricNamespace::Unsupported), &limits[0]),
(Item::new(6, MetricNamespace::Spans), &limits[0]),
]
);
assert_eq!(
split.accepted,
vec![
Item::new(1, MetricNamespace::Transactions),
Item::new(3, MetricNamespace::Custom),
Item::new(3, MetricNamespace::Unsupported),
Item::new(5, MetricNamespace::Transactions),
]
);
Expand Down Expand Up @@ -671,12 +671,12 @@ mod tests {
];

let items = vec![
Item::new(0, MetricNamespace::Custom),
Item::new(1, MetricNamespace::Custom),
Item::new(2, MetricNamespace::Custom),
Item::new(3, MetricNamespace::Custom),
Item::new(4, MetricNamespace::Custom),
Item::new(5, MetricNamespace::Custom),
Item::new(0, MetricNamespace::Spans),
Item::new(1, MetricNamespace::Spans),
Item::new(2, MetricNamespace::Spans),
Item::new(3, MetricNamespace::Spans),
Item::new(4, MetricNamespace::Spans),
Item::new(5, MetricNamespace::Spans),
];
let limited = limiter
.check_cardinality_limits(build_scoping(), limits, items)
Expand All @@ -689,17 +689,17 @@ mod tests {
assert_eq!(
split.rejected,
vec![
(Item::new(0, MetricNamespace::Custom), &limits[0]),
(Item::new(2, MetricNamespace::Custom), &limits[0]),
(Item::new(4, MetricNamespace::Custom), &limits[0]),
(Item::new(0, MetricNamespace::Spans), &limits[0]),
(Item::new(2, MetricNamespace::Spans), &limits[0]),
(Item::new(4, MetricNamespace::Spans), &limits[0]),
]
);
assert_eq!(
split.accepted,
vec![
Item::new(1, MetricNamespace::Custom),
Item::new(3, MetricNamespace::Custom),
Item::new(5, MetricNamespace::Custom),
Item::new(1, MetricNamespace::Spans),
Item::new(3, MetricNamespace::Spans),
Item::new(5, MetricNamespace::Spans),
]
);
}
Expand Down Expand Up @@ -795,7 +795,7 @@ mod tests {
},
];
let scoping = build_scoping();
let items = vec![Item::new(0, MetricNamespace::Custom)];
let items = vec![Item::new(0, MetricNamespace::Spans)];

let limiter = CardinalityLimiter::new(CreateReports);
let limited = limiter
Expand Down
Loading
Loading