mirror of https://github.com/grafana/loki
Remove `cortex/pkg/util/extract` dependency from Loki (#5049)
Copy only `extract.MetricNameMatcherFromMatchers`. Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>pull/5053/head
parent
a4f218305d
commit
ac6e092f3c
@ -0,0 +1,29 @@ |
||||
package extract |
||||
|
||||
import ( |
||||
"github.com/prometheus/common/model" |
||||
"github.com/prometheus/prometheus/model/labels" |
||||
) |
||||
|
||||
// MetricNameMatcherFromMatchers extracts the metric name from a set of matchers
|
||||
func MetricNameMatcherFromMatchers(matchers []*labels.Matcher) (*labels.Matcher, []*labels.Matcher, bool) { |
||||
// Handle the case where there is no metric name and all matchers have been
|
||||
// filtered out e.g. {foo=""}.
|
||||
if len(matchers) == 0 { |
||||
return nil, matchers, false |
||||
} |
||||
|
||||
outMatchers := make([]*labels.Matcher, len(matchers)-1) |
||||
for i, matcher := range matchers { |
||||
if matcher.Name != model.MetricNameLabel { |
||||
continue |
||||
} |
||||
|
||||
// Copy other matchers, excluding the found metric name matcher
|
||||
copy(outMatchers, matchers[:i]) |
||||
copy(outMatchers[i:], matchers[i+1:]) |
||||
return matcher, outMatchers, true |
||||
} |
||||
// Return all matchers if none are metric name matchers
|
||||
return nil, matchers, false |
||||
} |
Loading…
Reference in new issue