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

Reject labels with invalid runes when using implicit extraction parser. #3983

Merged
merged 1 commit into from
Jul 12, 2021

Conversation

cyriltovena
Copy link
Contributor

@cyriltovena cyriltovena commented Jul 12, 2021

json and logfmt parser will attempt to extract all possible keys and values as labels.
But if a values currently contains the rune error (used as replacement when there's an invalid rune) PromQL parser will fail and the request
will be fully rejected.

This PR removes those labels values when using those two parsers.

For other parser you can just decide to not extract these values.( At least that's my choice for now).

Unfortunately this comes with a small cpu overhead prices:

~/go/src/github.com/grafana/loki utf8-parser*
❯ benchcmp  before.txt after.txt
benchmark                                    old ns/op     new ns/op     delta
Benchmark_Parser/json/no_labels_hints-16     3647          4210          +15.44%
Benchmark_Parser/json/labels_hints-16        2210          2247          +1.67%

benchmark                                    old allocs     new allocs     delta
Benchmark_Parser/json/no_labels_hints-16     72             72             +0.00%
Benchmark_Parser/json/labels_hints-16        35             35             +0.00%

benchmark                                    old bytes     new bytes     delta
Benchmark_Parser/json/no_labels_hints-16     1121          1121          +0.00%
Benchmark_Parser/json/labels_hints-16        472           472           +0.00%

Fixes #2859

Signed-off-by: Cyril Tovena [email protected]

`json` and `logfmt` parser will attempt to extract all possible keys and values as labels.
But if a values currently contains the rune error (replace when there's an invalid rune) PromQL parser will fail and the request
will be fully rejected.

This PR removes those labels values when using those two parsers.

For other parser you can just decide to not extract thoses values.( At least that's my choice for now).

Unfortunatelly this comes with a small cpu overhead prices:

```
~/go/src/github.com/grafana/loki utf8-parser*
❯ benchcmp  before.txt after.txt
benchmark                                    old ns/op     new ns/op     delta
Benchmark_Parser/json/no_labels_hints-16     3647          4210          +15.44%
Benchmark_Parser/json/labels_hints-16        2210          2247          +1.67%

benchmark                                    old allocs     new allocs     delta
Benchmark_Parser/json/no_labels_hints-16     72             72             +0.00%
Benchmark_Parser/json/labels_hints-16        35             35             +0.00%

benchmark                                    old bytes     new bytes     delta
Benchmark_Parser/json/no_labels_hints-16     1121          1121          +0.00%
Benchmark_Parser/json/labels_hints-16        472           472           +0.00%
```

Fixes grafana#2859

Signed-off-by: Cyril Tovena <[email protected]>
@dannykopping
Copy link
Contributor

Should this also apply to the JSON expression parser?

@cyriltovena
Copy link
Contributor Author

cyriltovena commented Jul 12, 2021

I think because you explicitly ask to extract a set of values with this parser, it's easy to avoid those values when crafting the query. That's my main reasoning for not adding this everywhere.

@dannykopping
Copy link
Contributor

Seems like a fair argument 👍

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

err while creating labelset
2 participants