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

ref(store): Normalize units in event payload [INGEST-1638] #1488

Merged
merged 7 commits into from
Sep 22, 2022

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Sep 21, 2022

The allowlist introduced in #1483 strictly checks the measurement unit. For that to work, we need to normalize the event unit first. Until now, unit normalization happened in metrics extraction. This PR moves it into (light) normalization.

// Default
_ => None,
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was moved 1:1 from transaction metrics extraction.

@jjbayer jjbayer marked this pull request as ready for review September 21, 2022 14:12
@jjbayer jjbayer requested a review from a team September 21, 2022 14:12
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple of suggestions.

CHANGELOG.md Outdated Show resolved Hide resolved

let stated_unit = measurement.unit.value().copied();
let default_unit = get_metric_measurement_unit(name);
if let (Some(default), Some(stated)) = (default_unit, stated_unit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems default is now a keyword in Rust. Although still experimental, see https://github.com/rust-lang/rfcs/blob/master/text/1210-impl-specialization.md. Can we use another name?

Suggested change
if let (Some(default), Some(stated)) = (default_unit, stated_unit) {
if let (Some(expected), Some(actual)) = (default_unit, stated_unit) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, thanks!

Comment on lines +274 to +276
measurement
.unit
.set_value(Some(stated_unit.or(default_unit).unwrap_or_default()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If stated_unit is None and default_unit is Some we should also throw a mismatch error, and same for the opposite case of Some and None. If both are None, then it's fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to prioritizing stated_unit here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I copied this logic from

stated_unit.or(default_unit).unwrap_or_default(),

Let's break down the use cases:

  • If stated_unit is None and default_unit is Some, there is no mismatch, because we allow SDKs to omit the unit for builtin measurements.
  • If stated_unit is Some and default_unit is None, we are dealing with a custom measurement for which we don't have a default. In this case, we accept any unit, so there is also no mismatch.

Note the subtle difference between None (unit not set) and Some(MetricUnit::None) (this is a unitless measurement).

Now that I think of it, get_metric_measurement_unit should probably use the allowlist passed down from Sentry to determine default units. I'll leave that for a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the subtle difference between None (unit not set) and Some(MetricUnit::None) (this is a unitless measurement).

Yep, I messed that one hehe. And I wasn't aware of omitting the unit was allowed. So all good then 👍.

Now that I think of it, get_metric_measurement_unit should probably use the allowlist passed down from Sentry to determine default units. I'll leave that for a follow-up PR.

I would not do that for now. At the moment, that'd mean using the project config, and I think the confusion of doing that is bigger vs the work and frequency to add/update new built-in metrics.

@jjbayer jjbayer merged commit e203987 into master Sep 22, 2022
@jjbayer jjbayer deleted the ref/move-measurement-unit-normalization branch September 22, 2022 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants