2021-06-22 12:33:37 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
2022-11-30 06:22:12 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
2021-06-22 12:33:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_addHTTPTargetLabels(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
src []httpGroupTarget
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2022-11-30 06:22:12 +01:00
|
|
|
want []*promutils.Labels
|
2021-06-22 12:33:37 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "add ok",
|
|
|
|
args: args{
|
|
|
|
src: []httpGroupTarget{
|
|
|
|
{
|
|
|
|
Targets: []string{"127.0.0.1:9100", "127.0.0.2:91001"},
|
2022-11-30 06:22:12 +01:00
|
|
|
Labels: promutils.NewLabelsFromMap(map[string]string{"__meta_kubernetes_pod": "pod-1", "__meta_consul_dc": "dc-2"}),
|
2021-06-22 12:33:37 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-11-30 06:22:12 +01:00
|
|
|
want: []*promutils.Labels{
|
|
|
|
promutils.NewLabelsFromMap(map[string]string{
|
2021-06-22 12:40:33 +02:00
|
|
|
"__address__": "127.0.0.1:9100",
|
|
|
|
"__meta_kubernetes_pod": "pod-1",
|
|
|
|
"__meta_consul_dc": "dc-2",
|
|
|
|
"__meta_url": "http://foo.bar/baz?aaa=bb",
|
2021-06-22 12:33:37 +02:00
|
|
|
}),
|
2022-11-30 06:22:12 +01:00
|
|
|
promutils.NewLabelsFromMap(map[string]string{
|
2021-06-22 12:40:33 +02:00
|
|
|
"__address__": "127.0.0.2:91001",
|
|
|
|
"__meta_kubernetes_pod": "pod-1",
|
|
|
|
"__meta_consul_dc": "dc-2",
|
|
|
|
"__meta_url": "http://foo.bar/baz?aaa=bb",
|
2021-06-22 12:33:37 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-06-22 12:40:33 +02:00
|
|
|
got := addHTTPTargetLabels(tt.args.src, "http://foo.bar/baz?aaa=bb")
|
2022-11-30 06:22:12 +01:00
|
|
|
discoveryutils.TestEqualLabelss(t, got, tt.want)
|
2021-06-22 12:33:37 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|