mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
lib/storage: add missing reset for tagFilter.matchesEmptyValue on tagFilter.Init
This commit is contained in:
parent
c189104be7
commit
0ad7aaf535
@ -1735,10 +1735,6 @@ func (is *indexSearch) searchMetricIDs(tfss []*TagFilters, tr TimeRange, maxMetr
|
||||
}
|
||||
|
||||
func (is *indexSearch) updateMetricIDsForTagFilters(metricIDs *uint64set.Set, tfs *TagFilters, tr TimeRange, maxMetrics int) error {
|
||||
// Sort tag filters for faster ts.Seek below.
|
||||
sort.Slice(tfs.tfs, func(i, j int) bool {
|
||||
return tfs.tfs[i].Less(&tfs.tfs[j])
|
||||
})
|
||||
err := is.tryUpdatingMetricIDsForDateRange(metricIDs, tfs, tr, maxMetrics)
|
||||
if err == nil {
|
||||
// Fast path: found metricIDs by date range.
|
||||
@ -1749,6 +1745,11 @@ func (is *indexSearch) updateMetricIDsForTagFilters(metricIDs *uint64set.Set, tf
|
||||
}
|
||||
|
||||
// Slow path - try searching over the whole inverted index.
|
||||
|
||||
// Sort tag filters for faster ts.Seek below.
|
||||
sort.Slice(tfs.tfs, func(i, j int) bool {
|
||||
return tfs.tfs[i].Less(&tfs.tfs[j])
|
||||
})
|
||||
minTf, minMetricIDs, err := is.getTagFilterWithMinMetricIDsCountOptimized(tfs, tr, maxMetrics)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1119,6 +1119,17 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add(nil, []byte(".+"), true, true); err != nil {
|
||||
t.Fatalf("cannot add regexp, negative filter: %s", err)
|
||||
}
|
||||
ok, err = matchTagFilters(&mn, toTFPointers(tfs.tfs), &bb)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
|
||||
// Positive match by MetricGroup
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
@ -1165,6 +1176,17 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("Should match")
|
||||
}
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add(nil, []byte(".+"), 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(mn.AccountID, mn.ProjectID)
|
||||
@ -1222,6 +1244,17 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("Should match")
|
||||
}
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add([]byte("non-existing-tag"), []byte(".+"), false, true); err != nil {
|
||||
t.Fatalf("cannot add regexp, non-negative filter: %s", err)
|
||||
}
|
||||
ok, err = matchTagFilters(&mn, toTFPointers(tfs.tfs), &bb)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
|
||||
// Negative match by existing tag
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
@ -1268,6 +1301,17 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add([]byte("key 3"), []byte(".+"), true, true); err != nil {
|
||||
t.Fatalf("cannot add regexp, negative filter: %s", err)
|
||||
}
|
||||
ok, err = matchTagFilters(&mn, toTFPointers(tfs.tfs), &bb)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
|
||||
// Positive match by existing tag
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
@ -1304,7 +1348,7 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
t.Fatalf("Should match")
|
||||
}
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add([]byte("key 3"), []byte("v.+lue 2"), true, true); err != nil {
|
||||
if err := tfs.Add([]byte("key 3"), []byte("v.+lue 2|"), true, true); err != nil {
|
||||
t.Fatalf("cannot add regexp, negative filter: %s", err)
|
||||
}
|
||||
ok, err = matchTagFilters(&mn, toTFPointers(tfs.tfs), &bb)
|
||||
@ -1325,6 +1369,17 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("Should match")
|
||||
}
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add([]byte("key 3"), []byte(".+"), false, true); err != nil {
|
||||
t.Fatalf("cannot add regexp, non-negative 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")
|
||||
}
|
||||
|
||||
// Positive match by multiple tags and MetricGroup
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
@ -1396,6 +1451,22 @@ func TestMatchTagFilters(t *testing.T) {
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
|
||||
// Negative match for multiple non-regexp positive filters
|
||||
tfs.Reset(mn.AccountID, mn.ProjectID)
|
||||
if err := tfs.Add(nil, []byte("foobar_metric"), false, false); err != nil {
|
||||
t.Fatalf("cannot add non-regexp positive filter for MetricGroup: %s", err)
|
||||
}
|
||||
if err := tfs.Add([]byte("non-existing-metric"), []byte("foobar"), false, false); err != nil {
|
||||
t.Fatalf("cannot add non-regexp positive filter for non-existing tag: %s", err)
|
||||
}
|
||||
ok, err = matchTagFilters(&mn, toTFPointers(tfs.tfs), &bb)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if ok {
|
||||
t.Fatalf("Shouldn't match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchTSIDWithTimeRange(t *testing.T) {
|
||||
|
@ -242,6 +242,7 @@ func (tf *tagFilter) Init(commonPrefix, key, value []byte, isNegative, isRegexp
|
||||
|
||||
tf.orSuffixes = tf.orSuffixes[:0]
|
||||
tf.reSuffixMatch = nil
|
||||
tf.matchesEmptyValue = false
|
||||
|
||||
tf.prefix = append(tf.prefix, commonPrefix...)
|
||||
tf.prefix = marshalTagValue(tf.prefix, key)
|
||||
|
Loading…
Reference in New Issue
Block a user