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(webvitals): Drop negative web vitals from measurements #2982

Merged
merged 6 commits into from
Jan 24, 2024

Conversation

edwardgou-sentry
Copy link
Contributor

@edwardgou-sentry edwardgou-sentry commented Jan 22, 2024

Add allow_negative to BuiltinMeasurementKey. Filter out negative BuiltinMeasurements if allow_negative is false.

@edwardgou-sentry edwardgou-sentry requested review from a team January 22, 2024 21:39
@edwardgou-sentry edwardgou-sentry marked this pull request as ready for review January 22, 2024 21:39
@edwardgou-sentry edwardgou-sentry requested a review from a team as a code owner January 22, 2024 21:39
Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

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

Thank you for this change, it makes sense to consider negative web vitals as invalid and remove them during normalization.

Instead of hard-coding this, we can use builtin_measurements from the global config. This way, the same normalization automatically applies to new measurements added in the future and extends beyond web vitals. Most of our measurements would require positive values (except for things measuring relative change, such as memory), so we can make this a new default:

/// Defines a builtin measurement.
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Hash, Eq)]
#[serde(default, rename_all = "camelCase")]
pub struct BuiltinMeasurementKey {
    name: String,
    unit: MetricUnit,
    #[serde(default, skip_serializing_if = "is_false")]
    allow_negative: bool,
}

fn is_false(b: &bool) -> bool {
    !b
}

There's already a function called remove_invalid_measurements that has access to this configuration and is used to prune invalid measurements. It is also called from within normalize_measurments (here), so the only thing left to do is move it to the bottom of the function after calling compute_measurements.

By returning false from the retain closure, you can evict measurements from the list. An example where builtin measurement keys are checked is here. You can add this additional check and return false if the measurement's value is negative and the matching config does not permit negative values.

@edwardgou-sentry
Copy link
Contributor Author

Thanks @jan-auer ! I've made updates to BuiltinMeasurementKey an moved the negative check to remove_invalid_measurements

Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

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

Thank you!

@edwardgou-sentry edwardgou-sentry force-pushed the egou/fix/drop-negative-web-vitals branch from 9b69e2b to 0a4bd57 Compare January 24, 2024 15:17
@edwardgou-sentry edwardgou-sentry merged commit f51ca94 into master Jan 24, 2024
20 checks passed
@edwardgou-sentry edwardgou-sentry deleted the egou/fix/drop-negative-web-vitals branch January 24, 2024 16:18
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.

2 participants