api: check silence matching by string comparison in getSilences#2443
api: check silence matching by string comparison in getSilences#2443beorn7 merged 4 commits intoprometheus:masterfrom
Conversation
| } | ||
| } | ||
|
|
||
| return matchFilterLabels(matchers, sms) |
There was a problem hiding this comment.
If the new logic you have here were refactored into matchFilterLabels, would it also improve alert filtering (since matchFilterLabels seems to be used by that endpoint too)?
There was a problem hiding this comment.
Hmm, I think it wouldn't. IMO we should apply different logic to filter alerts or silences.
For instance, suppose we'd like to filter alerts coming from *.example.com -- we can use regexp instance=~".*.example.com" for this purpose. In this case, we should rather apply the existing matchFilterLabels logic, which checks whether an alert label matches with the given matcher by using regexp.
On the other hand, unlike alerts, a label of silence may contain regex like instance=~".*.example.com" (silence all alerts from *.example.com). In this case, we should not use regexp to check whether the silence label matches with the given matcher, but apply a simple string comparison.
|
Sure, I'll work on it! |
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
|
Currently, the OpenAPI model for silence doesn't support negative matchers, while the Protobuf model does: OpenAPIalertmanager/api/v2/models/matcher.go Lines 32 to 45 in e6a1bed Protobufalertmanager/silence/silencepb/silence.pb.go Lines 65 to 75 in e6a1bed alertmanager/silence/silencepb/silence.pb.go Lines 35 to 40 in e6a1bed
We may have to work on 2 at some point, but that needs more consideration. I believe the first solution should be reasonable and has less impact for now. |
Signed-off-by: Koki Kato <koki.kato1994@gmail.com> To support negative matchers.
b19e6e2 to
b7beb57
Compare
Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
b7beb57 to
b5ddc5d
Compare
I tried updating the PR in this direction. Now silences with negative matchers will start working immediately after OpenAPI models and clients/frontends are updated. Could you take a look again? @beorn7 |
|
The changes for alertmanager/api/v2/models/matcher.go are in #2471 (which is not yet merged). |
|
The test failure might be due to flakiness. I have rerun the test. (The test_frontend is known to be broken at the moment.) |
|
OK, now we are down to only the expected test_frontend error. |
beorn7
left a comment
There was a problem hiding this comment.
I think we should go with this, but I'd much prefer if @simonpasquier could also chime in. I'll leave this open for another day or so to give him the opportunity.
|
I take silence as consent and merge this now. |
Fixes #2283.
This PR changes how
gettableSilenceMatchesFilterLabelsin api/v2 checks whether a silence matches a given filter, especially for regex cases. In short,For instance, as shown in figure #2283, a silence
alertname~=(foo|bar)didn't match a filter of the same patternalertname~=(foo|bar), since the regex match fails. After the fix, the silence and filter will match as we use string comparison instead.