The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/promlib/converter/prom_bench_test.go

45 lines
1.2 KiB

package converter
import (
"os"
"testing"
jsoniter "github.com/json-iterator/go"
)
// readTestData reads a JSON file from testdata directory
func readTestData(t *testing.B, filename string) []byte {
// Can ignore gosec G304 here, because this is a constant defined below benchmark test
// nolint:gosec
data, err := os.ReadFile("testdata/" + filename)
if err != nil {
t.Fatal(err)
}
return data
}
// BenchmarkReadPrometheusStyleResult_FromFile benchmarks processing different test files
// go test -benchmem -run=^$ -bench=BenchmarkReadPrometheusStyleResult_FromFile$ github.com/grafana/grafana/pkg/promlib/converter/ -memprofile pmem.out -count 6 | tee pmem.0.txt
func BenchmarkReadPrometheusStyleResult_FromFile(b *testing.B) {
testFiles := []string{
"prom-query-range.json",
"prom-query-range-big.json",
"prom-matrix-histogram-partitioned.json",
}
opt := Options{Dataplane: true}
for _, tf := range testFiles {
testData := readTestData(b, tf)
iter := jsoniter.ParseBytes(jsoniter.ConfigDefault, testData)
b.Run(tf, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ReadPrometheusStyleResult(iter, opt)
iter.ResetBytes(testData)
}
})
}
}