Skip to content
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

fix(protocol): Disallow - in measurement and breakdown names #1571

Merged
merged 3 commits into from
Nov 9, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Features**:

- Support decaying rules. Decaying rules are regular sampling rules, but they are only applicable in a specific time range. ([#1544](https://github.com/getsentry/relay/pull/1544))
- Disallow `-` in measurement and breakdown names. These items are converted to metrics, which do not allow `-` in their name. ([#1571](https://github.com/getsentry/relay/pull/1571))

**Bug Fixes**:

Expand Down
4 changes: 2 additions & 2 deletions relay-general/src/protocol/breakdowns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Breakdowns {
&& name.starts_with(|c| matches!(c, 'a'..='z' | 'A'..='Z'))
&& name
.chars()
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '.'))
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.'))
}
}

Expand All @@ -34,7 +34,7 @@ impl FromValue for Breakdowns {
return Some((name.into(), object));
} else {
processing_errors.push(Error::invalid(format!(
"breakdown name '{}' can contain only characters a-z0-9.-_",
"breakdown name '{}' can contain only characters a-z0-9._",
name
)));
}
Expand Down
28 changes: 14 additions & 14 deletions relay-general/src/protocol/measurements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl FromValue for Measurements {
return Some((name.to_lowercase(), object));
} else {
processing_errors.push(Error::invalid(format!(
"measurement name '{}' can contain only characters a-z0-9.-_",
"measurement name '{}' can contain only characters a-z0-9._",
name
)));
}
Expand Down Expand Up @@ -139,7 +139,7 @@ fn is_valid_measurement_name(name: &str) -> bool {
name.starts_with(|c| matches!(c, 'a'..='z' | 'A'..='Z'))
&& name
.chars()
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '.'))
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.'))
}

#[cfg(test)]
Expand Down Expand Up @@ -185,9 +185,6 @@ mod tests {
"value": 420.69,
"unit": "millisecond"
},
"lcp_final.element-size123": {
"value": 1.0
},
"missing_value": null
},
"_meta": {
Expand All @@ -203,7 +200,13 @@ mod tests {
[
"invalid_data",
{
"reason": "measurement name 'Total Blocking Time' can contain only characters a-z0-9.-_"
"reason": "measurement name 'lcp_final.element-Size123' can contain only characters a-z0-9._"
}
],
[
"invalid_data",
{
"reason": "measurement name 'Total Blocking Time' can contain only characters a-z0-9._"
}
]
]
Expand Down Expand Up @@ -256,13 +259,6 @@ mod tests {
unit: Annotated::new(MetricUnit::Duration(DurationUnit::MilliSecond)),
}),
);
measurements.insert(
"lcp_final.element-size123".to_owned(),
Annotated::new(Measurement {
value: Annotated::new(1f64),
unit: Annotated::empty(),
}),
);
measurements.insert(
"fid".to_owned(),
Annotated::new(Measurement {
Expand Down Expand Up @@ -301,7 +297,11 @@ mod tests {
measurements_meta.add_error(Error::invalid("measurement name '' cannot be empty"));

measurements_meta.add_error(Error::invalid(
"measurement name 'Total Blocking Time' can contain only characters a-z0-9.-_",
"measurement name 'lcp_final.element-Size123' can contain only characters a-z0-9._",
));

measurements_meta.add_error(Error::invalid(
"measurement name 'Total Blocking Time' can contain only characters a-z0-9._",
));

let event = Annotated::new(Event {
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def test_normalize_measurement_interface(
"inp": {"unit": "millisecond", "value": 100.14},
"fp": {"unit": "millisecond", "value": None},
"lcp": {"unit": "millisecond", "value": 420.69},
"lcp_final.element-size123": {"unit": "none", "value": 1.0},
"missing_value": None,
}

Expand Down