Fix for #2038: Make correct __address__ value for dockerswarm promscrape (#2041)

This commit is contained in:
Alexander Shtuchkin 2022-01-11 01:59:06 -05:00 committed by Aliaksandr Valialkin
parent 21e5e90d75
commit 45a92e6ce1
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 8 additions and 7 deletions

View File

@ -94,6 +94,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []map[string]strin
} }
addLabels(commonLabels, servicesLabels, "__meta_dockerswarm_service_id", task.ServiceID) addLabels(commonLabels, servicesLabels, "__meta_dockerswarm_service_id", task.ServiceID)
addLabels(commonLabels, nodesLabels, "__meta_dockerswarm_node_id", task.NodeID) addLabels(commonLabels, nodesLabels, "__meta_dockerswarm_node_id", task.NodeID)
delete(commonLabels, "__address__")
for _, port := range task.Status.PortStatus.Ports { for _, port := range task.Status.PortStatus.Ports {
if port.Protocol != "tcp" { if port.Protocol != "tcp" {
@ -121,7 +122,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []map[string]strin
continue continue
} }
m := map[string]string{ 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, "__meta_dockerswarm_task_port_publish_mode": ep.PublishMode,
} }
for k, v := range commonLabels { for k, v := range commonLabels {

View File

@ -167,7 +167,7 @@ func Test_addTasksLabels(t *testing.T) {
}, },
want: [][]prompbmarshal.Label{ want: [][]prompbmarshal.Label{
discoveryutils.GetSortedLabels(map[string]string{ 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_address": "172.31.40.97",
"__meta_dockerswarm_node_availability": "active", "__meta_dockerswarm_node_availability": "active",
"__meta_dockerswarm_node_engine_version": "19.03.11", "__meta_dockerswarm_node_engine_version": "19.03.11",
@ -298,6 +298,7 @@ func Test_addTasksLabels(t *testing.T) {
Protocol: "tcp", Protocol: "tcp",
Name: "redis", Name: "redis",
PublishMode: "ingress", PublishMode: "ingress",
PublishedPort: 6379,
}, },
}, VirtualIPs: []struct { }, VirtualIPs: []struct {
NetworkID string NetworkID string
@ -315,8 +316,7 @@ func Test_addTasksLabels(t *testing.T) {
}, },
want: [][]prompbmarshal.Label{ want: [][]prompbmarshal.Label{
discoveryutils.GetSortedLabels(map[string]string{ discoveryutils.GetSortedLabels(map[string]string{
"__address": "10.10.15.15:0", "__address__": "10.10.15.15:6379",
"__address__": "172.31.40.97:9100",
"__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1", "__meta_dockerswarm_network_id": "qs0hog6ldlei9ct11pr3c77v1",
"__meta_dockerswarm_network_ingress": "true", "__meta_dockerswarm_network_ingress": "true",
"__meta_dockerswarm_network_internal": "false", "__meta_dockerswarm_network_internal": "false",