feat: gce metadata for additional interfaces

Signed-off-by: Joey Freeland <joey@free.land>
This commit is contained in:
Joey Freeland 2021-06-21 20:40:50 -07:00
parent 4a5aef0495
commit 77e25cf2e5
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -1131,6 +1131,7 @@ The following meta labels are available on targets during [relabeling](#relabel_
* `__meta_gce_metadata_<name>`: 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<int>`: 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