From 77bb9e16561026b265aae2335e10ce51eaa4c21a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 3 Aug 2021 15:47:25 +0300 Subject: [PATCH] lib/promscrape/discovery/gce: add __meta_gce_interface_ipv4_ labels as in Prometheus 2.29 See https://github.com/prometheus/prometheus/pull/8978 --- docs/CHANGELOG.md | 3 ++- lib/promscrape/discovery/gce/instance.go | 5 +++++ lib/promscrape/discovery/gce/instance_test.go | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c2d858f453..200992b7a2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,7 +7,8 @@ sort: 15 ## tip * FEATURE: add `present_over_time(m[d])` function, which returns 1 if `m` has a least a single sample over the previous duration `d`. This function has been added also to [Prometheus 2.29](https://github.com/prometheus/prometheus/releases/tag/v2.29.0-rc.0). -* FEATURE: vmagent: add `__meta_ec2_availability_zone_id` label, which has been introduced in [Prometheus 2.29](https://github.com/prometheus/prometheus/releases/tag/v2.29.0-rc.0). +* FEATURE: vmagent: add `__meta_ec2_availability_zone_id` label to discovered Amazon EC2 targets. This label is available in Prometheus [starting from v2.29](https://github.com/prometheus/prometheus/releases/tag/v2.29.0-rc.0). +* FAETURE: vmagent: add `__meta_gce_interface_ipv4_` labels to discovered GCE targets. These labels are available in Prometheus [starting from v2.29](https://github.com/prometheus/prometheus/releases/tag/v2.29.0-rc.0). * FEATURE: add `-search.maxSamplesPerSeries` command-line flag for limiting the number of raw samples a single query can process per each time series. This option can protect from out of memory errors when a query processes tens of millions of raw samples per series. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1067). * FEATURE: add `-search.maxSamplesPerQuery` command-line flag for limiting the number of raw samples a single query can process across all the time series. This option can protect from heavy queries, which select too big number of raw samples. Thanks to @jiangxinlingdu for [the initial pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1478). * FEATURE: improve performance for queries that process big number of time series and/or samples on systems with big number of CPU cores. diff --git a/lib/promscrape/discovery/gce/instance.go b/lib/promscrape/discovery/gce/instance.go index 345f7189c8..65ad7bdd70 100644 --- a/lib/promscrape/discovery/gce/instance.go +++ b/lib/promscrape/discovery/gce/instance.go @@ -93,6 +93,7 @@ type Instance struct { // NetworkInterface is network interface from https://cloud.google.com/compute/docs/reference/rest/v1/instances/list type NetworkInterface struct { + Name string Network string Subnetwork string NetworkIP string @@ -148,6 +149,10 @@ func (inst *Instance) appendTargetLabels(ms []map[string]string, project, tagSep "__meta_gce_subnetwork": iface.Subnetwork, "__meta_gce_zone": inst.Zone, } + for _, iface := range inst.NetworkInterfaces { + ifaceName := discoveryutils.SanitizeLabelName(iface.Name) + m["__meta_gce_interface_ipv4_"+ifaceName] = iface.NetworkIP + } if len(inst.Tags.Items) > 0 { // We surround the separated list with the separator as well. This way regular expressions // in relabeling rules don't have to consider tag positions. diff --git a/lib/promscrape/discovery/gce/instance_test.go b/lib/promscrape/discovery/gce/instance_test.go index a5426d81ef..0364ae6ef2 100644 --- a/lib/promscrape/discovery/gce/instance_test.go +++ b/lib/promscrape/discovery/gce/instance_test.go @@ -158,6 +158,7 @@ func TestParseInstanceListSuccess(t *testing.T) { "__meta_gce_instance_id": "7897352091592122", "__meta_gce_instance_name": "play-1m-1-vmagent", "__meta_gce_instance_status": "RUNNING", + "__meta_gce_interface_ipv4_nic0": "10.11.2.7", "__meta_gce_label_cluster_num": "1", "__meta_gce_label_cluster_retention": "1m", "__meta_gce_label_env": "play",