forked from grafana/loki
/
matchers.go
23 lines (21 loc) · 868 Bytes
/
matchers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package util
import (
"github.com/prometheus/prometheus/model/labels"
)
// SplitFiltersAndMatchers splits empty matchers off, which are treated as filters, see #220
func SplitFiltersAndMatchers(allMatchers []*labels.Matcher) (filters, matchers []*labels.Matcher) {
for _, matcher := range allMatchers {
// If a matcher matches "", we need to fetch possible chunks where
// there is no value and will therefore not be in our label index.
// e.g. {foo=""} and {foo!="bar"} both match "", so we need to return
// chunks which do not have a foo label set. When looking entries in
// the index, we should ignore this matcher to fetch all possible chunks
// and then filter on the matcher after the chunks have been fetched.
if matcher.Matches("") {
filters = append(filters, matcher)
} else {
matchers = append(matchers, matcher)
}
}
return
}