Skip to content

Commit

Permalink
switch to composite store and use composite entity id in tagger compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
adel121 committed Oct 11, 2024
1 parent 967da85 commit 692bb8a
Show file tree
Hide file tree
Showing 59 changed files with 312 additions and 2,233 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@
/pkg/util/orchestrator/ @DataDog/container-app
/pkg/util/podman/ @DataDog/container-integrations
/pkg/util/prometheus @DataDog/container-integrations
/pkg/util/tagger @DataDog/container-platform
/pkg/util/trivy/ @DataDog/container-integrations @DataDog/agent-security
/pkg/util/uuid/ @DataDog/agent-shared-components
/pkg/util/cgroups/ @DataDog/container-integrations
Expand Down
1 change: 0 additions & 1 deletion cmd/serverless/dependencies_linux_amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ github.com/DataDog/datadog-agent/pkg/util/statstracker
github.com/DataDog/datadog-agent/pkg/util/sync
github.com/DataDog/datadog-agent/pkg/util/system
github.com/DataDog/datadog-agent/pkg/util/system/socket
github.com/DataDog/datadog-agent/pkg/util/tagger
github.com/DataDog/datadog-agent/pkg/util/tmplvar
github.com/DataDog/datadog-agent/pkg/version
github.com/DataDog/datadog-api-client-go/v2
Expand Down
1 change: 0 additions & 1 deletion cmd/serverless/dependencies_linux_arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ github.com/DataDog/datadog-agent/pkg/util/statstracker
github.com/DataDog/datadog-agent/pkg/util/sync
github.com/DataDog/datadog-agent/pkg/util/system
github.com/DataDog/datadog-agent/pkg/util/system/socket
github.com/DataDog/datadog-agent/pkg/util/tagger
github.com/DataDog/datadog-agent/pkg/util/tmplvar
github.com/DataDog/datadog-agent/pkg/version
github.com/DataDog/datadog-api-client-go/v2
Expand Down
2 changes: 1 addition & 1 deletion comp/api/api/apiimpl/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (s *serverSecure) DogstatsdSetTaggerState(_ context.Context, req *pb.Tagger
}

