2022-11-16 22:02:21 +01:00
|
|
|
package promscrape
|
|
|
|
|
|
|
|
import (
|
2022-11-30 06:22:12 +01:00
|
|
|
"fmt"
|
2022-11-16 22:02:21 +01:00
|
|
|
"testing"
|
|
|
|
|
2022-11-30 06:22:12 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
2022-11-16 22:02:21 +01:00
|
|
|
)
|
|
|
|
|
2022-11-30 06:22:12 +01:00
|
|
|
func BenchmarkGetScrapeWork(b *testing.B) {
|
|
|
|
swc := &scrapeWorkConfig{
|
|
|
|
jobName: "job-1",
|
|
|
|
scheme: "http",
|
|
|
|
metricsPath: "/metrics",
|
|
|
|
scrapeIntervalString: "30s",
|
|
|
|
scrapeTimeoutString: "10s",
|
|
|
|
}
|
|
|
|
target := "host1.com:1234"
|
|
|
|
extraLabels := promutils.NewLabelsFromMap(map[string]string{
|
|
|
|
"env": "prod",
|
|
|
|
"datacenter": "dc-foo",
|
|
|
|
})
|
|
|
|
metaLabels := promutils.NewLabelsFromMap(map[string]string{
|
|
|
|
"__meta_foo": "bar",
|
|
|
|
"__meta_kubernetes_namespace": "default",
|
|
|
|
"__address__": "foobar.com",
|
|
|
|
"__meta_sfdfdf_dsfds_fdfdfds_fdfdfd": "true",
|
|
|
|
})
|
2022-11-16 22:02:21 +01:00
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(1)
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2022-11-30 06:22:12 +01:00
|
|
|
sw, err := swc.getScrapeWork(target, extraLabels, metaLabels)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("BUG: getScrapeWork returned non-nil error: %w", err))
|
|
|
|
}
|
|
|
|
if sw == nil {
|
|
|
|
panic(fmt.Errorf("BUG: getScrapeWork returned nil ScrapeWork"))
|
|
|
|
}
|
2022-11-16 22:02:21 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|