2021-06-22 12:33:37 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_addHTTPTargetLabels(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
src []httpGroupTarget
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want [][]prompbmarshal.Label
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "add ok",
|
|
|
|
args: args{
|
|
|
|
src: []httpGroupTarget{
|
|
|
|
{
|
|
|
|
Targets: []string{"127.0.0.1:9100", "127.0.0.2:91001"},
|
2021-06-22 12:40:33 +02:00
|
|
|
Labels: map[string]string{"__meta_kubernetes_pod": "pod-1", "__meta_consul_dc": "dc-2"},
|
2021-06-22 12:33:37 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: [][]prompbmarshal.Label{
|
|
|
|
discoveryutils.GetSortedLabels(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
|
|
|
}),
|
|
|
|
discoveryutils.GetSortedLabels(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")
|
2021-06-22 12:33:37 +02:00
|
|
|
var sortedLabelss [][]prompbmarshal.Label
|
|
|
|
for _, labels := range got {
|
|
|
|
sortedLabelss = append(sortedLabelss, discoveryutils.GetSortedLabels(labels))
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(sortedLabelss, tt.want) {
|
|
|
|
t.Errorf("addHTTPTargetLabels() \ngot \n%v\n, \nwant \n%v\n", sortedLabelss, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|