discovery/ec2: Maintain order of subnet_id label

Signed-off-by: José Martínez <xosemp@gmail.com>
pull/4415/head
José Martínez 2018-07-25 09:36:46 +02:00 committed by Brian Brazil
parent 286a8e0554
commit 5e4a33c890
1 changed files with 6 additions and 5 deletions

View File

@ -257,13 +257,14 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) {
if inst.VpcId != nil {
labels[ec2LabelVPCID] = model.LabelValue(*inst.VpcId)
// Deduplicate VPC Subnet IDs maintaining the order of the network interfaces returned by EC2.
var subnets []string
subnetsMap := make(map[string]struct{})
for _, eni := range inst.NetworkInterfaces {
subnetsMap[*eni.SubnetId] = struct{}{}
}
subnets := []string{}
for k := range subnetsMap {
subnets = append(subnets, k)
if _, ok := subnetsMap[*eni.SubnetId]; !ok {
subnetsMap[*eni.SubnetId] = struct{}{}
subnets = append(subnets, *eni.SubnetId)
}
}
labels[ec2LabelSubnetID] = model.LabelValue(
subnetSeparator +