mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
f325410c26
- Return meta-labels for the discovered targets via promutils.Labels instead of map[string]string. This improves the speed of generating meta-labels for discovered targets by up to 5x. - Remove memory allocations in hot paths during ScrapeWork generation. The ScrapeWork contains scrape settings for a single discovered target. This improves the service discovery speed by up to 2x.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package http
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
)
|
|
|
|
func Test_addHTTPTargetLabels(t *testing.T) {
|
|
type args struct {
|
|
src []httpGroupTarget
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []*promutils.Labels
|
|
}{
|
|
{
|
|
name: "add ok",
|
|
args: args{
|
|
src: []httpGroupTarget{
|
|
{
|
|
Targets: []string{"127.0.0.1:9100", "127.0.0.2:91001"},
|
|
Labels: promutils.NewLabelsFromMap(map[string]string{"__meta_kubernetes_pod": "pod-1", "__meta_consul_dc": "dc-2"}),
|
|
},
|
|
},
|
|
},
|
|
want: []*promutils.Labels{
|
|
promutils.NewLabelsFromMap(map[string]string{
|
|
"__address__": "127.0.0.1:9100",
|
|
"__meta_kubernetes_pod": "pod-1",
|
|
"__meta_consul_dc": "dc-2",
|
|
"__meta_url": "http://foo.bar/baz?aaa=bb",
|
|
}),
|
|
promutils.NewLabelsFromMap(map[string]string{
|
|
"__address__": "127.0.0.2:91001",
|
|
"__meta_kubernetes_pod": "pod-1",
|
|
"__meta_consul_dc": "dc-2",
|
|
"__meta_url": "http://foo.bar/baz?aaa=bb",
|
|
}),
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := addHTTPTargetLabels(tt.args.src, "http://foo.bar/baz?aaa=bb")
|
|
discoveryutils.TestEqualLabelss(t, got, tt.want)
|
|
})
|
|
}
|
|
}
|