From df92a00838b028313044839921c02352872dbeb3 Mon Sep 17 00:00:00 2001 From: Alex Gaganov <31386536+alexgaganov-fiverr@users.noreply.github.com> Date: Tue, 3 Mar 2020 10:03:16 +0200 Subject: [PATCH] Expose EC2 instance lifecycle as label (#6914) Signed-off-by: Alex Gaganov --- discovery/ec2/ec2.go | 37 ++++++++++++++++------------- docs/configuration/configuration.md | 1 + 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/discovery/ec2/ec2.go b/discovery/ec2/ec2.go index e6c4ff87b88..d4b27b15dd0 100644 --- a/discovery/ec2/ec2.go +++ b/discovery/ec2/ec2.go @@ -37,22 +37,23 @@ import ( ) const ( - ec2Label = model.MetaLabelPrefix + "ec2_" - ec2LabelAZ = ec2Label + "availability_zone" - ec2LabelInstanceID = ec2Label + "instance_id" - ec2LabelInstanceState = ec2Label + "instance_state" - ec2LabelInstanceType = ec2Label + "instance_type" - ec2LabelOwnerID = ec2Label + "owner_id" - ec2LabelPlatform = ec2Label + "platform" - ec2LabelPublicDNS = ec2Label + "public_dns_name" - ec2LabelPublicIP = ec2Label + "public_ip" - ec2LabelPrivateDNS = ec2Label + "private_dns_name" - ec2LabelPrivateIP = ec2Label + "private_ip" - ec2LabelPrimarySubnetID = ec2Label + "primary_subnet_id" - ec2LabelSubnetID = ec2Label + "subnet_id" - ec2LabelTag = ec2Label + "tag_" - ec2LabelVPCID = ec2Label + "vpc_id" - subnetSeparator = "," + ec2Label = model.MetaLabelPrefix + "ec2_" + ec2LabelAZ = ec2Label + "availability_zone" + ec2LabelInstanceID = ec2Label + "instance_id" + ec2LabelInstanceState = ec2Label + "instance_state" + ec2LabelInstanceType = ec2Label + "instance_type" + ec2LabelInstanceLifecycle = ec2Label + "instance_lifecycle" + ec2LabelOwnerID = ec2Label + "owner_id" + ec2LabelPlatform = ec2Label + "platform" + ec2LabelPublicDNS = ec2Label + "public_dns_name" + ec2LabelPublicIP = ec2Label + "public_ip" + ec2LabelPrivateDNS = ec2Label + "private_dns_name" + ec2LabelPrivateIP = ec2Label + "private_ip" + ec2LabelPrimarySubnetID = ec2Label + "primary_subnet_id" + ec2LabelSubnetID = ec2Label + "subnet_id" + ec2LabelTag = ec2Label + "tag_" + ec2LabelVPCID = ec2Label + "vpc_id" + subnetSeparator = "," ) // DefaultSDConfig is the default EC2 SD configuration. @@ -214,6 +215,10 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { labels[ec2LabelInstanceState] = model.LabelValue(*inst.State.Name) labels[ec2LabelInstanceType] = model.LabelValue(*inst.InstanceType) + if inst.InstanceLifecycle != nil { + labels[ec2LabelInstanceLifecycle] = model.LabelValue(*inst.InstanceLifecycle) + } + if inst.VpcId != nil { labels[ec2LabelVPCID] = model.LabelValue(*inst.VpcId) labels[ec2LabelPrimarySubnetID] = model.LabelValue(*inst.SubnetId) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 811ed656327..7be946c0f63 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -428,6 +428,7 @@ The following meta labels are available on targets during [relabeling](#relabel_ * `__meta_ec2_availability_zone`: the availability zone in which the instance is running * `__meta_ec2_instance_id`: the EC2 instance ID +* `__meta_ec2_instance_lifecycle`: the lifecycle of the EC2 instance, set only for 'spot' or 'scheduled' instances, absent otherwise * `__meta_ec2_instance_state`: the state of the EC2 instance * `__meta_ec2_instance_type`: the type of the EC2 instance * `__meta_ec2_owner_id`: the ID of the AWS account that owns the EC2 instance