From 17613833e4144be2577c117e756f73b0100e9480 Mon Sep 17 00:00:00 2001 From: Adel Haj Hassan <41540817+adel121@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:25:12 +0200 Subject: [PATCH] do not recalculate global entity id as string on each call (#29934) --- comp/core/tagger/common/entity_id_builder.go | 6 ++++++ comp/core/tagger/taggerimpl/local/fake_tagger.go | 4 ++-- comp/core/tagger/taggerimpl/tagger.go | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/comp/core/tagger/common/entity_id_builder.go b/comp/core/tagger/common/entity_id_builder.go index d46af748cc08b..93774664bc7bf 100644 --- a/comp/core/tagger/common/entity_id_builder.go +++ b/comp/core/tagger/common/entity_id_builder.go @@ -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 +} diff --git a/comp/core/tagger/taggerimpl/local/fake_tagger.go b/comp/core/tagger/taggerimpl/local/fake_tagger.go index 32c4ae31cb5b0..65f2e679c7890 100644 --- a/comp/core/tagger/taggerimpl/local/fake_tagger.go +++ b/comp/core/tagger/taggerimpl/local/fake_tagger.go @@ -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 @@ -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 diff --git a/comp/core/tagger/taggerimpl/tagger.go b/comp/core/tagger/taggerimpl/tagger.go index c8c0b2020c846..a0b40abca7a0c 100644 --- a/comp/core/tagger/taggerimpl/tagger.go +++ b/comp/core/tagger/taggerimpl/tagger.go @@ -338,14 +338,14 @@ 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 @@ -353,7 +353,7 @@ func (t *TaggerClient) GlobalTags(cardinality types.TagCardinality) ([]string, e 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() @@ -361,7 +361,7 @@ func (t *TaggerClient) globalTagBuilder(cardinality types.TagCardinality, tb tag } } 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