github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/util/matchers.go (about)

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