From 68a117a25a6d5c4b0a517712a3e6318ab2c1d198 Mon Sep 17 00:00:00 2001 From: Alexander Shtuchkin Date: Tue, 11 Jan 2022 01:59:06 -0500 Subject: [PATCH] Fix for #2038: Make correct __address__ value for dockerswarm promscrape (#2041) --- lib/promscrape/discovery/dockerswarm/tasks.go | 3 ++- lib/promscrape/discovery/dockerswarm/tasks_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/promscrape/discovery/dockerswarm/tasks.go b/lib/promscrape/discovery/dockerswarm/tasks.go index 4cd4b7dca..416fc6f38 100644 --- a/lib/promscrape/discovery/dockerswarm/tasks.go +++ b/lib/promscrape/discovery/dockerswarm/tasks.go @@ -94,6 +94,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []map[string]strin } addLabels(commonLabels, servicesLabels, "__meta_dockerswarm_service_id", task.ServiceID) addLabels(commonLabels, nodesLabels, "__meta_dockerswarm_node_id", task.NodeID) + delete(commonLabels, "__address__") for _, port := range task.Status.PortStatus.Ports { if port.Protocol != "tcp" { @@ -121,7 +122,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []map[string]strin continue } m := map[string]string{ - "__address": discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort), + "__address__": discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort), "__meta_dockerswarm_task_port_publish_mode": ep.PublishMode, } for k, v := range commonLabels { diff --git a/lib/promscrape/discovery/dockerswarm/tasks_test.go b/lib/promscrape/discovery/dockerswarm/tasks_test.go index 783122939..4a1d1ed2f 100644 --- a/lib/promscrape/discovery/dockerswarm/tasks_test.go +++ b/lib/promscrape/discovery/dockerswarm/tasks_test.go @@ -167,7 +167,7 @@ func Test_addTasksLabels(t *testing.T) { }, want: [][]prompbmarshal.Label{ discoveryutils.GetSortedLabels(map[string]string{ - "__address__": "172.31.40.97:9100", + "__address__": "172.31.40.97:6379", "__meta_dockerswarm_node_address": "172.31.40.97", "__meta_dockerswarm_node_availability": "active", "__meta_dockerswarm_node_engine_version": "19.03.11", @@ -295,9 +295,10 @@ func Test_addTasksLabels(t *testing.T) { }{ Ports: []portConfig{ { - Protocol: "tcp", - Name: "redis", - PublishMode: "ingress", + Protocol: "tcp", + Name: "redis", + PublishMode: "ingress", + PublishedPort: 6379, }, }, VirtualIPs: []struct { NetworkID string @@ -315,8 +316,7 @@ func Test_addTasksLabels(t *testing.T) { }, want: [][]prompbmarshal.Label{ discoveryutils.GetSortedLabels(map[string]string{ - "__address": "10.10.15.15:0", - "__address__": "172.31.40.97:9100", + "__address__": "10.10.15.15:6379", "__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1", "__meta_dockerswarm_network_ingress": "true", "__meta_dockerswarm_network_internal": "false",