agentcfg

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// ErrInfrastructureNotReady is returned when a fetch request comes in while
	// the infrastructure is not ready to serve the request.
	// This may happen when the local cache is not initialized and no fallback fetcher is configured.
	ErrInfrastructureNotReady = "agentcfg infrastructure is not ready"

	// ErrNoValidElasticsearchConfig is an error where the server is
	// not properly configured to fetch agent configuration.
	ErrNoValidElasticsearchConfig = "no valid elasticsearch config to fetch agent config"
)
View Source
const (
	// ServiceName keyword
	ServiceName = "service.name"
	// ServiceEnv keyword
	ServiceEnv = "service.environment"
	// Etag / If-None-Match keyword
	Etag = "ifnonematch"
	// EtagSentinel is a value to return back to agents when Kibana doesn't have any configuration
	EtagSentinel = "-"
)
View Source
const ElasticsearchIndexName = ".apm-agent-configuration"
View Source
const TransactionSamplingRateKey = "transaction_sample_rate"

TransactionSamplingRateKey is the agent configuration key for the sampling rate. This is used by the Jaeger handler to adapt our agent configuration to the Jaeger remote sampler protocol.

Variables

View Source
var UnrestrictedSettings = map[string]bool{"transaction_sample_rate": true}

UnrestrictedSettings are settings considered safe to be returned to all requesters, including unauthenticated ones such as RUM.

Functions

This section is empty.

Types

type AgentConfig

type AgentConfig struct {
	// Config holds configuration settings that should be sent to
	// agents matching the above constraints.
	Config map[string]string
	// ServiceName holds the service name to which this agent configuration
	// applies. This is optional.
	ServiceName string
	// ServiceEnvironment holds the service environment to which this agent
	// configuration applies. This is optional.
	ServiceEnvironment string
	// AgentName holds the agent name to which this agent configuration
	// applies. This is optional, and is used for filtering configuration
	// settings for unauthenticated agents.
	AgentName string
	// Etag holds a unique ID for the configuration, which agents
	// will send along with their queries. The server uses this to
	// determine whether agent configuration has been applied.
	Etag string
}

AgentConfig holds an agent configuration definition.

type ElasticsearchFetcher

type ElasticsearchFetcher struct {
	// contains filtered or unexported fields
}

TODO: - Add Otel tracer - Collection metrics

func NewElasticsearchFetcher

func NewElasticsearchFetcher(
	client *elasticsearch.Client,
	cacheDuration time.Duration,
	logger *zap.Logger,
) *ElasticsearchFetcher

func (*ElasticsearchFetcher) Fetch

func (f *ElasticsearchFetcher) Fetch(ctx context.Context, query Query) (Result, error)

Fetch finds a matching agent config based on the received query.

func (*ElasticsearchFetcher) Run

Run refreshes the fetcher cache by querying Elasticsearch periodically.

type Fetcher

type Fetcher interface {
	Fetch(context.Context, Query) (Result, error)
}

Fetcher defines a common interface to retrieving agent config.

type Query

type Query struct {
	Service Service `json:"service"`
	// Etag should be set to the Etag of a previous agent config query result.
	// When the query is processed by the receiver a new Etag is calculated
	// for the query result. If Etags from the query and the query result match,
	// it indicates that the exact same query response has already been delivered.
	Etag string `json:"etag"`
	// InsecureAgents holds a set of prefixes for restricting results to those whose
	// agent name matches any of the specified prefixes.
	//
	// If InsecureAgents is non-empty, and any of the prefixes matches the result,
	// then the resulting settings will be filtered down to the subset of settings
	// identified by UnrestrictedSettings. Otherwise, if InsecureAgents is empty,
	// the agent name is ignored and no restrictions are applied.
	InsecureAgents []string `json:"-"`
	// MarkAsAppliedByAgent can be used to signal to the receiver that the response to this
	// query can be considered to have been applied immediately. When building queries for Elastic APM
	// agent requests the Etag should be set, instead of the AppliedByAgent setting.
	// Use this flag when building queries for third party integrations,
	// such as Jaeger, that do not send an Etag in their request.
	MarkAsAppliedByAgent bool `json:"mark_as_applied_by_agent,omitempty"`
}

Query represents an URL body or query params for agent configuration

type Result

type Result struct {
	Source Source `json:"_source"`
}

Result models a Kibana response

type Service

type Service struct {
	Name        string `json:"name"`
	Environment string `json:"environment,omitempty"`
}

Service holds supported attributes for querying configuration

type Settings

type Settings map[string]string

Settings hold agent configuration

func (Settings) UnmarshalJSON

func (s Settings) UnmarshalJSON(b []byte) error

UnmarshalJSON overrides default method to convert any JSON type to string

type Source

type Source struct {
	Settings Settings `json:"settings"`
	Etag     string   `json:"etag"`
	Agent    string   `json:"agent_name"`
}

Source is the Elasticsearch _source

Jump to

Keyboard shortcuts

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