Skip to content

Commit

Permalink
do not recalculate global entity id as string on each call (#29934)
Browse files Browse the repository at this point in the history
  • Loading branch information
adel121 authored Oct 8, 2024
1 parent 4c69af7 commit 1761383
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions comp/core/tagger/common/entity_id_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ func BuildTaggerEntityID(entityID workloadmeta.EntityID) types.EntityID {
}

var globalEntityID = types.NewEntityID("internal", "global-entity-id")
var globalEntityIDString = globalEntityID.String()

// GetGlobalEntityID returns the entity ID that holds global tags
func GetGlobalEntityID() types.EntityID {
return globalEntityID
}

// GetGlobalEntityIDString returns, in a plain string format, the entity ID that holds global tags
func GetGlobalEntityIDString() string {
return globalEntityIDString
}
4 changes: 2 additions & 2 deletions comp/core/tagger/taggerimpl/local/fake_tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (f *FakeTagger) SetTags(entityID string, source string, low, orch, high, st

// SetGlobalTags allows to set tags in store for the global entity
func (f *FakeTagger) SetGlobalTags(low, orch, high, std []string) {
f.SetTags(common.GetGlobalEntityID().String(), "static", low, orch, high, std)
f.SetTags(common.GetGlobalEntityIDString(), "static", low, orch, high, std)
}

// SetTagsFromInfo allows to set tags from list of TagInfo
Expand Down Expand Up @@ -112,7 +112,7 @@ func (f *FakeTagger) Tag(entityID string, cardinality types.TagCardinality) ([]s

// GlobalTags fake implementation
func (f *FakeTagger) GlobalTags(cardinality types.TagCardinality) ([]string, error) {
return f.Tag(common.GetGlobalEntityID().String(), cardinality)
return f.Tag(common.GetGlobalEntityIDString(), cardinality)
}

// AccumulateTagsFor fake implementation
Expand Down
8 changes: 4 additions & 4 deletions comp/core/tagger/taggerimpl/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,30 +338,30 @@ func (t *TaggerClient) AgentTags(cardinality types.TagCardinality) ([]string, er
func (t *TaggerClient) GlobalTags(cardinality types.TagCardinality) ([]string, error) {
t.mux.RLock()
if t.captureTagger != nil {
tags, err := t.captureTagger.Tag(taggercommon.GetGlobalEntityID().String(), cardinality)
tags, err := t.captureTagger.Tag(taggercommon.GetGlobalEntityIDString(), cardinality)
if err == nil && len(tags) > 0 {
t.mux.RUnlock()
return tags, nil
}
}
t.mux.RUnlock()
return t.defaultTagger.Tag(taggercommon.GetGlobalEntityID().String(), cardinality)
return t.defaultTagger.Tag(taggercommon.GetGlobalEntityIDString(), cardinality)
}

// globalTagBuilder queries global tags that should apply to all data coming
// from the agent and appends them to the TagsAccumulator
func (t *TaggerClient) globalTagBuilder(cardinality types.TagCardinality, tb tagset.TagsAccumulator) error {
t.mux.RLock()
if t.captureTagger != nil {
err := t.captureTagger.AccumulateTagsFor(taggercommon.GetGlobalEntityID().String(), cardinality, tb)
err := t.captureTagger.AccumulateTagsFor(taggercommon.GetGlobalEntityIDString(), cardinality, tb)

if err == nil {
t.mux.RUnlock()
return nil
}
}
t.mux.RUnlock()
return t.defaultTagger.AccumulateTagsFor(taggercommon.GetGlobalEntityID().String(), cardinality, tb)
return t.defaultTagger.AccumulateTagsFor(taggercommon.GetGlobalEntityIDString(), cardinality, tb)
}

// List the content of the defaulTagger
Expand Down

0 comments on commit 1761383

Please sign in to comment.