-
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(metrics): Parse custom units #1312
Conversation
Co-authored-by: Markus Unterwaditzer <[email protected]>
Co-authored-by: Iker Barriocanal <[email protected]>
relay-common/src/constants.rs
Outdated
let mut unit = Self(Default::default()); | ||
unit.0.copy_from_slice(s.as_bytes()); | ||
let mut unit = Self([0; CUSTOM_UNIT_MAX_SIZE]); | ||
unit.0[..s.len()].copy_from_slice(s.as_bytes()); |
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.
I'd probably try and avoid indexing operations, using .get()
or so instead. IIRC it's also possible to add a clippy lint for this.
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.
you could use unit.0.get(..s.len()).ok_or(ParseMetricUnitError())?
and forego the s.len()
check on line 490 (but still leave the is_ascii check)
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.
done
The parser of
CustomUnit
only worked when the length of the custom unit was exactly 15.Fixes POP-RELAY-2GF.