Repository navigation
[BUGFIX] Prometheus: escape label values in metrics finder filters - #970
Open
rida-ghreizy wants to merge 1 commit into
Open
rida-ghreizy wants to merge 1 commit into
rida-ghreizy wants to merge 1 commit into
Conversation
computeFilterExpr put the label values of the metrics finder filters between double quotes without escaping them, so a value containing a double quote, a backslash or a line break produced an invalid PromQL selector, and the finder's queries failed. Escape them like a PromQL double-quoted string. Signed-off-by: rida <ghreizyrida1@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Prometheus metrics finder turns its label filters into PromQL with
computeFilterExpr(used for thematch[]of the label names/values and series requests, and for the metric overview queries):`${filter.label}${filter.operator}"${filter.labelValues.join('|')}"`The values are put between double quotes without escaping, so:
"or\(Windows paths, JSON fragments) gives an invalid selector, e.g.path="C:\data"(\dis not a valid escape), and the finder's requests fail;=~mode such as\d+is sent as"\d+", which Prometheus rejects as an invalid escape sequence, instead of"\d+".This PR escapes backslashes, double quotes and line breaks in the joined values, as for any PromQL double-quoted string. Values without those characters are unchanged, and regexes keep their meaning (a backslash typed in the field reaches the regex engine as one backslash).
Added
types.test.tswith cases for joined regex values, several filters, and escaping. I couldn't install the monorepo here, so I ran these three tests against the transpiledtypes.tswith a small harness: they pass, and the escaping case fails without the fix. CI will run them with Vitest.Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.