mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 22:07:27 -08:00
discovery: ec2: expose IPv6 as label (#7086)
* discovery: ec2: expose IPv6 as label Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
This commit is contained in:
parent
5f103aaecc
commit
587fd740be
|
@ -42,21 +42,22 @@ const (
|
|||
ec2LabelAMI = ec2Label + "ami"
|
||||
ec2LabelAZ = ec2Label + "availability_zone"
|
||||
ec2LabelArch = ec2Label + "architecture"
|
||||
ec2LabelIPv6Addresses = ec2Label + "ipv6_addresses"
|
||||
ec2LabelInstanceID = ec2Label + "instance_id"
|
||||
ec2LabelInstanceLifecycle = ec2Label + "instance_lifecycle"
|
||||
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"
|
||||
ec2LabelPrimarySubnetID = ec2Label + "primary_subnet_id"
|
||||
ec2LabelPrivateDNS = ec2Label + "private_dns_name"
|
||||
ec2LabelPrivateIP = ec2Label + "private_ip"
|
||||
ec2LabelPrimarySubnetID = ec2Label + "primary_subnet_id"
|
||||
ec2LabelPublicDNS = ec2Label + "public_dns_name"
|
||||
ec2LabelPublicIP = ec2Label + "public_ip"
|
||||
ec2LabelSubnetID = ec2Label + "subnet_id"
|
||||
ec2LabelTag = ec2Label + "tag_"
|
||||
ec2LabelVPCID = ec2Label + "vpc_id"
|
||||
subnetSeparator = ","
|
||||
ec2LabelSeparator = ","
|
||||
)
|
||||
|
||||
// DefaultSDConfig is the default EC2 SD configuration.
|
||||
|
@ -243,22 +244,33 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
|||
labels[ec2LabelVPCID] = model.LabelValue(*inst.VpcId)
|
||||
labels[ec2LabelPrimarySubnetID] = model.LabelValue(*inst.SubnetId)
|
||||
|
||||
// Deduplicate VPC Subnet IDs maintaining the order of the network interfaces returned by EC2.
|
||||
var subnets []string
|
||||
var ipv6addrs []string
|
||||
subnetsMap := make(map[string]struct{})
|
||||
for _, eni := range inst.NetworkInterfaces {
|
||||
if eni.SubnetId == nil {
|
||||
continue
|
||||
}
|
||||
// Deduplicate VPC Subnet IDs maintaining the order of the subnets returned by EC2.
|
||||
if _, ok := subnetsMap[*eni.SubnetId]; !ok {
|
||||
subnetsMap[*eni.SubnetId] = struct{}{}
|
||||
subnets = append(subnets, *eni.SubnetId)
|
||||
}
|
||||
|
||||
for _, ipv6addr := range eni.Ipv6Addresses {
|
||||
ipv6addrs = append(ipv6addrs, *ipv6addr.Ipv6Address)
|
||||
}
|
||||
}
|
||||
labels[ec2LabelSubnetID] = model.LabelValue(
|
||||
subnetSeparator +
|
||||
strings.Join(subnets, subnetSeparator) +
|
||||
subnetSeparator)
|
||||
ec2LabelSeparator +
|
||||
strings.Join(subnets, ec2LabelSeparator) +
|
||||
ec2LabelSeparator)
|
||||
if len(ipv6addrs) > 0 {
|
||||
labels[ec2LabelIPv6Addresses] = model.LabelValue(
|
||||
ec2LabelSeparator +
|
||||
strings.Join(ipv6addrs, ec2LabelSeparator) +
|
||||
ec2LabelSeparator)
|
||||
}
|
||||
}
|
||||
|
||||
for _, t := range inst.Tags {
|
||||
|
|
|
@ -662,6 +662,7 @@ The following meta labels are available on targets during [relabeling](#relabel_
|
|||
* `__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_ipv6_addresses`: comma seperated list of IPv6 addresses for the all the network interfaces of the instance, if available
|
||||
* `__meta_ec2_owner_id`: the ID of the AWS account that owns the EC2 instance
|
||||
* `__meta_ec2_platform`: the Operating System platform, set to 'windows' on Windows servers, absent otherwise
|
||||
* `__meta_ec2_primary_subnet_id`: the subnet ID of the primary network interface, if available
|
||||
|
|
Loading…
Reference in a new issue