Fix metrics filter with colon : in query value#428
Fix metrics filter with colon : in query value#428kgeckhart merged 1 commit intoprometheus-community:masterfrom
: in query value#428Conversation
: in query value: in query value
|
@SuperQ @kgeckhart Feel free to close this one in favor of anything that will fix this :) The problem is visible in debug logs |
|
After testing this I should probably mention that for this to work the quotes around the filter value |
kgeckhart
left a comment
There was a problem hiding this comment.
Thanks for this! I had a few comments and a question.
After testing this I should probably mention that for this to work the quotes around the filter value "project-id:database-name" are very important.
Can you add some context about why the quotes are very important?
utils/utils.go
Outdated
| return "", "" | ||
| } | ||
| return mPrefix[0], strings.Join(mPrefix[1:], "") | ||
| return mPrefix[0], strings.Join(mPrefix[1:], separator) |
There was a problem hiding this comment.
Perhaps we could change the strings.Split on line 45 -> strings.SplitN(extraFIlter, separator, 2) and then we have no need for the join here.
There was a problem hiding this comment.
Thanks, I changed it to strings.SplitN().
Also slightly changed the guard if to check for slice length. Hope that's OK.
| }) | ||
| }) | ||
|
|
||
| var _ = Describe("SplitExtraFilter", func() { |
There was a problem hiding this comment.
Could you add a test for the case where there's no : in the filter as well please?
There was a problem hiding this comment.
No problem. Also added one for the incomplete/missing filter.
I don't have much experience with ginkgo but it seems that with v2 (or extensions/table) we could use DescribeTable for nicer parametrized tests. But I didn't want to introduce/change dependencies here.
There was a problem hiding this comment.
Thank you! The testing framework is rather outdated 😬 . I imagine we would probably look to remove the library in favor of more basic std lib based tests but never really got the time to do it.
Otherwise some parser would fail. Full error: |
Got it, if you think you can add an extra guard that could produce a more helpful error go for it. I tried to quickly scan the sdk for a function that could validate the filter but didn't find anything. |
Hmm, I also didn't find anything useful in the SDK. The error is coming either from a serializer or from some DSL parsing happening on Google servers. Looking at https://cloud.google.com/monitoring/api/v3/filters the filters can be quite complex. I was hoping that a check could be implemented somewhere in/around We could mention it in the README (Using filters section) - link the official filters spec, maybe mention to use quotes around strings (not only filter values but also user label keys) and mention to check logs when implementing complex filters. |
I think that's a great idea and could hopefully help someone who gets the rather unhelpful error from GCP. |
Example of a metric filter affected by this: ``` cloudsql.googleapis.com/database:resource.labels.database_id="project-id:database-name" ``` + Added/updated tests + Updated README with this example and a note about quoting special characters Signed-off-by: Daniel Kontsek <daniel@kontsek.sk>
|
I just noticed that the link the the official official filters spec is already there :) So I only updated the full example in README and mentioned the need for quotes. |
|
TYVM for this, sorry it took me so long to merge it I lost track of it |
Example of a metric filter affected by this: