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(metrics): Parse custom units #1312

Merged
merged 7 commits into from
Jun 20, 2022
Merged

fix(metrics): Parse custom units #1312

merged 7 commits into from
Jun 20, 2022

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Jun 20, 2022

The parser of CustomUnit only worked when the length of the custom unit was exactly 15.

Fixes POP-RELAY-2GF.

@jjbayer jjbayer requested a review from a team June 20, 2022 06:39
Co-authored-by: Markus Unterwaditzer <[email protected]>
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());
Copy link
Contributor

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.

Copy link
Member

@untitaker untitaker Jun 20, 2022

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@jjbayer jjbayer merged commit b04662e into master Jun 20, 2022
@jjbayer jjbayer deleted the fix/metrics-parse-unit branch June 20, 2022 11:19
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.

4 participants