Skip to content

Commit

Permalink
Don't reuse vals in inversePostingsForMatchers
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Zaytsev <[email protected]>
  • Loading branch information
colega committed Jan 3, 2025
1 parent c2b6130 commit 163420d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tsdb/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"slices"

"github.com/oklog/ulid"
"go.opentelemetry.io/otel/trace"

"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/labels"
Expand Down Expand Up @@ -363,7 +364,7 @@ func inversePostingsForMatcher(ctx context.Context, ix IndexPostingsReader, m *l
return nil, err
}

res := vals[:0]
res := make([]string, 0, len(vals))
// If the match before inversion was !="" or !~"", we just want all the values.
if m.Value == "" && (m.Type == labels.MatchRegexp || m.Type == labels.MatchEqual) {
res = vals
Expand All @@ -380,6 +381,12 @@ func inversePostingsForMatcher(ctx context.Context, ix IndexPostingsReader, m *l
}
}

for _, val := range res {
if m.Matches(val) {
fmt.Println("UNEXPECTED MATCH", m.String(), "SHOULD NOT MATCH", val, "BUT DOES. TOTAL RES", len(res), "VALS", len(vals), "TRACE", trace.SpanFromContext(ctx).SpanContext().TraceID().String())
}
}

return ix.Postings(ctx, m.Name, res...)
}

Expand Down

0 comments on commit 163420d

Please sign in to comment.