mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
lib/promscrape/discovery: add a benchmark for measuring the performance of creating pod meta-labels
This commit is contained in:
parent
002c028f22
commit
2524d94fe1
@ -289,6 +289,18 @@ func TestParseNodeListSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func getSortedLabelss(objectsByKey map[string]object) [][]prompbmarshal.Label {
|
||||
gw := newTestGroupWatcher()
|
||||
var result [][]prompbmarshal.Label
|
||||
for _, o := range objectsByKey {
|
||||
labelss := o.getTargetLabels(gw)
|
||||
for _, labels := range labelss {
|
||||
result = append(result, discoveryutils.GetSortedLabels(labels))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func newTestGroupWatcher() *groupWatcher {
|
||||
var gw groupWatcher
|
||||
gw.m = map[string]*urlWatcher{
|
||||
"node": {
|
||||
@ -308,14 +320,7 @@ func getSortedLabelss(objectsByKey map[string]object) [][]prompbmarshal.Label {
|
||||
},
|
||||
}
|
||||
gw.attachNodeMetadata = true
|
||||
var result [][]prompbmarshal.Label
|
||||
for _, o := range objectsByKey {
|
||||
labelss := o.getTargetLabels(&gw)
|
||||
for _, labels := range labelss {
|
||||
result = append(result, discoveryutils.GetSortedLabels(labels))
|
||||
}
|
||||
}
|
||||
return result
|
||||
return &gw
|
||||
}
|
||||
|
||||
func areEqualLabelss(a, b [][]prompbmarshal.Label) bool {
|
||||
|
@ -26,8 +26,7 @@ func TestParsePodListFailure(t *testing.T) {
|
||||
f(`{"items":[{"metadata":{"labels":[1]}}]}`)
|
||||
}
|
||||
|
||||
func TestParsePodListSuccess(t *testing.T) {
|
||||
data := `
|
||||
const testPodsList = `
|
||||
{
|
||||
"kind": "PodList",
|
||||
"apiVersion": "v1",
|
||||
@ -229,7 +228,9 @@ func TestParsePodListSuccess(t *testing.T) {
|
||||
]
|
||||
}
|
||||
`
|
||||
r := bytes.NewBufferString(data)
|
||||
|
||||
func TestParsePodListSuccess(t *testing.T) {
|
||||
r := bytes.NewBufferString(testPodsList)
|
||||
objectsByKey, meta, err := parsePodList(r)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
|
34
lib/promscrape/discovery/kubernetes/pod_timing_test.go
Normal file
34
lib/promscrape/discovery/kubernetes/pod_timing_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkPodGetTargetLabels(b *testing.B) {
|
||||
r := bytes.NewBufferString(testPodsList)
|
||||
objectsByKey, _, err := parsePodList(r)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("BUG: unexpected error: %s", err))
|
||||
}
|
||||
var o object
|
||||
for _, srcObject := range objectsByKey {
|
||||
o = srcObject
|
||||
break
|
||||
}
|
||||
if o == nil {
|
||||
panic(fmt.Errorf("BUG: expecting at least a single pod object"))
|
||||
}
|
||||
gw := newTestGroupWatcher()
|
||||
b.ReportAllocs()
|
||||
b.SetBytes(1)
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
labelss := o.getTargetLabels(gw)
|
||||
if len(labelss) != 1 {
|
||||
panic(fmt.Errorf("BUG: unexpected number of labelss returned: %d; want 1", len(labelss)))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user