2020-02-23 11:35:47 +00:00
|
|
|
package promscrape
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-08-08 11:46:24 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/auth"
|
2024-01-30 15:51:44 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
2020-02-23 11:35:47 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
|
|
)
|
|
|
|
|
2022-11-29 02:37:06 +00:00
|
|
|
func BenchmarkIsAutoMetricMiss(b *testing.B) {
|
|
|
|
metrics := []string{
|
|
|
|
"process_cpu_seconds_total",
|
|
|
|
"process_resident_memory_bytes",
|
|
|
|
"vm_tcplistener_read_calls_total",
|
|
|
|
"http_requests_total",
|
|
|
|
"node_cpu_seconds_total",
|
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(1)
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, metric := range metrics {
|
|
|
|
if isAutoMetric(metric) {
|
|
|
|
panic(fmt.Errorf("BUG: %q mustn't be detected as auto metric", metric))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIsAutoMetricHit(b *testing.B) {
|
|
|
|
metrics := []string{
|
|
|
|
"up",
|
|
|
|
"scrape_duration_seconds",
|
|
|
|
"scrape_series_current",
|
|
|
|
"scrape_samples_scraped",
|
|
|
|
"scrape_series_added",
|
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(1)
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, metric := range metrics {
|
|
|
|
if !isAutoMetric(metric) {
|
|
|
|
panic(fmt.Errorf("BUG: %q must be detected as auto metric", metric))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-23 11:35:47 +00:00
|
|
|
func BenchmarkScrapeWorkScrapeInternal(b *testing.B) {
|
|
|
|
data := `
|
|
|
|
vm_tcplistener_accepts_total{name="http", addr=":80"} 1443
|
|
|
|
vm_tcplistener_accepts_total{name="https", addr=":443"} 12801
|
|
|
|
vm_tcplistener_conns{name="http", addr=":80"} 0
|
|
|
|
vm_tcplistener_conns{name="https", addr=":443"} 2
|
|
|
|
vm_tcplistener_errors_total{name="http", addr=":80", type="accept"} 0
|
|
|
|
vm_tcplistener_errors_total{name="http", addr=":80", type="close"} 0
|
|
|
|
vm_tcplistener_errors_total{name="http", addr=":80", type="read"} 97
|
|
|
|
vm_tcplistener_errors_total{name="http", addr=":80", type="write"} 2
|
|
|
|
vm_tcplistener_errors_total{name="https", addr=":443", type="accept"} 0
|
|
|
|
vm_tcplistener_errors_total{name="https", addr=":443", type="close"} 0
|
|
|
|
vm_tcplistener_errors_total{name="https", addr=":443", type="read"} 243
|
|
|
|
vm_tcplistener_errors_total{name="https", addr=":443", type="write"} 285
|
|
|
|
vm_tcplistener_read_bytes_total{name="http", addr=":80"} 879339
|
|
|
|
vm_tcplistener_read_bytes_total{name="https", addr=":443"} 19453340
|
|
|
|
vm_tcplistener_read_calls_total{name="http", addr=":80"} 7780
|
|
|
|
vm_tcplistener_read_calls_total{name="https", addr=":443"} 70323
|
|
|
|
vm_tcplistener_read_timeouts_total{name="http", addr=":80"} 673
|
|
|
|
vm_tcplistener_read_timeouts_total{name="https", addr=":443"} 12353
|
|
|
|
vm_tcplistener_write_calls_total{name="http", addr=":80"} 3996
|
|
|
|
vm_tcplistener_write_calls_total{name="https", addr=":443"} 132356
|
|
|
|
`
|
2024-01-30 15:51:44 +00:00
|
|
|
readDataFunc := func(dst *bytesutil.ByteBuffer) error {
|
|
|
|
dst.B = append(dst.B, data...)
|
|
|
|
return nil
|
2020-02-23 11:35:47 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(int64(len(data)))
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
var sw scrapeWork
|
2020-12-17 12:30:33 +00:00
|
|
|
sw.Config = &ScrapeWork{}
|
2020-02-23 11:35:47 +00:00
|
|
|
sw.ReadData = readDataFunc
|
2024-04-02 20:16:24 +00:00
|
|
|
sw.PushData = func(_ *auth.Token, _ *prompbmarshal.WriteRequest) {}
|
2024-01-30 14:05:36 +00:00
|
|
|
tsmGlobal.Register(&sw)
|
2020-02-23 11:35:47 +00:00
|
|
|
timestamp := int64(0)
|
|
|
|
for pb.Next() {
|
2020-08-10 09:31:59 +00:00
|
|
|
if err := sw.scrapeInternal(timestamp, timestamp); err != nil {
|
2020-06-30 19:58:18 +00:00
|
|
|
panic(fmt.Errorf("unexpected error: %w", err))
|
2020-02-23 11:35:47 +00:00
|
|
|
}
|
|
|
|
timestamp++
|
|
|
|
}
|
2024-01-30 14:05:36 +00:00
|
|
|
tsmGlobal.Unregister(&sw)
|
2020-02-23 11:35:47 +00:00
|
|
|
})
|
|
|
|
}
|