-
Notifications
You must be signed in to change notification settings - Fork 94
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
Conversation
…ents since it is invalid
There was a problem hiding this 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.
…_measurements to check for negative values
…p-negative-web-vitals
Thanks @jan-auer ! I've made updates to BuiltinMeasurementKey an moved the negative check to remove_invalid_measurements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
9b69e2b
to
0a4bd57
Compare
Add
allow_negative
toBuiltinMeasurementKey
. Filter out negative BuiltinMeasurements ifallow_negative
is false.