in pkg/discovery/discovery.go [201:235]
func (d *discovery) processServiceInstances(tgSourceSpec targetSourceSpec, dio *servicediscovery.DiscoverInstancesOutput) *targetgroup.Group {
d.newSources[tgSourceSpec] = true
tg := &targetgroup.Group{
Source: tgSourceSpec.String(),
Labels: model.LabelSet{
lblNamespaceName: model.LabelValue(tgSourceSpec.namespace),
lblServiceName: model.LabelValue(tgSourceSpec.service),
},
Targets: make([]model.LabelSet, 0, len(dio.Instances)),
}
for _, inst := range dio.Instances {
instanceID := aws.StringValue(inst.InstanceId)
ipv4 := aws.StringValue(inst.Attributes["AWS_INSTANCE_IPV4"])
ipv6 := aws.StringValue(inst.Attributes["AWS_INSTANCE_IPV6"])
var ipAddr string
if ipv4 != "" {
ipAddr = ipv4
} else if ipv6 != "" {
ipAddr = ipv6
} else {
level.Info(d.logger).Log("msg", "skipping instance with no ip", "instance", instanceID)
continue
}
port := aws.StringValue(inst.Attributes["AWS_INSTANCE_PORT"])
if port != "" {
ipAddr = net.JoinHostPort(ipAddr, port)
}
labels := model.LabelSet{
model.AddressLabel: model.LabelValue(ipAddr),
}
tg.Targets = append(tg.Targets, labels)
}
return tg
}