api: check silence matching by string comparison in getSilences

Signed-off-by: Koki Kato <koki.kato1994@gmail.com>
This commit is contained in:
Koki Kato 2020-12-26 17:52:10 +09:00
parent e6a1bede89
commit f8c33ab47d
1 changed files with 19 additions and 4 deletions

View File

@ -638,13 +638,28 @@ func sortSilences(sils open_api_models.GettableSilences) {
})
}
// gettableSilenceMatchesFilterLabels returns true if
// a given silence matches a list of matchers.
// A silence matches a filter (list of matchers) if
// for all matchers in the filter, there exists a matcher in the silence
// such that their names, types, and values are equivalent.
func gettableSilenceMatchesFilterLabels(s open_api_models.GettableSilence, matchers []*labels.Matcher) bool {
sms := make(map[string]string)
for _, m := range s.Matchers {
sms[*m.Name] = *m.Value
for _, matcher := range matchers {
found := false
for _, m := range s.Matchers {
if matcher.Name == *m.Name &&
(matcher.Type == labels.MatchEqual && !*m.IsRegex || matcher.Type == labels.MatchRegexp && *m.IsRegex) &&
matcher.Value == *m.Value {
found = true
break
}
}
if !found {
return false
}
}
return matchFilterLabels(matchers, sms)
return true
}
func (api *API) getSilenceHandler(params silence_ops.GetSilenceParams) middleware.Responder {