diff --git a/pkg/chunkenc/memchunk_test.go b/pkg/chunkenc/memchunk_test.go index 73cdd46f5be3..459f51354b2a 100644 --- a/pkg/chunkenc/memchunk_test.go +++ b/pkg/chunkenc/memchunk_test.go @@ -814,11 +814,11 @@ func BenchmarkBufferedIteratorLabels(b *testing.B) { }, } for _, test := range []string{ - // `{app="foo"}`, + `{app="foo"}`, `{app="foo"} != "foo"`, - // `{app="foo"} != "foo" | logfmt `, - // `{app="foo"} != "foo" | logfmt | duration > 10ms`, - // `{app="foo"} != "foo" | logfmt | duration > 10ms and component="tsdb"`, + `{app="foo"} != "foo" | logfmt `, + `{app="foo"} != "foo" | logfmt | duration > 10ms`, + `{app="foo"} != "foo" | logfmt | duration > 10ms and component="tsdb"`, } { b.Run(test, func(b *testing.B) { b.ReportAllocs() @@ -851,13 +851,13 @@ func BenchmarkBufferedIteratorLabels(b *testing.B) { } for _, test := range []string{ - // `rate({app="foo"}[1m])`, - // `sum by (cluster) (rate({app="foo"}[10s]))`, - // `sum by (cluster) (rate({app="foo"} != "foo" [10s]))`, - // `sum by (cluster) (rate({app="foo"} != "foo" | logfmt[10s]))`, - // `sum by (caller) (rate({app="foo"} != "foo" | logfmt[10s]))`, - // `sum by (cluster) (rate({app="foo"} != "foo" | logfmt | duration > 10ms[10s]))`, - // `sum by (cluster) (rate({app="foo"} != "foo" | logfmt | duration > 10ms and component="tsdb"[1m]))`, + `rate({app="foo"}[1m])`, + `sum by (cluster) (rate({app="foo"}[10s]))`, + `sum by (cluster) (rate({app="foo"} != "foo" [10s]))`, + `sum by (cluster) (rate({app="foo"} != "foo" | logfmt[10s]))`, + `sum by (caller) (rate({app="foo"} != "foo" | logfmt[10s]))`, + `sum by (cluster) (rate({app="foo"} != "foo" | logfmt | duration > 10ms[10s]))`, + `sum by (cluster) (rate({app="foo"} != "foo" | logfmt | duration > 10ms and component="tsdb"[1m]))`, } { b.Run(test, func(b *testing.B) { b.ReportAllocs() diff --git a/pkg/logql/log/labels.go b/pkg/logql/log/labels.go index 03bdbf9f272f..24283a36c914 100644 --- a/pkg/logql/log/labels.go +++ b/pkg/logql/log/labels.go @@ -64,6 +64,7 @@ func (h *hasher) Hash(lbs labels.Labels) uint64 { type BaseLabelsBuilder struct { del []string add []labels.Label + // nolint(structcheck) https://github.com/golangci/golangci-lint/issues/826 err string groups []string @@ -238,40 +239,10 @@ Outer: // No grouping is applied and the cache is used when possible. func (b *LabelsBuilder) LabelsResult() LabelsResult { // unchanged path. - if len(b.del) == 0 && len(b.add) == 0 { - if b.err == "" { - return b.currentResult - } - // unchanged but with error. - res := append(b.base.Copy(), labels.Label{Name: ErrorLabel, Value: b.err}) - sort.Sort(res) - return b.toResult(res) - } - - // In the general case, labels are removed, modified or moved - // rather than added. - res := make(labels.Labels, 0, len(b.base)+len(b.add)) -Outer: - for _, l := range b.base { - for _, n := range b.del { - if l.Name == n { - continue Outer - } - } - for _, la := range b.add { - if l.Name == la.Name { - continue Outer - } - } - res = append(res, l) + if len(b.del) == 0 && len(b.add) == 0 && b.err == "" { + return b.currentResult } - res = append(res, b.add...) - if b.err != "" { - res = append(res, labels.Label{Name: ErrorLabel, Value: b.err}) - } - sort.Sort(res) - - return b.toResult(res) + return b.toResult(b.Labels()) } func (b *BaseLabelsBuilder) toResult(lbs labels.Labels) LabelsResult {