lib/promscrape/discovery: add a comment explaining why duplicates are removed from the generated target labels

This commit is contained in:
Aliaksandr Valialkin 2023-02-22 17:01:01 -08:00
parent 55708fa474
commit b7d13c3478
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
6 changed files with 12 additions and 0 deletions

View file

@ -81,6 +81,7 @@ func addContainersLabels(containers []container, networkLabels map[string]*promu
m.Add("__meta_docker_port_public_ip", p.IP)
}
addCommonLabels(m, c, networkLabels[n.NetworkID])
// Remove possible duplicate labels, which can appear after addCommonLabels() call
m.RemoveDuplicates()
ms = append(ms, m)
added = true
@ -95,6 +96,7 @@ func addContainersLabels(containers []container, networkLabels map[string]*promu
m.Add("__address__", addr)
m.Add("__meta_docker_network_ip", n.IPAddress)
addCommonLabels(m, c, networkLabels[n.NetworkID])
// Remove possible duplicate labels, which can appear after addCommonLabels() call
m.RemoveDuplicates()
ms = append(ms, m)
}

View file

@ -123,6 +123,7 @@ func addServicesLabels(services []service, networksLabels map[string]*promutils.
m.Add("__meta_dockerswarm_service_endpoint_port_publish_mode", ep.PublishMode)
m.AddFrom(commonLabels)
m.AddFrom(networksLabels[vip.NetworkID])
// Remove possible duplicate labels, which can appear after AddFrom() calls
m.RemoveDuplicates()
added = true
ms = append(ms, m)
@ -132,6 +133,7 @@ func addServicesLabels(services []service, networksLabels map[string]*promutils.
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), port))
m.AddFrom(commonLabels)
m.AddFrom(networksLabels[vip.NetworkID])
// Remove possible duplicate labels, which can appear after AddFrom() calls
m.RemoveDuplicates()
ms = append(ms, m)
}

View file

@ -111,6 +111,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
m.AddFrom(commonLabels)
m.Add("__address__", discoveryutils.JoinHostPort(commonLabels.Get("__meta_dockerswarm_node_address"), port.PublishedPort))
m.Add("__meta_dockerswarm_task_port_publish_mode", port.PublishMode)
// Remove possible duplicate labels, which can appear after AddFrom() call
m.RemoveDuplicates()
ms = append(ms, m)
}
@ -132,6 +133,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
m.AddFrom(networkLabels)
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort))
m.Add("__meta_dockerswarm_task_port_publish_mode", ep.PublishMode)
// Remove possible duplicate labels, which can appear after AddFrom() calls
m.RemoveDuplicates()
ms = append(ms, m)
added = true
@ -141,6 +143,7 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []*promutils.Label
m.AddFrom(commonLabels)
m.AddFrom(networkLabels)
m.Add("__address__", discoveryutils.JoinHostPort(ip.String(), port))
// Remove possible duplicate labels, which can appear after AddFrom() calls
m.RemoveDuplicates()
ms = append(ms, m)
}

View file

@ -47,6 +47,7 @@ func addHTTPTargetLabels(src []httpGroupTarget, sourceURL string) []*promutils.L
m.AddFrom(labels)
m.Add("__address__", target)
m.Add("__meta_url", sourceURL)
// Remove possible duplicate labels, which can appear after AddFrom() call
m.RemoveDuplicates()
ms = append(ms, m)
}

View file

@ -137,6 +137,7 @@ func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []*promutils.Labels {
if svc != nil {
svc.appendCommonLabels(m)
}
// Remove possible duplicate labels, which can appear after appendCommonLabels() call
m.RemoveDuplicates()
ms = append(ms, m)
}
@ -155,6 +156,7 @@ func appendEndpointLabelsForAddresses(ms []*promutils.Labels, gw *groupWatcher,
}
}
m := getEndpointLabelsForAddressAndPort(gw, podPortsSeen, eps, ea, epp, p, svc, ready)
// Remove possible duplicate labels, which can appear inside getEndpointLabelsForAddressAndPort()
m.RemoveDuplicates()
ms = append(ms, m)
}

View file

@ -56,6 +56,7 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutils.Labels
for _, epp := range eps.Ports {
for _, addr := range ess.Addresses {
m := getEndpointSliceLabelsForAddressAndPort(gw, podPortsSeen, addr, eps, ess, epp, p, svc)
// Remove possible duplicate labels, which can appear after getEndpointSliceLabelsForAddressAndPort() call
m.RemoveDuplicates()
ms = append(ms, m)
}
@ -86,6 +87,7 @@ func (eps *EndpointSlice) getTargetLabels(gw *groupWatcher) []*promutils.Labels
if svc != nil {
svc.appendCommonLabels(m)
}
// Remove possible duplicate labels, which can appear after appendCommonLabels() calls
m.RemoveDuplicates()
ms = append(ms, m)
}