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

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Nov 7, 2022

Names of custom measurements are converted into MRIs without any validation. This means that in metrics extraction, we are able to construct MRIs that are less strict than what the metrics protocol demands. Subsequent attempts to parse the MRI string into a MetricsResourceIdentifier object will fail.

This popped up in rate limiting, where we have to parse the MRI to know what namespace and name we are dealing with. Because of this bug, custom measurements with invalid names are currently not rate limited at all.

Fixes POP-RELAY-2N8.

}
}
false
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to move this function from relay-metrics to relay-common so it can be used from relay-general.

}
}
false
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to move this function from relay-metrics to relay-common so it can be used from relay-general. Note that this version no longer allows /.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can disallowing the usage of / cause issues in any of the places where it's currently used?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only other usage is here, and I refactored that part to split by / before validating, so all cases should be covered.

let (raw_namespace, name) = name_and_namespace
.split_once('/')
.unwrap_or(("custom", string));
let (raw_namespace, name, unit, value) = parse_name_unit_value(name_value_str, ty)?;
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to refactor these parser functions because is_valid_metric_name no longer allows / (because it is also called from normalization). Instead of validate-then-split, we know do split-then-validate.

@jjbayer jjbayer marked this pull request as ready for review November 7, 2022 12:01
@jjbayer jjbayer requested a review from a team November 7, 2022 12:01
CHANGELOG.md Outdated Show resolved Hide resolved
}
}
false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can disallowing the usage of / cause issues in any of the places where it's currently used?

Comment on lines 2147 to 2148
"my_custom-measurement_1": {"value": 123},
"my_custom_measurement_2": {"value": 789}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: considering the parsing fails if the name is not correct and we've modified the accepted domain, I'd add a third measurement with a . (valid), and maybe one with a / (invalid).

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 was great advice! By adding some more cases I realized that there is already protocol validation in protocol.rs, which actually adds errors for invalid names, so I reverted all changes in this PR and just fixed the validation there.

@jjbayer jjbayer changed the title fix(normalize): Drop invalid measurement names fix(protocol): Disallow - in measurement and breakdown names Nov 8, 2022
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.

🚀

@jjbayer jjbayer merged commit 054a8a8 into master Nov 9, 2022
@jjbayer jjbayer deleted the fix/normalize-enforce-mri branch November 9, 2022 08:47
@dashed
Copy link
Member

dashed commented Nov 9, 2022

Sorry I missed this. But this looks good to me 👍

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.

None yet

4 participants