From 5e24deef904507d3d2ed664d509c61bd4f914473 Mon Sep 17 00:00:00 2001 From: Sean Breen Date: Wed, 16 Oct 2024 15:20:45 +0100 Subject: [PATCH] more feedback --- internal/collector/otel_collector_plugin.go | 28 ++++++++----------- .../collector/otel_collector_plugin_test.go | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/internal/collector/otel_collector_plugin.go b/internal/collector/otel_collector_plugin.go index 8293941ded..b7487731d6 100644 --- a/internal/collector/otel_collector_plugin.go +++ b/internal/collector/otel_collector_plugin.go @@ -248,7 +248,7 @@ func (oc *Collector) handleResourceUpdate(ctx context.Context, msg *bus.Message) var reloadCollector bool if oc.config.Collector.Processors.Attribute != nil { if resourceUpdateContext.GetResourceId() != "" { - reloadCollector = oc.updateResourceAttributes( + reloadCollector = oc.updateAttributeActions( []config.Action{ { Key: "resource.id", @@ -395,30 +395,24 @@ func (oc *Collector) updateExistingNginxOSSReceiver( } // nolint: revive -func (oc *Collector) updateResourceAttributes( +func (oc *Collector) updateAttributeActions( actionsToAdd []config.Action, ) (reloadCollector bool) { reloadCollector = false if oc.config.Collector.Processors.Attribute.Actions != nil { + OUTER: for _, toAdd := range actionsToAdd { - duplicateKey := false - for _, a := range oc.config.Collector.Processors.Attribute.Actions { - // check for key name collision - if a.Key == toAdd.Key { - duplicateKey = true - reloadCollector = true - - break + for _, action := range oc.config.Collector.Processors.Attribute.Actions { + if action.Key == toAdd.Key { + continue OUTER } } - if !duplicateKey { - oc.config.Collector.Processors.Attribute.Actions = append( - oc.config.Collector.Processors.Attribute.Actions, - toAdd, - ) - reloadCollector = true - } + oc.config.Collector.Processors.Attribute.Actions = append( + oc.config.Collector.Processors.Attribute.Actions, + toAdd, + ) + reloadCollector = true } } diff --git a/internal/collector/otel_collector_plugin_test.go b/internal/collector/otel_collector_plugin_test.go index 4d9d33a91c..9c82a3e28b 100644 --- a/internal/collector/otel_collector_plugin_test.go +++ b/internal/collector/otel_collector_plugin_test.go @@ -524,7 +524,7 @@ func TestCollector_updateResourceAttributes(t *testing.T) { // set up Actions conf.Collector.Processors.Attribute = &config.Attribute{Actions: test.setupActions} - reloadRequired := collector.updateResourceAttributes(test.actions) + reloadRequired := collector.updateAttributeActions(test.actions) assert.Equal(tt, test.expectedAttribs, conf.Collector.Processors.Attribute.Actions)