From a62f81f1cf15d49e02958ae9a6097e84986ea336 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Fri, 20 Nov 2020 03:49:35 -0500 Subject: [PATCH] Improve tailer matcher function. (#2959) Don't create a map on every new push of a stream or appearance of a new stream. Signed-off-by: Cyril Tovena --- pkg/ingester/stream.go | 3 +-- pkg/ingester/tailer.go | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/ingester/stream.go b/pkg/ingester/stream.go index dde44a050bc2f..801331c42376d 100644 --- a/pkg/ingester/stream.go +++ b/pkg/ingester/stream.go @@ -310,6 +310,5 @@ func (s *stream) addTailer(t *tailer) { } func (s *stream) matchesTailer(t *tailer) bool { - metric := util.LabelsToMetric(s.labels) - return t.isWatchingLabels(metric) + return t.isWatchingLabels(s.labels) } diff --git a/pkg/ingester/tailer.go b/pkg/ingester/tailer.go index d1670e4c29047..091eb9e691ef2 100644 --- a/pkg/ingester/tailer.go +++ b/pkg/ingester/tailer.go @@ -8,7 +8,6 @@ import ( cortex_util "github.com/cortexproject/cortex/pkg/util" "github.com/go-kit/kit/log/level" - "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "golang.org/x/net/context" @@ -183,9 +182,9 @@ func (t *tailer) processStream(stream logproto.Stream) ([]logproto.Stream, error } // Returns true if tailer is interested in the passed labelset -func (t *tailer) isWatchingLabels(metric model.Metric) bool { +func (t *tailer) isWatchingLabels(lbs labels.Labels) bool { for _, matcher := range t.matchers { - if !matcher.Matches(string(metric[model.LabelName(matcher.Name)])) { + if !matcher.Matches(lbs.Get(matcher.Name)) { return false } }