From 77e25cf2e5ab9aa2e794344c35e8aba56056ceec Mon Sep 17 00:00:00 2001 From: Joey Freeland Date: Mon, 21 Jun 2021 20:40:50 -0700 Subject: [PATCH 1/3] feat: gce metadata for additional interfaces Signed-off-by: Joey Freeland --- discovery/gce/gce.go | 9 +++++++++ docs/configuration/configuration.md | 1 + 2 files changed, 10 insertions(+) diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index 53ee9943d..bae6c6248 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -178,6 +178,15 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { addr := fmt.Sprintf("%s:%d", priIface.NetworkIP, d.port) labels[model.AddressLabel] = model.LabelValue(addr) + // Append additional interface private IP address metadata if multiple interfaces exist. + if len(inst.NetworkInterfaces) > 1 { + gceLabelEthAddressPrefix := gceLabel + "private_ip_eth" + for idx, iface := range inst.NetworkInterfaces { + gceLabelEthAddressPrivate := model.LabelName(fmt.Sprintf("%s%d", gceLabelEthAddressPrefix, idx)) + labels[gceLabelEthAddressPrivate] = model.LabelValue(iface.NetworkIP) + } + } + // Tags in GCE are usually only used for networking rules. if inst.Tags != nil && len(inst.Tags.Items) > 0 { // We surround the separated list with the separator as well. This way regular expressions diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 939d66e8f..cce6ff1ab 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1131,6 +1131,7 @@ The following meta labels are available on targets during [relabeling](#relabel_ * `__meta_gce_metadata_`: each metadata item of the instance * `__meta_gce_network`: the network URL of the instance * `__meta_gce_private_ip`: the private IP address of the instance +* `__meta_gce_private_ip_eth`: if more than one interface exists * `__meta_gce_project`: the GCP project in which the instance is running * `__meta_gce_public_ip`: the public IP address of the instance, if present * `__meta_gce_subnetwork`: the subnetwork URL of the instance From 8017dd724279fc7e00fb4c632fdf5235c19aaf86 Mon Sep 17 00:00:00 2001 From: Joey Freeland Date: Sun, 27 Jun 2021 18:03:10 -0700 Subject: [PATCH 2/3] chore: always append interface ipv4 with api interface name Signed-off-by: Joey Freeland --- discovery/gce/gce.go | 11 ++++------- docs/configuration/configuration.md | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index bae6c6248..1585f25c3 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -178,13 +178,10 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { addr := fmt.Sprintf("%s:%d", priIface.NetworkIP, d.port) labels[model.AddressLabel] = model.LabelValue(addr) - // Append additional interface private IP address metadata if multiple interfaces exist. - if len(inst.NetworkInterfaces) > 1 { - gceLabelEthAddressPrefix := gceLabel + "private_ip_eth" - for idx, iface := range inst.NetworkInterfaces { - gceLabelEthAddressPrivate := model.LabelName(fmt.Sprintf("%s%d", gceLabelEthAddressPrefix, idx)) - labels[gceLabelEthAddressPrivate] = model.LabelValue(iface.NetworkIP) - } + // Append named interface metadata for all interfaces + for _, iface := range inst.NetworkInterfaces { + gceLabelNetAddress := model.LabelName(fmt.Sprintf("%sinterface_ipv4_%s", gceLabel, iface.Name)) + labels[gceLabelNetAddress] = model.LabelValue(iface.NetworkIP) } // Tags in GCE are usually only used for networking rules. diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index cce6ff1ab..134c150f6 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1131,7 +1131,7 @@ The following meta labels are available on targets during [relabeling](#relabel_ * `__meta_gce_metadata_`: each metadata item of the instance * `__meta_gce_network`: the network URL of the instance * `__meta_gce_private_ip`: the private IP address of the instance -* `__meta_gce_private_ip_eth`: if more than one interface exists +* `__meta_gce_interface_ipv4_`: IPv4 address of each named interface * `__meta_gce_project`: the GCP project in which the instance is running * `__meta_gce_public_ip`: the public IP address of the instance, if present * `__meta_gce_subnetwork`: the subnetwork URL of the instance From 5d0a12855ba40712b473133ce37df5d88f62ca58 Mon Sep 17 00:00:00 2001 From: Joey Freeland <30938344+jfreeland@users.noreply.github.com> Date: Tue, 6 Jul 2021 07:53:23 -0400 Subject: [PATCH 3/3] Update discovery/gce/gce.go Co-authored-by: Julien Pivotto Signed-off-by: Joey Freeland --- discovery/gce/gce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index 1585f25c3..e17c60f71 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -180,7 +180,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { // Append named interface metadata for all interfaces for _, iface := range inst.NetworkInterfaces { - gceLabelNetAddress := model.LabelName(fmt.Sprintf("%sinterface_ipv4_%s", gceLabel, iface.Name)) + gceLabelNetAddress := model.LabelName(fmt.Sprintf("%sinterface_ipv4_%s", gceLabel, strutil.SanitizeLabelName(iface.Name))) labels[gceLabelNetAddress] = model.LabelValue(iface.NetworkIP) }