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
|
|
|
)
|
|
|
|
|
2024-07-09 22:32:54 +02:00
|
|
|
func TestAddHTTPTargetLabels(t *testing.T) {
|
|
|
|
f := func(src []httpGroupTarget, labelssExpected []*promutils.Labels) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
labelss := addHTTPTargetLabels(src, "http://foo.bar/baz?aaa=bb")
|
|
|
|
discoveryutils.TestEqualLabelss(t, labelss, labelssExpected)
|
2021-06-22 12:33:37 +02:00
|
|
|
}
|
2024-07-09 22:32:54 +02:00
|
|
|
|
|
|
|
// add ok
|
|
|
|
src := []httpGroupTarget{
|
2021-06-22 12:33:37 +02:00
|
|
|
{
|
2024-07-09 22:32:54 +02:00
|
|
|
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"}),
|
2021-06-22 12:33:37 +02:00
|
|
|
},
|
|
|
|
}
|
2024-07-09 22:32:54 +02:00
|
|
|
labelssExpected := []*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",
|
|
|
|
}),
|
2021-06-22 12:33:37 +02:00
|
|
|
}
|
2024-07-09 22:32:54 +02:00
|
|
|
f(src, labelssExpected)
|
2021-06-22 12:33:37 +02:00
|
|
|
}
|