tagger

package
v0.0.0-...-8c2e9aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

package tagger

The Tagger is the central source of truth for client-side entity tagging. It subscribes to workloadmeta to get updates for all the entity kinds (containers, kubernetes pods, kubernetes nodes, etc.) and extracts the tags for each of them. Tags are then stored in memory (by the TagStore) and can be queried by the tagger.Tag() method. Calling once tagger.Start() after the config package is ready is needed to enable collection.

The package methods use a common defaultTagger object, but we can create a custom Tagger object for testing.

The package implements an IPC mechanism (a server and a client) to allow other agents to query the DefaultTagger and avoid duplicating the information in their process. Check the remote package for more details.

The tagger is also available to python checks via the tagger module exporting the get_tags() function. This function accepts the same arguments as the Go Tag() function, and returns an empty list on errors.

Workloadmeta

The entities that need to be tagged are collected by workloadmeta. The tagger subscribes to workloadmeta to get updates for all the entity kinds (containers, kubernetes pods, kubernetes nodes, etc.) and extracts the tags for each of them.

TagStore

The TagStore reads types.TagInfo structs and stores them in an in-memory cache. Cache invalidation is triggered by the collectors (or source) by either:

  • sending new tags for the same Entity, all the tags from this Source will be removed and replaced by the new tags.
  • sending a types.TagInfo with DeleteEntity set, all the tags collected for this entity by the specified source (but not others) will be deleted when prune() is called.

TagCardinality

types.TagInfo accepts and store tags that have different cardinality. TagCardinality can be:

  • LowCardinality: in the host count order of magnitude
  • OrchestratorCardinality: tags that change value for each pod or task
  • HighCardinality: typically tags that change value for each web request, user agent, container, etc.

Entity IDs

Tagger entities are identified by a string-typed ID, with one of the following forms:

Entity ID
workloadmeta.KindContainer container_id://<sha>
workloadmeta.KindContainerImageMetadata container_image_metadata://<sha>
workloadmeta.KindECSTask ecs_task://<task-id>
workloadmeta.KindHost host
workloadmeta.KindKubernetesDeployment deployment://<namespace>/<name>
workloadmeta.KindKubernetesNamespace namespace://<name>
workloadmeta.KindKubernetesNode kubernetes_node_uid://<name>
workloadmeta.KindKubernetesPod kubernetes_pod_uid://<uid>
workloadmeta.KindProcess process://<pid>

Tagger

The Tagger handles the glue between the workloadmeta collector and the TagStore.

For convenience, the package creates a defaultTagger object that is used when calling the tagger.Tag() method.

               +--------------+
               | Workloadmeta |
               +---+----------+
                   |
                   |
+--------+      +--+-------+       +-------------+
|  User  <------+  Tagger  +-------> IPC handler |
|packages|      +--+-----^-+       +-------------+
+--------+         |     |
                   |     |
                +--v-----+-+
                | TagStore |
                +----------+

Documentation

Overview

Package tagger provides the tagger component for the Datadog Agent

Index

Constants

This section is empty.

Variables

View Source
var (

	// ChecksCardinality defines the cardinality of tags we should send for check metrics
	// this can still be overridden when calling get_tags in python checks.
	ChecksCardinality types.TagCardinality

	// DogstatsdCardinality defines the cardinality of tags we should send for metrics from
	// dogstatsd.
	DogstatsdCardinality types.TagCardinality
)

Functions

func AccumulateTagsFor

func AccumulateTagsFor(entity string, cardinality types.TagCardinality, tb tagset.TagsAccumulator) error

AccumulateTagsFor is an interface function that queries taggerclient singleton

func AgentTags

func AgentTags(cardinality types.TagCardinality) ([]string, error)

AgentTags is an interface function that queries taggerclient singleton

func EnrichTags

func EnrichTags(tb tagset.TagsAccumulator, originInfo taggertypes.OriginInfo)

EnrichTags is an interface function that queries taggerclient singleton

func GetEntity

func GetEntity(entityID string) (*types.Entity, error)

GetEntity returns the hash for the provided entity id.

func GetEntityHash

func GetEntityHash(entity string, cardinality types.TagCardinality) string

GetEntityHash is an interface function that queries taggerclient singleton

func GlobalTags

func GlobalTags(cardinality types.TagCardinality) ([]string, error)

GlobalTags is an interface function that queries taggerclient singleton

func List

List the content of the defaulTagger

func ResetCaptureTagger

func ResetCaptureTagger()

ResetCaptureTagger will reset capture tagger

func SetGlobalTaggerClient

func SetGlobalTaggerClient(t Component)

SetGlobalTaggerClient sets the global taggerClient instance

func SetNewCaptureTagger

func SetNewCaptureTagger(newCaptureTagger Component)

SetNewCaptureTagger will set capture tagger in global tagger instance by using provided capture tagger

