From 7e9549b3986585aede0904391f81cd1e084695c2 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Fri, 10 Aug 2018 11:11:03 -0400 Subject: [PATCH 1/3] Added __meta_gce_instance_id discovery label Populated from instance.ID. I will follow up with a change to the documentation. Signed-off-by: Javier Kohen --- discovery/gce/gce.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index b92336d0d2..32a5b52b54 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -40,6 +40,7 @@ const ( gceLabelSubnetwork = gceLabel + "subnetwork" gceLabelPublicIP = gceLabel + "public_ip" gceLabelPrivateIP = gceLabel + "private_ip" + gceLabelInstanceID = gceLabel + "instance_id" gceLabelInstanceName = gceLabel + "instance_name" gceLabelInstanceStatus = gceLabel + "instance_status" gceLabelTags = gceLabel + "tags" @@ -209,6 +210,7 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) { labels := model.LabelSet{ gceLabelProject: model.LabelValue(d.project), gceLabelZone: model.LabelValue(inst.Zone), + gceLabelInstanceID: model.LabelValue(inst.Id), gceLabelInstanceName: model.LabelValue(inst.Name), gceLabelInstanceStatus: model.LabelValue(inst.Status), gceLabelMachineType: model.LabelValue(inst.MachineType), From 2d4bcb3ee1f348418dc6b531c21eb3e429d805f5 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Fri, 10 Aug 2018 11:59:22 -0400 Subject: [PATCH 2/3] Document the new __meta_gce_instance_id discovery label. Signed-off-by: Javier Kohen --- docs/configuration/configuration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 8fc479963b..9c97002ace 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -589,6 +589,7 @@ address with relabeling. The following meta labels are available on targets during [relabeling](#relabel_config): +* `__meta_gce_instance_id`: the numeric id of the instance * `__meta_gce_instance_name`: the name of the instance * `__meta_gce_label_`: each GCE label of the instance * `__meta_gce_machine_type`: full or partial URL of the machine type of the instance From 403ac08ece0d0f1b1dfbb1892002416b137d7840 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Fri, 10 Aug 2018 16:21:46 -0400 Subject: [PATCH 3/3] Expose __meta_gce_instance_id as an integer (instead of raw bytes). Signed-off-by: Javier Kohen --- discovery/gce/gce.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index 32a5b52b54..4a9cae8916 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -17,6 +17,7 @@ import ( "context" "fmt" "net/http" + "strconv" "strings" "time" @@ -210,7 +211,7 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) { labels := model.LabelSet{ gceLabelProject: model.LabelValue(d.project), gceLabelZone: model.LabelValue(inst.Zone), - gceLabelInstanceID: model.LabelValue(inst.Id), + gceLabelInstanceID: model.LabelValue(strconv.FormatUint(inst.Id, 10)), gceLabelInstanceName: model.LabelValue(inst.Name), gceLabelInstanceStatus: model.LabelValue(inst.Status), gceLabelMachineType: model.LabelValue(inst.MachineType),