From 4f0e6b99e853b4b0f8acbc1d5c974aa86c714836 Mon Sep 17 00:00:00 2001 From: Manik Rana Date: Fri, 20 Sep 2024 11:43:04 +0530 Subject: [PATCH] refac: move OM ct benchmark to promparse_test Signed-off-by: Manik Rana --- model/textparse/omtestdata.txt | 24 ++++++++++++ model/textparse/openmetricsparse_test.go | 48 ------------------------ model/textparse/promparse_test.go | 39 ++++++++++++++++++- 3 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 model/textparse/omtestdata.txt diff --git a/model/textparse/omtestdata.txt b/model/textparse/omtestdata.txt new file mode 100644 index 000000000..62e43048a --- /dev/null +++ b/model/textparse/omtestdata.txt @@ -0,0 +1,24 @@ +# HELP foo Counter with and without labels to certify CT is parsed for both cases +# TYPE foo counter +foo_total 17.0 1520879607.789 # {id="counter-test"} 5 +foo_created 1000 +foo_total{a="b"} 17.0 1520879607.789 # {id="counter-test"} 5 +foo_created{a="b"} 1000 +# HELP bar Summary with CT at the end, making sure we find CT even if it's multiple lines a far +# TYPE bar summary +bar_count 17.0 +bar_sum 324789.3 +bar{quantile="0.95"} 123.7 +bar{quantile="0.99"} 150.0 +bar_created 1520430000 +# HELP baz Histogram with the same objective as above's summary +# TYPE baz histogram +baz_bucket{le="0.0"} 0 +baz_bucket{le="+Inf"} 17 +baz_count 17 +baz_sum 324789.3 +baz_created 1520430000 +# HELP fizz_created Gauge which shouldn't be parsed as CT +# TYPE fizz_created gauge +fizz_created 17.0 +# EOF diff --git a/model/textparse/openmetricsparse_test.go b/model/textparse/openmetricsparse_test.go index b8c2d522e..cadaabc99 100644 --- a/model/textparse/openmetricsparse_test.go +++ b/model/textparse/openmetricsparse_test.go @@ -992,51 +992,3 @@ go_gc_duration_seconds_created`) require.Equal(t, "go_gc_duration_seconds", string(copyParser.l.b[copyParser.offsets[0]:copyParser.offsets[1]])) require.False(t, copyParser.skipCTSeries) } - -func BenchmarkCTParse(b *testing.B) { - b.ReportAllocs() - - input := `# HELP foo Counter with and without labels to certify CT is parsed for both cases -# TYPE foo counter -foo_total 17.0 1520879607.789 # {id="counter-test"} 5 -foo_created 1000 -foo_total{a="b"} 17.0 1520879607.789 # {id="counter-test"} 5 -foo_created{a="b"} 1000 -# HELP bar Summary with CT at the end, making sure we find CT even if it's multiple lines a far -# TYPE bar summary -bar_count 17.0 -bar_sum 324789.3 -bar{quantile="0.95"} 123.7 -bar{quantile="0.99"} 150.0 -bar_created 1520430000 -# HELP baz Histogram with the same objective as above's summary -# TYPE baz histogram -baz_bucket{le="0.0"} 0 -baz_bucket{le="+Inf"} 17 -baz_count 17 -baz_sum 324789.3 -baz_created 1520430000 -# HELP fizz_created Gauge which shouldn't be parsed as CT -# TYPE fizz_created gauge -fizz_created 17.0` - - input += "\n# EOF\n" - - b.ResetTimer() - for i := 0; i < b.N; i++ { - p := NewOpenMetricsParser([]byte(input), labels.NewSymbolTable(), WithOMParserCTSeriesSkipped()) - Outer: - for { - et, err := p.Next() - switch et { - case EntryInvalid: - if errors.Is(err, io.EOF) { - break Outer - } - b.Fatal(err) - case EntrySeries: - p.CreatedTimestamp() - } - } - } -} diff --git a/model/textparse/promparse_test.go b/model/textparse/promparse_test.go index 992140ce0..16a99bd70 100644 --- a/model/textparse/promparse_test.go +++ b/model/textparse/promparse_test.go @@ -498,8 +498,16 @@ func BenchmarkParse(b *testing.B) { "openmetrics": func(b []byte, st *labels.SymbolTable) Parser { return NewOpenMetricsParser(b, st) }, + "openmetrics/skip-ct": func(b []byte, st *labels.SymbolTable) Parser { + return NewOpenMetricsParser(b, st, WithOMParserCTSeriesSkipped()) + }, } { - for _, fn := range []string{"promtestdata.txt", "promtestdata.nometa.txt"} { + for _, fn := range []string{"promtestdata.txt", "promtestdata.nometa.txt", "omtestdata.txt"} { + // we only want to benchmark om parsers with omtestdata + if fn == "omtestdata.txt" && parserName == "prometheus" { + continue + } + f, err := os.Open(fn) require.NoError(b, err) defer f.Close() @@ -631,6 +639,35 @@ func BenchmarkParse(b *testing.B) { } _ = total }) + b.Run(parserName+"/created-lines/"+fn, func(b *testing.B) { + b.SetBytes(int64(len(buf) / promtestdataSampleCount)) + b.ReportAllocs() + b.ResetTimer() + + total := 0 + + st := labels.NewSymbolTable() + for i := 0; i < b.N; i += promtestdataSampleCount { + p := parser(buf, st) + + Outer: + for i < b.N { + t, err := p.Next() + switch t { + case EntryInvalid: + if errors.Is(err, io.EOF) { + break Outer + } + b.Fatal(err) + case EntrySeries: + if parserName == "openmetrics/skip-ct" { + p.CreatedTimestamp() + } + } + } + } + _ = total + }) } } }