mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-07 06:37:17 +02:00
Fix bug in lbl!~".+" shortcut (#15684)
We were appending to the wrong slice, so instead of removing values, we were adding them. Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
This commit is contained in:
parent
dd95a7e231
commit
c8359fcd6b
@ -271,7 +271,7 @@ func PostingsForMatchers(ctx context.Context, ix IndexReader, ms ...*labels.Matc
|
|||||||
its = append(its, it)
|
its = append(its, it)
|
||||||
case m.Type == labels.MatchNotRegexp && m.Value == ".+":
|
case m.Type == labels.MatchNotRegexp && m.Value == ".+":
|
||||||
// .+ regexp matches any non-empty string: get postings for all label values and remove them.
|
// .+ regexp matches any non-empty string: get postings for all label values and remove them.
|
||||||
its = append(notIts, ix.PostingsForAllLabelValues(ctx, m.Name))
|
notIts = append(notIts, ix.PostingsForAllLabelValues(ctx, m.Name))
|
||||||
|
|
||||||
case labelMustBeSet[m.Name]:
|
case labelMustBeSet[m.Name]:
|
||||||
// If this matcher must be non-empty, we can be smarter.
|
// If this matcher must be non-empty, we can be smarter.
|
||||||
|
@ -3017,6 +3017,15 @@ func TestPostingsForMatchers(t *testing.T) {
|
|||||||
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^.*$")},
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "n", "1"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", "^.*$")},
|
||||||
exp: []labels.Labels{},
|
exp: []labels.Labels{},
|
||||||
},
|
},
|
||||||
|
// Test shortcut i!~".+"
|
||||||
|
{
|
||||||
|
matchers: []*labels.Matcher{labels.MustNewMatcher(labels.MatchRegexp, "n", ".*"), labels.MustNewMatcher(labels.MatchNotRegexp, "i", ".+")},
|
||||||
|
exp: []labels.Labels{
|
||||||
|
labels.FromStrings("n", "1"),
|
||||||
|
labels.FromStrings("n", "2"),
|
||||||
|
labels.FromStrings("n", "2.5"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ir, err := h.Index()
|
ir, err := h.Index()
|
||||||
|
Loading…
Reference in New Issue
Block a user