Skip to content

fix(models): reject measurements and keys with leading underscores #20314

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

Closed
wants to merge 5 commits into from

Conversation

danxmoran
Copy link
Contributor

Closes #20310

This brings our implementation in line with the spec, and prevents panics when users override keys like _start. The first commit is a refactoring that I could split into a separate PR, if desired. The diff in the test file shows the impact of the actual fix.

@danxmoran danxmoran requested a review from docmerlin December 11, 2020 19:16
@docmerlin
Copy link
Contributor

This will likely break a lot of people's Kap workflows, because they tend to write fields like _start and _stop, iirc.

@danxmoran danxmoran marked this pull request as draft December 11, 2020 21:57
err = walkFields(fields, func(k, v []byte) bool {
if k[0] == '_' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to check len(k)>0 here first?

Copy link
Contributor Author

@danxmoran danxmoran Dec 14, 2020

Choose a reason for hiding this comment

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

This one seems to be covered by a preceding check, I get "missing field key" if I try to parse a line with an empty key

@@ -534,10 +551,13 @@ func scanKey(buf []byte, i int) (int, []byte, error) {
}

// Iterate over tags keys ensure that we do not encounter any
// of the reserved tag keys such as _measurement or _field.
// of the reserved tag keys.
for j := 0; j < commas; j++ {
_, key := scanTo(buf[indices[j]:indices[j+1]-1], 0, '=')

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to check len(k)>0 here first?

before line 558 or is that impossible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one seems to be covered by a preceding check, I get "missing tag key" if I try to parse cpu,=testing,tag=value value=2

@danxmoran danxmoran requested a review from rogpeppe December 14, 2020 17:03
@danxmoran
Copy link
Contributor Author

Closing for now, needs more discussion

@danxmoran danxmoran closed this Dec 16, 2020
@danxmoran danxmoran deleted the dm-keys-no-leading-underscore-20310 branch December 21, 2020 22:30
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.

Write path doesn't enforce naming restrictions on measurement and key names
2 participants