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

Validate label names #236

Merged
merged 2 commits into from
Jan 9, 2022
Merged

Validate label names #236

merged 2 commits into from
Jan 9, 2022

Conversation

Sinjo
Copy link
Member

@Sinjo Sinjo commented Dec 25, 2021

Up to now, we've only been performing limited validation of label names.
This commit validates that the characters use match the regex
/\A[a-zA-Z_][a-zA-Z0-9_]*\Z/ as specified by:

https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels


I ran into this while working on #234 for #186, but thought I'd separate it out into its own PR.

It's technically a breaking change, but I can't imagine Prometheus would have been happy scraping labels with these names to begin with. On top of that, our master branch already has breaking changes on it for the 3.0 release, so I figure one more doesn't hurt.

@Sinjo Sinjo force-pushed the sinjo-validate-label-names branch from 9c4ff92 to b06f8e7 Compare December 25, 2021 13:59
@Sinjo Sinjo requested a review from dmagliola January 2, 2022 02:23

unless key.to_s =~ LABEL_NAME_REGEX
msg = "label name must match /#{LABEL_NAME_REGEX}/"
raise InvalidLabelError, msg
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does rubocop complain if we inline this msg?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, in the sense that we don't run rubocop on this project. I think I must have wanted a shorter line, but I'm happy to change it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd inline it, for readability. The separate var had me scanning the code for where else we use it

Looks like a regex replacement was run against this file and was a
little too eager.

Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
@Sinjo Sinjo force-pushed the sinjo-validate-label-names branch 2 times, most recently from 1efd685 to 3fc686d Compare January 9, 2022 02:20
Up to now, we've only been performing limited validation of label names.
This commit validates that the characters use match the regex
`/\A[a-zA-Z_][a-zA-Z0-9_]*\Z/` as specified by:

https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels

Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
@Sinjo Sinjo force-pushed the sinjo-validate-label-names branch from 3fc686d to 3519342 Compare January 9, 2022 02:21
@Sinjo Sinjo merged commit 391aa20 into master Jan 9, 2022
@Sinjo Sinjo deleted the sinjo-validate-label-names branch January 9, 2022 02:24
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