func StandardTags

func StandardTags(entity string) ([]string, error)

StandardTags is an interface function that queries taggerclient singleton

func Tag

func Tag(entity string, cardinality types.TagCardinality) ([]string, error)

Tag is an interface function that queries taggerclient singleton

func UnlockGlobalTaggerClient

func UnlockGlobalTaggerClient()

UnlockGlobalTaggerClient releases the initOnce lock on the global tagger. For testing only.

Types

type AgentTypeForTagger

type AgentTypeForTagger uint8

AgentTypeForTagger represents agent types that tagger is used for

const (
	LocalTaggerAgent AgentTypeForTagger = 1 << iota
	NodeRemoteTaggerAgent
	CLCRunnerRemoteTaggerAgent
	FakeTagger
)

Define agent type for tagger

type Component

type Component interface {
	Start(ctx context.Context) error
	Stop() error
	Tag(entity string, cardinality types.TagCardinality) ([]string, error)
	AccumulateTagsFor(entity string, cardinality types.TagCardinality, tb tagset.TagsAccumulator) error
	Standard(entity string) ([]string, error)
	List() types.TaggerListResponse
	GetEntity(entityID string) (*types.Entity, error)
	Subscribe(cardinality types.TagCardinality) chan []types.EntityEvent
	Unsubscribe(ch chan []types.EntityEvent)
	GetEntityHash(entity string, cardinality types.TagCardinality) string
	AgentTags(cardinality types.TagCardinality) ([]string, error)
	GlobalTags(cardinality types.TagCardinality) ([]string, error)
	SetNewCaptureTagger(newCaptureTagger Component)
	ResetCaptureTagger()
	EnrichTags(tb tagset.TagsAccumulator, originInfo taggertypes.OriginInfo)
}

Component is the component type.

func GetTaggerInstance

func GetTaggerInstance() Component

GetTaggerInstance returns the global Tagger instance

type Params

type Params struct {
	AgentTypeForTagger                 AgentTypeForTagger
	FallBackToLocalIfRemoteTaggerFails bool
}

Params provides the kind of agent we're instantiating workloadmeta for

func NewCLCRunnerRemoteTaggerParams

func NewCLCRunnerRemoteTaggerParams() Params

NewCLCRunnerRemoteTaggerParams creates a Params struct with the CLCRunnerRemoteTagger type

func NewFakeTaggerParams

func NewFakeTaggerParams() Params

NewFakeTaggerParams creates a Params struct with the FakeTagger type and for testing purposes

func NewNodeRemoteTaggerParams

func NewNodeRemoteTaggerParams() Params

NewNodeRemoteTaggerParams creates a Params struct with the NodeRemoteTagger type

func NewNodeRemoteTaggerParamsWithFallback

func NewNodeRemoteTaggerParamsWithFallback() Params

NewNodeRemoteTaggerParamsWithFallback creates a Params struct with the NodeRemoteTagger type and fallback to local tagger if remote tagger fails

func NewTaggerParams

func NewTaggerParams() Params

NewTaggerParams creates a Params struct with the default LocalTagger type

func NewTaggerParamsForCoreAgent

func NewTaggerParamsForCoreAgent(_ config.Component) Params

NewTaggerParamsForCoreAgent is a constructor function for creating core agent tagger params

Directories

Path Synopsis
Package taggerimpl contains the implementation of the tagger component.
Package taggerimpl contains the implementation of the tagger component.
api
Package api implements the Tagger API.
Package api implements the Tagger API.
collectors
Package collectors implements a collector for the Tagger component that subscribes to workloadmeta
Package collectors implements a collector for the Tagger component that subscribes to workloadmeta
empty
Package empty implements empty functions for the tagger component interface.
Package empty implements empty functions for the tagger component interface.
local
Package local implements a local Tagger.
Package local implements a local Tagger.
remote
Package remote implements a remote Tagger.
Package remote implements a remote Tagger.
replay
Package replay implements the Tagger replay.
Package replay implements the Tagger replay.
server
Package server implements a gRPC server that streams Tagger entities.
Package server implements a gRPC server that streams Tagger entities.
subscriber
Package subscriber implements the functionality needed to subscribe to events generated by the Tagger component.
Package subscriber implements the functionality needed to subscribe to events generated by the Tagger component.
tagstore
Package tagstore implements the TagStore which is the component of the Tagger responsible for storing the tags in memory.
Package tagstore implements the TagStore which is the component of the Tagger responsible for storing the tags in memory.
telemetry
Package telemetry defines the telemetry for the Tagger component.
Package telemetry defines the telemetry for the Tagger component.
Package types defines types used by the Tagger component.
Package types defines types used by the Tagger component.
Package utils defines several helpers used by the Tagger component.
Package utils defines several helpers used by the Tagger component.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL