Remove `cortex/pkg/util/extract` dependency from Loki (#5049)

Copy only `extract.MetricNameMatcherFromMatchers`.

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
pull/5053/head
Kaviraj 3 years ago committed by GitHub
parent a4f218305d
commit ac6e092f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      pkg/storage/chunk/chunk_store.go
  2. 29
      pkg/util/extract/extract.go

@ -17,14 +17,13 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/extract"
util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/cortexproject/cortex/pkg/util/validation"
"github.com/grafana/loki/pkg/util/spanlogger"
"github.com/grafana/loki/pkg/storage/chunk/cache"
"github.com/grafana/loki/pkg/storage/chunk/encoding"
"github.com/grafana/loki/pkg/util/extract"
"github.com/grafana/loki/pkg/util/spanlogger"
)
var (

@ -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…
Cancel
Save