Skip to content

Commit

Permalink
more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-breen committed Oct 16, 2024
1 parent 2526215 commit 5e24dee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions internal/collector/otel_collector_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/collector/otel_collector_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5e24dee

Please sign in to comment.