mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
web/api: extend BenchmarkRespond with more types of data
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
657da2eb98
commit
54e1046616
|
@ -3417,14 +3417,31 @@ func TestReturnAPIError(t *testing.T) {
|
|||
var testResponseWriter = httptest.ResponseRecorder{}
|
||||
|
||||
func BenchmarkRespond(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
request, err := http.NewRequest(http.MethodGet, "/does-not-matter", nil)
|
||||
require.NoError(b, err)
|
||||
points := []promql.FPoint{}
|
||||
for i := 0; i < 10000; i++ {
|
||||
points = append(points, promql.FPoint{F: float64(i * 1000000), T: int64(i)})
|
||||
}
|
||||
response := &QueryData{
|
||||
matrix := promql.Matrix{}
|
||||
for i := 0; i < 1000; i++ {
|
||||
matrix = append(matrix, promql.Series{
|
||||
Metric: labels.FromStrings("__name__", fmt.Sprintf("series%v", i),
|
||||
"label", fmt.Sprintf("series%v", i),
|
||||
"label2", fmt.Sprintf("series%v", i)),
|
||||
Floats: points[:10],
|
||||
})
|
||||
}
|
||||
series := []labels.Labels{}
|
||||
for i := 0; i < 1000; i++ {
|
||||
series = append(series, labels.FromStrings("__name__", fmt.Sprintf("series%v", i),
|
||||
"label", fmt.Sprintf("series%v", i),
|
||||
"label2", fmt.Sprintf("series%v", i)))
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
response interface{}
|
||||
}{
|
||||
{name: "10000 points no labels", response: &QueryData{
|
||||
ResultType: parser.ValueTypeMatrix,
|
||||
Result: promql.Matrix{
|
||||
promql.Series{
|
||||
|
@ -3432,12 +3449,25 @@ func BenchmarkRespond(b *testing.B) {
|
|||
Metric: labels.EmptyLabels(),
|
||||
},
|
||||
},
|
||||
}},
|
||||
{name: "1000 labels", response: series},
|
||||
{name: "1000 series 10 points", response: &QueryData{
|
||||
ResultType: parser.ValueTypeMatrix,
|
||||
Result: matrix,
|
||||
}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
b.Run(c.name, func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
request, err := http.NewRequest(http.MethodGet, "/does-not-matter", nil)
|
||||
require.NoError(b, err)
|
||||
b.ResetTimer()
|
||||
api := API{}
|
||||
api.InstallCodec(JSONCodec{})
|
||||
for n := 0; n < b.N; n++ {
|
||||
api.respond(&testResponseWriter, request, response, nil)
|
||||
api.respond(&testResponseWriter, request, c.response, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue