From 6206a8c0fa91bcf53cf4e7d91b7e176754f9cbae Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Thu, 28 May 2026 09:16:21 -0300 Subject: [PATCH] fix: add missing labels for target health Signed-off-by: Gustavo Carvalho --- collector_test.go | 10 ++++++++++ input.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/collector_test.go b/collector_test.go index eb99c5b..3331ca7 100644 --- a/collector_test.go +++ b/collector_test.go @@ -350,6 +350,16 @@ func TestCollectorCollectsAllRecordTypesAndAccumulatesErrors(t *testing.T) { if th.Input.Config["target_id"] != "i-1234567890abcdef0" || th.Input.Config["target_health_state"] != "healthy" { t.Fatalf("target health config = %#v", th.Input.Config) } + if th.Labels["target_id"] != "i-1234567890abcdef0" { + t.Fatalf("target health labels missing target_id: %#v", th.Labels) + } + for _, typ := range []string{resourceTypeLoadBalancer, resourceTypeListener, resourceTypeTargetGroup} { + for _, record := range byType[typ] { + if _, ok := record.Labels["target_id"]; ok { + t.Fatalf("%s labels should not contain target_id: %#v", typ, record.Labels) + } + } + } var sawHealthError bool for _, record := range result.Records { diff --git a/input.go b/input.go index 3f0405c..5b70cb6 100644 --- a/input.go +++ b/input.go @@ -169,6 +169,10 @@ func newTargetHealthRecord(account AccountContext, region string, targetGroupARN "target_health_state": state, } record := newResourceRecord(account, region, ResourceIdentity{ID: id, ARN: targetGroupARN, Type: resourceTypeTargetHealth}, config, nil, nil, errors, policyInputs, collectedAt, nil, targetHealth, "aws-elbv2-target-health", fmt.Sprintf("aws-elbv2-target-health/%s/%s/%s", account.AccountID, region, id), "AWS ELBv2 Target Health ["+id+"]") + // target_id is exposed as a label so downstream evidence-search consumers can + // disambiguate targets sharing a target-group ARN; the resource_arn/resource_id + // labels alone are not sufficient for exact-match filtering. + record.Labels["target_id"] = targetID return &record }