mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-18 22:52:11 +01:00
bd6405df01
Address `non-constant format string in call` check:
https://github.com/golang/go/issues/60529
Signed-off-by: hagen1778 <roman@victoriametrics.com>
(cherry picked from commit febba3971b
)
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package datasource
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkMetrics(b *testing.B) {
|
|
payload := []byte(`[{"metric":{"__name__":"vm_rows"},"value":[1583786142,"13763"]},{"metric":{"__name__":"vm_requests", "foo":"bar", "baz": "qux"},"value":[1583786140,"2000"]}]`)
|
|
|
|
var pi promInstant
|
|
if err := pi.Unmarshal(payload); err != nil {
|
|
b.Fatal(err.Error())
|
|
}
|
|
b.Run("Instant", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, _ = pi.metrics()
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkParsePrometheusResponse(b *testing.B) {
|
|
req, _ := http.NewRequest("GET", "", nil)
|
|
resp := &http.Response{StatusCode: http.StatusOK}
|
|
data, err := os.ReadFile("testdata/instant_response.json")
|
|
if err != nil {
|
|
b.Fatalf("error while reading file: %s", err)
|
|
}
|
|
resp.Body = io.NopCloser(bytes.NewReader(data))
|
|
|
|
b.Run("Instant", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := parsePrometheusResponse(req, resp)
|
|
if err != nil {
|
|
b.Fatalf("unexpected parse err: %s", err)
|
|
}
|
|
resp.Body = io.NopCloser(bytes.NewReader(data))
|
|
}
|
|
})
|
|
}
|