mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
c38d3dab4d
commit
3da4b970d7
5 changed files with 76 additions and 70 deletions
|
@ -50,7 +50,7 @@ func TestStorageSearchStreamIDs(t *testing.T) {
|
|||
|
||||
f := func(filterStream string, expectedStreamIDs []streamID) {
|
||||
t.Helper()
|
||||
sf := mustNewStreamFilter(filterStream)
|
||||
sf := mustNewTestStreamFilter(filterStream)
|
||||
if expectedStreamIDs == nil {
|
||||
expectedStreamIDs = []streamID{}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func TestStorageSearchStreamIDs(t *testing.T) {
|
|||
AccountID: 1,
|
||||
ProjectID: 2,
|
||||
}
|
||||
sf := mustNewStreamFilter(`{job="job-0",instance="instance-0"}`)
|
||||
sf := mustNewTestStreamFilter(`{job="job-0",instance="instance-0"}`)
|
||||
for i := 0; i < 3; i++ {
|
||||
streamIDs := idb.searchStreamIDs([]TenantID{tenantID}, sf)
|
||||
if len(streamIDs) > 0 {
|
||||
|
|
|
@ -1111,15 +1111,6 @@ func parseFilterStream(lex *lexer) (*filterStream, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func newStreamFilter(s string) (*StreamFilter, error) {
|
||||
lex := newLexer(s)
|
||||
fs, err := parseFilterStream(lex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.f, nil
|
||||
}
|
||||
|
||||
func parseAndStreamFilter(lex *lexer) (*andStreamFilter, error) {
|
||||
var filters []*streamTagFilter
|
||||
for {
|
||||
|
|
|
@ -34,51 +34,6 @@ func TestLexer(t *testing.T) {
|
|||
[]string{"_stream", ":", "{", "foo", "=", "bar", ",", "a", "=~", "baz", ",", "b", "!=", "cd", ",", "d,}a", "!~", "abc", "}"})
|
||||
}
|
||||
|
||||
func TestNewStreamFilterSuccess(t *testing.T) {
|
||||
f := func(s, resultExpected string) {
|
||||
t.Helper()
|
||||
sf, err := newStreamFilter(s)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
result := sf.String()
|
||||
if result != resultExpected {
|
||||
t.Fatalf("unexpected StreamFilter; got %s; want %s", result, resultExpected)
|
||||
}
|
||||
}
|
||||
|
||||
f("{}", "{}")
|
||||
f(`{foo="bar"}`, `{foo="bar"}`)
|
||||
f(`{ "foo" =~ "bar.+" , baz!="a" or x="y"}`, `{foo=~"bar.+",baz!="a" or x="y"}`)
|
||||
f(`{"a b"='c}"d' OR de="aaa"}`, `{"a b"="c}\"d" or de="aaa"}`)
|
||||
f(`{a="b", c="d" or x="y"}`, `{a="b",c="d" or x="y"}`)
|
||||
}
|
||||
|
||||
func TestNewStreamFilterFailure(t *testing.T) {
|
||||
f := func(s string) {
|
||||
t.Helper()
|
||||
sf, err := newStreamFilter(s)
|
||||
if err == nil {
|
||||
t.Fatalf("expecting non-nil error")
|
||||
}
|
||||
if sf != nil {
|
||||
t.Fatalf("expecting nil sf; got %v", sf)
|
||||
}
|
||||
}
|
||||
|
||||
f("")
|
||||
f("}")
|
||||
f("{")
|
||||
f("{foo")
|
||||
f("{foo}")
|
||||
f("{'foo")
|
||||
f("{foo=")
|
||||
f("{foo or bar}")
|
||||
f("{foo=bar")
|
||||
f("{foo=bar baz}")
|
||||
f("{foo='bar' baz='x'}")
|
||||
}
|
||||
|
||||
func TestParseTimeDuration(t *testing.T) {
|
||||
f := func(s string, durationExpected time.Duration) {
|
||||
t.Helper()
|
||||
|
|
|
@ -501,7 +501,7 @@ func TestStorageSearch(t *testing.T) {
|
|||
}
|
||||
})
|
||||
t.Run("stream-filter-mismatch", func(_ *testing.T) {
|
||||
sf := mustNewStreamFilter(`{job="foobar",instance=~"host-.+:2345"}`)
|
||||
sf := mustNewTestStreamFilter(`{job="foobar",instance=~"host-.+:2345"}`)
|
||||
minTimestamp := baseTimestamp
|
||||
maxTimestamp := baseTimestamp + rowsPerBlock*1e9 + blocksPerStream
|
||||
f := getBaseFilter(minTimestamp, maxTimestamp, sf)
|
||||
|
@ -517,7 +517,7 @@ func TestStorageSearch(t *testing.T) {
|
|||
})
|
||||
t.Run("matching-stream-id", func(t *testing.T) {
|
||||
for i := 0; i < streamsPerTenant; i++ {
|
||||
sf := mustNewStreamFilter(fmt.Sprintf(`{job="foobar",instance="host-%d:234"}`, i))
|
||||
sf := mustNewTestStreamFilter(fmt.Sprintf(`{job="foobar",instance="host-%d:234"}`, i))
|
||||
tenantID := TenantID{
|
||||
AccountID: 1,
|
||||
ProjectID: 11,
|
||||
|
@ -543,7 +543,7 @@ func TestStorageSearch(t *testing.T) {
|
|||
}
|
||||
})
|
||||
t.Run("matching-multiple-stream-ids", func(t *testing.T) {
|
||||
sf := mustNewStreamFilter(`{job="foobar",instance=~"host-[^:]+:234"}`)
|
||||
sf := mustNewTestStreamFilter(`{job="foobar",instance=~"host-[^:]+:234"}`)
|
||||
tenantID := TenantID{
|
||||
AccountID: 1,
|
||||
ProjectID: 11,
|
||||
|
@ -568,7 +568,7 @@ func TestStorageSearch(t *testing.T) {
|
|||
}
|
||||
})
|
||||
t.Run("matching-multiple-stream-ids-with-re-filter", func(t *testing.T) {
|
||||
sf := mustNewStreamFilter(`{job="foobar",instance=~"host-[^:]+:234"}`)
|
||||
sf := mustNewTestStreamFilter(`{job="foobar",instance=~"host-[^:]+:234"}`)
|
||||
tenantID := TenantID{
|
||||
AccountID: 1,
|
||||
ProjectID: 11,
|
||||
|
@ -602,7 +602,7 @@ func TestStorageSearch(t *testing.T) {
|
|||
}
|
||||
})
|
||||
t.Run("matching-stream-id-smaller-time-range", func(t *testing.T) {
|
||||
sf := mustNewStreamFilter(`{job="foobar",instance="host-1:234"}`)
|
||||
sf := mustNewTestStreamFilter(`{job="foobar",instance="host-1:234"}`)
|
||||
tenantID := TenantID{
|
||||
AccountID: 1,
|
||||
ProjectID: 11,
|
||||
|
@ -627,7 +627,7 @@ func TestStorageSearch(t *testing.T) {
|
|||
}
|
||||
})
|
||||
t.Run("matching-stream-id-missing-time-range", func(_ *testing.T) {
|
||||
sf := mustNewStreamFilter(`{job="foobar",instance="host-1:234"}`)
|
||||
sf := mustNewTestStreamFilter(`{job="foobar",instance="host-1:234"}`)
|
||||
tenantID := TenantID{
|
||||
AccountID: 1,
|
||||
ProjectID: 11,
|
||||
|
@ -649,11 +649,3 @@ func TestStorageSearch(t *testing.T) {
|
|||
s.MustClose()
|
||||
fs.MustRemoveAll(path)
|
||||
}
|
||||
|
||||
func mustNewStreamFilter(s string) *StreamFilter {
|
||||
sf, err := newStreamFilter(s)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("unexpected error in newStreamFilter(%q): %w", s, err))
|
||||
}
|
||||
return sf
|
||||
}
|
||||
|
|
68
lib/logstorage/stream_filter_test.go
Normal file
68
lib/logstorage/stream_filter_test.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package logstorage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewTestStreamFilterSuccess(t *testing.T) {
|
||||
f := func(s, resultExpected string) {
|
||||
t.Helper()
|
||||
sf, err := newTestStreamFilter(s)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
result := sf.String()
|
||||
if result != resultExpected {
|
||||
t.Fatalf("unexpected StreamFilter; got %s; want %s", result, resultExpected)
|
||||
}
|
||||
}
|
||||
|
||||
f("{}", "{}")
|
||||
f(`{foo="bar"}`, `{foo="bar"}`)
|
||||
f(`{ "foo" =~ "bar.+" , baz!="a" or x="y"}`, `{foo=~"bar.+",baz!="a" or x="y"}`)
|
||||
f(`{"a b"='c}"d' OR de="aaa"}`, `{"a b"="c}\"d" or de="aaa"}`)
|
||||
f(`{a="b", c="d" or x="y"}`, `{a="b",c="d" or x="y"}`)
|
||||
}
|
||||
|
||||
func TestNewTestStreamFilterFailure(t *testing.T) {
|
||||
f := func(s string) {
|
||||
t.Helper()
|
||||
sf, err := newTestStreamFilter(s)
|
||||
if err == nil {
|
||||
t.Fatalf("expecting non-nil error")
|
||||
}
|
||||
if sf != nil {
|
||||
t.Fatalf("expecting nil sf; got %v", sf)
|
||||
}
|
||||
}
|
||||
|
||||
f("")
|
||||
f("}")
|
||||
f("{")
|
||||
f("{foo")
|
||||
f("{foo}")
|
||||
f("{'foo")
|
||||
f("{foo=")
|
||||
f("{foo or bar}")
|
||||
f("{foo=bar")
|
||||
f("{foo=bar baz}")
|
||||
f("{foo='bar' baz='x'}")
|
||||
}
|
||||
|
||||
func mustNewTestStreamFilter(s string) *StreamFilter {
|
||||
sf, err := newTestStreamFilter(s)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("unexpected error in newTestStreamFilter(%q): %w", s, err))
|
||||
}
|
||||
return sf
|
||||
}
|
||||
|
||||
func newTestStreamFilter(s string) (*StreamFilter, error) {
|
||||
lex := newLexer(s)
|
||||
fs, err := parseFilterStream(lex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.f, nil
|
||||
}
|
Loading…
Reference in a new issue