diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fab0da64cf..170bc22b22 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,7 @@ sort: 15 * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): fix a few edge cases and improve migration speed for OpenTSDB importer. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2019). * BUGFIX: fix possible data race when searching for time series matching `{key=~"value|"}` filter over time range covering multipe days. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2032). Thanks to @waldoweng for the provided fix. * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): do not send staleness markers on graceful shutdown. This follows Prometheus behavior. See [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2013#issuecomment-1006994079). +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly set `__address__` label in `dockerswarm_sd_config`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2038). Thanks to @ashtuchkin for the fix. ## [v1.71.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.71.0) diff --git a/lib/promscrape/discovery/dockerswarm/tasks.go b/lib/promscrape/discovery/dockerswarm/tasks.go index 416fc6f385..922a7883e0 100644 --- a/lib/promscrape/discovery/dockerswarm/tasks.go +++ b/lib/promscrape/discovery/dockerswarm/tasks.go @@ -94,22 +94,21 @@ 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" { continue } - m := map[string]string{ - "__address__": discoveryutils.JoinHostPort(commonLabels["__meta_dockerswarm_node_address"], port.PublishedPort), - "__meta_dockerswarm_task_port_publish_mode": port.PublishMode, - } + m := make(map[string]string, len(commonLabels)+2) for k, v := range commonLabels { m[k] = v } + m["__address__"] = discoveryutils.JoinHostPort(commonLabels["__meta_dockerswarm_node_address"], port.PublishedPort) + m["__meta_dockerswarm_task_port_publish_mode"] = port.PublishMode ms = append(ms, m) } for _, na := range task.NetworksAttachments { + networkLabels := networksLabels[na.Network.ID] for _, address := range na.Addresses { ip, _, err := net.ParseCIDR(address) if err != nil { @@ -121,29 +120,27 @@ func addTasksLabels(tasks []task, nodesLabels, servicesLabels []map[string]strin if ep.Protocol != "tcp" { continue } - m := map[string]string{ - "__address__": discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort), - "__meta_dockerswarm_task_port_publish_mode": ep.PublishMode, - } + m := make(map[string]string, len(commonLabels)+len(networkLabels)+2) for k, v := range commonLabels { m[k] = v } - for k, v := range networksLabels[na.Network.ID] { + for k, v := range networkLabels { m[k] = v } + m["__address__"] = discoveryutils.JoinHostPort(ip.String(), ep.PublishedPort) + m["__meta_dockerswarm_task_port_publish_mode"] = ep.PublishMode ms = append(ms, m) added = true } if !added { - m := map[string]string{ - "__address__": discoveryutils.JoinHostPort(ip.String(), port), - } + m := make(map[string]string, len(commonLabels)+len(networkLabels)+1) for k, v := range commonLabels { m[k] = v } - for k, v := range networksLabels[na.Network.ID] { + for k, v := range networkLabels { m[k] = v } + m["__address__"] = discoveryutils.JoinHostPort(ip.String(), port) ms = append(ms, m) } }