Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/util/matchers.go

27 lines
1002 B

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("") {
// Always skip matches that match everything
if matcher.Type == labels.MatchRegexp && matcher.Value == ".*" {
continue
}
filters = append(filters, matcher)
} else {
matchers = append(matchers, matcher)
}
}
return
}