Skip to content

Commit

Permalink
Improve tailer matcher function. (#2959)
Browse files Browse the repository at this point in the history
Don't create a map on every new push of a stream or appearance of a new stream.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Nov 20, 2020
1 parent 4da505b commit a62f81f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pkg/ingester/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 2 additions & 3 deletions pkg/ingester/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit a62f81f

Please sign in to comment.