Fix matchLabels logic

This commit is contained in:
Stuart Nelson 2018-03-20 11:47:53 +01:00
parent 5ddf0444c4
commit 4c98f4b4a9

View File

@ -695,16 +695,30 @@ func matchFilterLabels(matchers []*labels.Matcher, sms map[string]string) bool {
for _, m := range matchers {
v, prs := sms[m.Name]
switch m.Type {
case labels.MatchNotEqual, labels.MatchNotRegexp:
if string(v) == "" && prs {
return true
case labels.MatchNotRegexp:
if string(m.Value) == "^(?:)$" && prs {
continue
}
if !m.Matches(string(v)) {
return false
}
case labels.MatchRegexp:
if string(m.Value) == "^(?:)$" && !prs {
continue
}
if !m.Matches(string(v)) {
return false
}
case labels.MatchNotEqual:
if string(m.Value) == "" && prs {
continue
}
if !m.Matches(string(v)) {
return false
}
default:
if string(v) == "" && !prs {
return true
if string(m.Value) == "" && !prs {
continue
}
if !prs || !m.Matches(string(v)) {
return false