mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
* fix for issue 2255 - matchTagFilters for positive empty-match filters * add example to comments * formatting * add test for positive empty match * formatting
This commit is contained in:
parent
65afe3b141
commit
e5868b9c29
2 changed files with 21 additions and 2 deletions
|
@ -2152,14 +2152,20 @@ func matchTagFilters(mn *MetricName, tfs []*tagFilter, kb *bytesutil.ByteBuffer)
|
|||
tagMatched = true
|
||||
break
|
||||
}
|
||||
if !tagSeen && tf.isNegative && !tf.isEmptyMatch {
|
||||
if !tagSeen && (!tf.isNegative && tf.isEmptyMatch || tf.isNegative && !tf.isEmptyMatch) {
|
||||
// tf contains positive empty-match filter for non-existing tag key, i.e.
|
||||
// {non_existing_tag_key=~"foobar|"}
|
||||
//
|
||||
// OR
|
||||
//
|
||||
// tf contains negative filter for non-exsisting tag key
|
||||
// and this filter doesn't match empty string, i.e. {non_existing_tag_key!="foobar"}
|
||||
// Such filter matches anything.
|
||||
//
|
||||
// Note that the filter `{non_existing_tag_key!~"|foobar"}` shouldn't match anything,
|
||||
// since it is expected that it matches non-empty `non_existing_tag_key`.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/546 for details.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/546 and
|
||||
// https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2255 for details.
|
||||
continue
|
||||
}
|
||||
if tagMatched {
|
||||
|
|
|
@ -1182,6 +1182,19 @@ func TestMatchTagFilters(t *testing.T) {
|
|||
t.Fatalf("Should match")
|
||||
}
|
||||
|
||||
// Positive empty match by non-existing tag
|
||||
tfs.Reset()
|
||||
if err := tfs.Add([]byte("non-existing-tag"), []byte("foobar|"), false, true); err != nil {
|
||||
t.Fatalf("cannot add regexp, positive filter: %s", err)
|
||||
}
|
||||
ok, err = matchTagFilters(&mn, toTFPointers(tfs.tfs), &bb)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatalf("Should match")
|
||||
}
|
||||
|
||||
// Negative match by non-existing tag
|
||||
tfs.Reset()
|
||||
if err := tfs.Add([]byte("non-existing-tag"), []byte("foobar"), false, false); err != nil {
|
||||
|
|
Loading…
Reference in a new issue