|
|
|
@ -12,15 +12,15 @@ import ( |
|
|
|
|
|
|
|
|
|
func TestNoopPipeline(t *testing.T) { |
|
|
|
|
lbs := labels.Labels{{Name: "foo", Value: "bar"}} |
|
|
|
|
l, lbr, ok := NewNoopPipeline().ForStream(lbs).Process(0, []byte("")) |
|
|
|
|
l, lbr, matches := NewNoopPipeline().ForStream(lbs).Process(0, []byte("")) |
|
|
|
|
require.Equal(t, []byte(""), l) |
|
|
|
|
require.Equal(t, NewLabelsResult(lbs, lbs.Hash()), lbr) |
|
|
|
|
require.Equal(t, true, ok) |
|
|
|
|
require.Equal(t, true, matches) |
|
|
|
|
|
|
|
|
|
ls, lbr, ok := NewNoopPipeline().ForStream(lbs).ProcessString(0, "") |
|
|
|
|
ls, lbr, matches := NewNoopPipeline().ForStream(lbs).ProcessString(0, "") |
|
|
|
|
require.Equal(t, "", ls) |
|
|
|
|
require.Equal(t, NewLabelsResult(lbs, lbs.Hash()), lbr) |
|
|
|
|
require.Equal(t, true, ok) |
|
|
|
|
require.Equal(t, true, matches) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestPipeline(t *testing.T) { |
|
|
|
@ -29,25 +29,25 @@ func TestPipeline(t *testing.T) { |
|
|
|
|
NewStringLabelFilter(labels.MustNewMatcher(labels.MatchEqual, "foo", "bar")), |
|
|
|
|
newMustLineFormatter("lbs {{.foo}}"), |
|
|
|
|
}) |
|
|
|
|
l, lbr, ok := p.ForStream(lbs).Process(0, []byte("line")) |
|
|
|
|
l, lbr, matches := p.ForStream(lbs).Process(0, []byte("line")) |
|
|
|
|
require.Equal(t, []byte("lbs bar"), l) |
|
|
|
|
require.Equal(t, NewLabelsResult(lbs, lbs.Hash()), lbr) |
|
|
|
|
require.Equal(t, true, ok) |
|
|
|
|
require.Equal(t, true, matches) |
|
|
|
|
|
|
|
|
|
ls, lbr, ok := p.ForStream(lbs).ProcessString(0, "line") |
|
|
|
|
ls, lbr, matches := p.ForStream(lbs).ProcessString(0, "line") |
|
|
|
|
require.Equal(t, "lbs bar", ls) |
|
|
|
|
require.Equal(t, NewLabelsResult(lbs, lbs.Hash()), lbr) |
|
|
|
|
require.Equal(t, true, ok) |
|
|
|
|
require.Equal(t, true, matches) |
|
|
|
|
|
|
|
|
|
l, lbr, ok = p.ForStream(labels.Labels{}).Process(0, []byte("line")) |
|
|
|
|
l, lbr, matches = p.ForStream(labels.Labels{}).Process(0, []byte("line")) |
|
|
|
|
require.Equal(t, []byte(nil), l) |
|
|
|
|
require.Equal(t, nil, lbr) |
|
|
|
|
require.Equal(t, false, ok) |
|
|
|
|
require.Equal(t, false, matches) |
|
|
|
|
|
|
|
|
|
ls, lbr, ok = p.ForStream(labels.Labels{}).ProcessString(0, "line") |
|
|
|
|
ls, lbr, matches = p.ForStream(labels.Labels{}).ProcessString(0, "line") |
|
|
|
|
require.Equal(t, "", ls) |
|
|
|
|
require.Equal(t, nil, lbr) |
|
|
|
|
require.Equal(t, false, ok) |
|
|
|
|
require.Equal(t, false, matches) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestFilteringPipeline(t *testing.T) { |
|
|
|
@ -74,11 +74,11 @@ func TestFilteringPipeline(t *testing.T) { |
|
|
|
|
|
|
|
|
|
for _, test := range tt { |
|
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
_, _, ok := p.ForStream(test.inputStreamLabels).Process(test.ts, []byte(test.line)) |
|
|
|
|
require.Equal(t, test.ok, ok) |
|
|
|
|
_, _, matches := p.ForStream(test.inputStreamLabels).Process(test.ts, []byte(test.line)) |
|
|
|
|
require.Equal(t, test.ok, matches) |
|
|
|
|
|
|
|
|
|
_, _, ok = p.ForStream(test.inputStreamLabels).ProcessString(test.ts, test.line) |
|
|
|
|
require.Equal(t, test.ok, ok) |
|
|
|
|
_, _, matches = p.ForStream(test.inputStreamLabels).ProcessString(test.ts, test.line) |
|
|
|
|
require.Equal(t, test.ok, matches) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -127,7 +127,7 @@ func (p *stubStreamPipeline) ProcessString(ts int64, line string) (string, Label |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
resOK bool |
|
|
|
|
resMatches bool |
|
|
|
|
resLine []byte |
|
|
|
|
resLineString string |
|
|
|
|
resLbs LabelsResult |
|
|
|
@ -168,13 +168,13 @@ func Benchmark_Pipeline(b *testing.B) { |
|
|
|
|
b.Run("pipeline bytes", func(b *testing.B) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resLine, resLbs, resOK = sp.Process(0, line) |
|
|
|
|
resLine, resLbs, resMatches = sp.Process(0, line) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
b.Run("pipeline string", func(b *testing.B) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resLineString, resLbs, resOK = sp.ProcessString(0, lineString) |
|
|
|
|
resLineString, resLbs, resMatches = sp.ProcessString(0, lineString) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -184,13 +184,13 @@ func Benchmark_Pipeline(b *testing.B) { |
|
|
|
|
b.Run("line extractor bytes", func(b *testing.B) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resSample, resLbs, resOK = ex.Process(0, line) |
|
|
|
|
resSample, resLbs, resMatches = ex.Process(0, line) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
b.Run("line extractor string", func(b *testing.B) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resSample, resLbs, resOK = ex.ProcessString(0, lineString) |
|
|
|
|
resSample, resLbs, resMatches = ex.ProcessString(0, lineString) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -201,13 +201,13 @@ func Benchmark_Pipeline(b *testing.B) { |
|
|
|
|
b.Run("label extractor bytes", func(b *testing.B) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resSample, resLbs, resOK = ex.Process(0, line) |
|
|
|
|
resSample, resLbs, resMatches = ex.Process(0, line) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
b.Run("label extractor string", func(b *testing.B) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resSample, resLbs, resOK = ex.ProcessString(0, lineString) |
|
|
|
|
resSample, resLbs, resMatches = ex.ProcessString(0, lineString) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
@ -240,9 +240,9 @@ func jsonBenchmark(b *testing.B, parser Stage) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
sp := p.ForStream(lbs) |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resLine, resLbs, resOK = sp.Process(0, line) |
|
|
|
|
resLine, resLbs, resMatches = sp.Process(0, line) |
|
|
|
|
|
|
|
|
|
if !resOK { |
|
|
|
|
if !resMatches { |
|
|
|
|
b.Fatalf("resulting line not ok: %s\n", line) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -263,9 +263,9 @@ func invalidJSONBenchmark(b *testing.B, parser Stage) { |
|
|
|
|
b.ResetTimer() |
|
|
|
|
sp := p.ForStream(labels.Labels{}) |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
resLine, resLbs, resOK = sp.Process(0, line) |
|
|
|
|
resLine, resLbs, resMatches = sp.Process(0, line) |
|
|
|
|
|
|
|
|
|
if !resOK { |
|
|
|
|
if !resMatches { |
|
|
|
|
b.Fatalf("resulting line not ok: %s\n", line) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|