state = append(state, taggerTypes.Entity{
ID: entityID,
ID: *entityID,
HighCardinalityTags: entity.HighCardinalityTags,
OrchestratorCardinalityTags: entity.OrchestratorCardinalityTags,
LowCardinalityTags: entity.LowCardinalityTags,
Expand Down
2 changes: 1 addition & 1 deletion comp/core/autodiscovery/listeners/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (l *ContainerListener) createContainerService(entity workloadmeta.Entity) {

svc := &service{
entity: container,
tagsHash: tagger.GetEntityHash(types.NewEntityID(types.ContainerID, container.ID).String(), tagger.ChecksCardinality()),
tagsHash: tagger.GetEntityHash(types.NewEntityID(types.ContainerID, container.ID), tagger.ChecksCardinality()),
adIdentifiers: computeContainerServiceIDs(
containers.BuildEntityName(string(container.Runtime), container.ID),
containerImg.RawName,
Expand Down
4 changes: 2 additions & 2 deletions comp/core/autodiscovery/listeners/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (l *KubeletListener) createPodService(
})

entity := kubelet.PodUIDToEntityName(pod.ID)
taggerEntityID := common.BuildTaggerEntityID(pod.GetID()).String()
taggerEntityID := common.BuildTaggerEntityID(pod.GetID())
svc := &service{
entity: pod,
tagsHash: tagger.GetEntityHash(taggerEntityID, tagger.ChecksCardinality()),
Expand Down Expand Up @@ -158,7 +158,7 @@ func (l *KubeletListener) createContainerService(
entity := containers.BuildEntityName(string(container.Runtime), container.ID)
svc := &service{
entity: container,
tagsHash: tagger.GetEntityHash(types.NewEntityID(types.ContainerID, container.ID).String(), tagger.ChecksCardinality()),
tagsHash: tagger.GetEntityHash(types.NewEntityID(types.ContainerID, container.ID), tagger.ChecksCardinality()),
ready: pod.Ready,
ports: ports,
extraConfig: map[string]string{
Expand Down
8 changes: 4 additions & 4 deletions comp/core/tagger/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type Component interface {
ReplayTagger() ReplayTagger
GetTaggerTelemetryStore() *telemetry.Store
Tag(entityID string, cardinality types.TagCardinality) ([]string, error)
AccumulateTagsFor(entityID string, cardinality types.TagCardinality, tb tagset.TagsAccumulator) error
Standard(entityID string) ([]string, error)
AccumulateTagsFor(entityID types.EntityID, cardinality types.TagCardinality, tb tagset.TagsAccumulator) error
Standard(entityID types.EntityID) ([]string, error)
List() types.TaggerListResponse
GetEntity(entityID string) (*types.Entity, error)
GetEntity(entityID types.EntityID) (*types.Entity, error)
// subscriptionID is used for logging and debugging purposes
Subscribe(subscriptionID string, filter *types.Filter) (types.Subscription, error)
GetEntityHash(entityID string, cardinality types.TagCardinality) string
GetEntityHash(entityID types.EntityID, cardinality types.TagCardinality) string
AgentTags(cardinality types.TagCardinality) ([]string, error)
GlobalTags(cardinality types.TagCardinality) ([]string, error)
SetNewCaptureTagger(newCaptureTagger Component)
Expand Down
4 changes: 3 additions & 1 deletion comp/core/tagger/component_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

package tagger

import "github.com/DataDog/datadog-agent/comp/core/tagger/types"

// Mock implements mock-specific methods for the tagger component.
type Mock interface {
Component

// SetTags allows to set tags in the mock fake tagger
SetTags(entityID string, source string, low, orch, high, std []string)
SetTags(entityID types.EntityID, source string, low, orch, high, std []string)

// SetGlobalTags allows to set tags in store for the global entity
SetGlobalTags(low, orch, high, std []string)
Expand Down
6 changes: 3 additions & 3 deletions comp/core/tagger/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func UnlockGlobalTaggerClient() {
}

// GetEntity returns the hash for the provided entity id.
func GetEntity(entityID string) (*types.Entity, error) {
func GetEntity(entityID types.EntityID) (*types.Entity, error) {
if globalTagger == nil {
return nil, fmt.Errorf("a global tagger must be set before calling GetEntity")
}
Expand All @@ -53,15 +53,15 @@ func Tag(entity string, cardinality types.TagCardinality) ([]string, error) {
}

// GetEntityHash is an interface function that queries taggerclient singleton
func GetEntityHash(entityID string, cardinality types.TagCardinality) string {
func GetEntityHash(entityID types.EntityID, cardinality types.TagCardinality) string {
if globalTagger != nil {
return globalTagger.GetEntityHash(entityID, cardinality)
}
return ""
}

// StandardTags is an interface function that queries taggerclient singleton
func StandardTags(entityID string) ([]string, error) {
func StandardTags(entityID types.EntityID) ([]string, error) {
if globalTagger == nil {
return nil, fmt.Errorf("a global tagger must be set before calling StandardTags")
}
Expand Down
8 changes: 4 additions & 4 deletions comp/core/tagger/noopimpl/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ func (n *noopTagger) Tag(string, types.TagCardinality) ([]string, error) {
return nil, nil
}

func (n *noopTagger) AccumulateTagsFor(string, types.TagCardinality, tagset.TagsAccumulator) error {
func (n *noopTagger) AccumulateTagsFor(types.EntityID, types.TagCardinality, tagset.TagsAccumulator) error {
return nil
}

func (n *noopTagger) Standard(string) ([]string, error) {
func (n *noopTagger) Standard(types.EntityID) ([]string, error) {
return nil, nil
}

func (n *noopTagger) List() types.TaggerListResponse {
return types.TaggerListResponse{}
}

func (n *noopTagger) GetEntity(string) (*types.Entity, error) {
func (n *noopTagger) GetEntity(types.EntityID) (*types.Entity, error) {
return nil, nil
}

func (n *noopTagger) Subscribe(string, *types.Filter) (types.Subscription, error) {
return nil, fmt.Errorf("not implemented")
}

func (n *noopTagger) GetEntityHash(string, types.TagCardinality) string {
func (n *noopTagger) GetEntityHash(types.EntityID, types.TagCardinality) string {
return ""
}

Expand Down
5 changes: 3 additions & 2 deletions comp/core/tagger/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ func Tagger2PbEntityEvent(event types.EntityEvent) (*pb.StreamTagsEvent, error)
}

// Pb2TaggerEntityID helper to convert a protobuf Entity ID to its expected format.
func Pb2TaggerEntityID(entityID *pb.EntityId) (types.EntityID, error) {
func Pb2TaggerEntityID(entityID *pb.EntityId) (*types.EntityID, error) {
if entityID == nil {
return nil, errors.New("Invalid entityID argument")
}

return types.NewEntityID(types.EntityIDPrefix(entityID.Prefix), entityID.Uid), nil
id := types.NewEntityID(types.EntityIDPrefix(entityID.Prefix), entityID.Uid)
return &id, nil
}

// Pb2TaggerCardinality helper to convert protobuf cardinality to native tag cardinality.
Expand Down
2 changes: 1 addition & 1 deletion comp/core/tagger/taggerimpl/empty/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Tagger struct{}

// GetEntityHash returns the hash for the tags associated with the given entity
// Returns an empty string if the tags lookup fails
func (t *Tagger) GetEntityHash(string, types.TagCardinality) string {
func (t *Tagger) GetEntityHash(types.EntityID, types.TagCardinality) string {
return ""
}

Expand Down
75 changes: 0 additions & 75 deletions comp/core/tagger/taggerimpl/generic_store/default_store.go

This file was deleted.

6 changes: 0 additions & 6 deletions comp/core/tagger/taggerimpl/generic_store/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@
// Package genericstore defines a generic object store that satisfies a redundant use-case in the tagger component implementation.
// The implementation of the tagger component requires storing objects indexed by keys.
// Keys are in the form of `{prefix}://{id}`.
//
// The package provides a generic interface ObjectStore which can store objects of a given type and index by tagger EntityID (i.e. a prefix + an id).
// It also provides 2 implementations of this interface:
// - defaultObjectStore: implements the object store as a plain from entity id to entity object. It is intended to be used when EntityID is stored as a string.
// - compositeObjectStore: implements the object store as a 2-layered map. The first map is indexed by prefix, and the second map is indexed by id. It is intended to be used when EntityID is stored
// as a struct separating prefix and id into 2 fields. This implementation is optimised for quick lookups, listing and filtering by prefix.
package genericstore
9 changes: 2 additions & 7 deletions comp/core/tagger/taggerimpl/generic_store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
package genericstore

import (
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/tagger/types"
)

// NewObjectStore constructs and returns a an ObjectStore
func NewObjectStore[T any](cfg config.Component) types.ObjectStore[T] {
// TODO: use composite object store always or use component framework for config component
if cfg.GetBool("tagger.tagstore_use_composite_entity_id") {
return newCompositeObjectStore[T]()
}
return newDefaultObjectStore[T]()
func NewObjectStore[T any]() types.ObjectStore[T] {
return newCompositeObjectStore[T]()
}
Loading

0 comments on commit 692bb8a

Please sign in to comment.