Documentation
¶
Overview ¶
Package model contains types for Agent config.
For config-related documentation (like adding new config items) check out the config documentation.
Index ¶
- Variables
- func AddOverrideFunc(f func(Config))
- func ApplyOverrideFuncs(config Config)
- func DedupPointerAddr(strcfg *StringifyConfig)
- func NewConfigFileNotFoundError(err error) error
- func OmitPointerAddr(strcfg *StringifyConfig)
- type BuildableConfig
- type Compound
- type Config
- type DirectSetting
- type NotificationReceiver
- type Proxy
- type Reader
- type ReaderWriter
- type Setup
- type Source
- type StringifyConfig
- type StringifyOption
- type ValueWithSource
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrConfigFileNotFound = errors.New("Config File Not Found")
ErrConfigFileNotFound is an error for when the config file is not found
var Sources = []Source{ SourceDefault, SourceUnknown, SourceInfraMode, SourceFile, SourceEnvVar, SourceFleetPolicies, SourceConfigPostInit, SourceSecret, SourceLocalConfigProcess, SourceAgentRuntime, SourceRC, SourceCLI, }
Sources list the known sources, following the order of hierarchy between them
Functions ¶
func AddOverrideFunc ¶
func AddOverrideFunc(f func(Config))
AddOverrideFunc allows to add a custom logic to override configuration. This method must be called before Load() to be effective.
func ApplyOverrideFuncs ¶
func ApplyOverrideFuncs(config Config)
ApplyOverrideFuncs calls overrideFuncs
func DedupPointerAddr ¶ added in v0.67.0
func DedupPointerAddr(strcfg *StringifyConfig)
DedupPointerAddr deduplicates pointers in the Stringify output
func NewConfigFileNotFoundError ¶ added in v0.72.0
NewConfigFileNotFoundError returns a well known error for the config file missing
func OmitPointerAddr ¶ added in v0.67.0
func OmitPointerAddr(strcfg *StringifyConfig)
OmitPointerAddr omits pointer's raw addresses in the Stringify output, useful for testing
Types ¶
type BuildableConfig ¶ added in v0.71.0
type BuildableConfig interface {
ReaderWriter
Setup
Compound
}
BuildableConfig is the most-general interface for the Config, it can be used both to build the config and also to read/write its values. It should only be used when necessary, such as when constructing a new config object from scratch.
type Compound ¶ added in v0.56.0
type Compound interface {
ReadInConfig() error
ReadConfig(in io.Reader) error
MergeConfig(in io.Reader) error
MergeFleetPolicy(configPath string) error
// Revert a finished configuration so that more can be build on top of it.
// When building is completed, the caller should call BuildSchema.
// NOTE: This method should not be used by any new callsites, it is needed
// currently because of the unique requirements of OTel's configuration.
RevertFinishedBackToBuilder() BuildableConfig
}
Compound is an interface for retrieving compound elements from the config, plus some misc functions, that should likely be split into another interface
type Config ¶
type Config interface {
ReaderWriter
Compound
}
Config is an interface that can read/write the config after it has been build and initialized.
type DirectSetting ¶ added in v0.84.0
DirectSetting is one key/value/source assignment for nodetreemodel's DirectBulkSet.
type NotificationReceiver ¶ added in v0.51.0
type NotificationReceiver func(setting string, source Source, oldValue, newValue any, sequenceID uint64, unsetSource Source)
NotificationReceiver represents the callback type to receive notifications each time the `Set` or `UnsetForSource` method is called. The configuration will call each NotificationReceiver registered through the 'OnUpdate' method, therefore 'NotificationReceiver' should not be blocking.
source and newValue describe what the setting resolves to after the change. unsetSource is empty except for a removal, where it names the layer that was cleared and source is the layer now winning, or SourceUnknown when none is left.
type Proxy ¶
type Proxy struct {
HTTP string `mapstructure:"http"`
HTTPS string `mapstructure:"https"`
NoProxy []string `mapstructure:"no_proxy"`
}
Proxy represents the configuration for proxies in the agent
type Reader ¶
type Reader interface {
Get(key string) interface{}
GetString(key string) string
GetBool(key string) bool
GetInt(key string) int
GetInt32(key string) int32
GetInt64(key string) int64
GetFloat64(key string) float64
GetDuration(key string) time.Duration
GetStringSlice(key string) []string
GetFloat64Slice(key string) []float64
GetStringMap(key string) map[string]interface{}
GetStringMapString(key string) map[string]string
GetStringMapStringSlice(key string) map[string][]string
GetSizeInBytes(key string) uint
GetProxies() *Proxy
GetSequenceID() uint64
GetSource(key string) Source
GetAllSources(key string) []ValueWithSource
ConfigFileUsed() string
ExtraConfigFilesUsed() []string
AllSettings() map[string]interface{}
AllSettingsWithoutDefault() map[string]interface{}
// AllSettingsWithoutSecrets returns all settings excluding the secrets layer.
AllSettingsWithoutSecrets() map[string]interface{}
// AllSettingsWithoutDefaultOrSecrets returns settings excluding both defaults and the secrets layer.
AllSettingsWithoutDefaultOrSecrets() map[string]interface{}
AllSettingsBySource() map[Source]interface{}
// AllKeysLowercased returns all config keys in the config, no matter how they are set.
// Note that it returns the keys lowercased.
AllKeysLowercased() []string
// AllFlattenedSettingsWithSequenceID returns all settings as a flattened map of schema leaf keys
// (for example, "logs_config.enabled" instead of nested {"logs_config": {"enabled": ...}})
// along with the current sequence ID.
// This provides atomic access to flattened keys, values, and sequence ID under a single lock.
AllFlattenedSettingsWithSequenceID() (map[string]interface{}, uint64)
// SetTestOnlyDynamicSchema is used by tests to disable validation of the config schema
// This lets tests use the config is more flexible ways (can add to the schema at any point,
// can modify env vars and the config will rebuild itself, etc)
SetTestOnlyDynamicSchema(allow bool)
// IsConfigured returns true if a setting is configured by the user. This means that either:
// 1. The key is for a leaf, and the setting has a non-nil value on a non-default source OR
// 2. The key is for an inner node, and one of its children IsConfigured
IsConfigured(key string) bool
// HasSection returns true if the key is for a non-leaf setting that is defined by the user
HasSection(key string) bool
// IsKnown returns whether this key is known
IsKnown(key string) bool
// IsSetting returns whether the key identifies a setting (and not a section)
IsSetting(key string) bool
// GetEnvVars returns a list of the env vars that the config supports.
// These have had the EnvPrefix applied, as well as the EnvKeyReplacer.
GetEnvVars() []string
// Warnings returns pointer to a list of warnings (completes config.Component interface)
Warnings() []string
// StartTime returns the time at which the agent process started (completes config.Component interface)
StartTime() time.Time
// Object returns Reader to config (completes config.Component interface)
Object() Reader
// OnUpdate adds a callback to the list receivers to be called each time a value is change in the configuration
// by a call to the 'Set' method. The configuration will sequentially call each receiver.
OnUpdate(callback NotificationReceiver)
// Stringify stringifies the config, only available if "test" build tag is enabled
Stringify(source Source, opts ...StringifyOption) string
}
Reader is a subset of Config that only allows reading of configuration
type ReaderWriter ¶
ReaderWriter is a subset of Config that allows reading and writing the configuration
type Setup ¶ added in v0.56.0
type Setup interface {
// BuildSchema should be called when Setup is done, it builds the schema making the config ready for use
BuildSchema()
SetDefault(key string, value interface{})
SetEnvPrefix(in string)
// ParseEnvSplitComma registers a transformer to parse the env var for key as a comma-separated list.
ParseEnvSplitComma(key string)
// ParseEnvSplitSpace registers a transformer to parse the env var for key as a space-separated list.
ParseEnvSplitSpace(key string)
// ParseEnvJSON registers a transformer to parse the env var for key as a JSON payload into varType.
// varType must be a zero value of the target type (e.g. []string{}, []map[string]string{}).
ParseEnvJSON(key string, varType any)
// The following helpers are legacy and should no longer be used. Instead leverage the one above
ParseEnvAsStringSlice(key string, fx func(string) []string)
ParseEnvAsMapStringInterface(key string, fx func(string) map[string]interface{})
// BindEnvAndSetDefault sets the default value for a config parameter and adds an env binding
// in one call, used for most config options.
//
// If env is provided, it will override the name of the environment variable used for this
// config key
BindEnvAndSetDefault(key string, val interface{}, env ...string)
// BindEnvAndSetDefaultWithDeprecation fully declares a setting with a default value, a list of deprecated names and
// optional env var overrides.
// If no env vars are declared, one will be derived from the key name.
// Settings in the deprecated names list take precedence over the official and will automatically generate a warning.
// Name in the list must be sorted by priority (oldest name first).
BindEnvAndSetDefaultWithDeprecation(key string, defaultVal interface{}, deprecatedNames []string, envvars ...string)
AddConfigPath(in string)
AddExtraConfigPaths(in []string) error
SetConfigName(in string)
SetConfigFile(in string)
SetConfigType(in string)
}
Setup is a subset of Config that allows setting up the configuration
type Source ¶
type Source string
Source stores what edits a setting as a string
const ( // SourceSchema are settings define in the schema for the configuration but without any default. SourceSchema Source = "schema" // SourceDefault are the values from defaults. SourceDefault Source = "default" // SourceUnknown are the values from unknown source. This should only be used in tests when calling // SetInTest. SourceUnknown Source = "unknown" // SourceInfraMode are the values set by infrastructure mode configurations. These values have higher // priority than defaults but lower priority than user configuration (file, env vars, etc.). SourceInfraMode Source = "infra-mode" // SourceFile are the values loaded from configuration file. SourceFile Source = "file" // SourceEnvVar are the values loaded from the environment variables. SourceEnvVar Source = "environment-variable" // SourceConfigPostInit are values computed by the agent during initial config setup. SourceConfigPostInit Source = "config-post-init" // SourceSecret are values resolved from secrets (ENC[...] placeholders). SourceSecret Source = "secret" // SourceLocalConfigProcess are the values mirrored from the config process via the configsync HTTP // polling mechanism. SourceLocalConfigProcess Source = "local-config-process" // SourceAgentRuntime are the values configured by the agent itself. The agent can dynamically compute the best // value for some settings when not set by the user. SourceAgentRuntime Source = "agent-runtime" // SourceRC are the values loaded from remote-config (aka Datadog backend) SourceRC Source = "remote-config" // SourceFleetPolicies are the values loaded from remote-config file SourceFleetPolicies Source = "fleet-policies" // SourceCLI are the values set by the user at runtime through the CLI. SourceCLI Source = "cli" // SourceProvided are all values set by any source but default. SourceProvided Source = "provided" // everything but defaults )
Declare every known Source
func (Source) IsGreaterThan ¶ added in v0.62.0
IsGreaterThan returns true if the current source is of higher priority than the one given as a parameter
func (Source) PreviousSource ¶ added in v0.62.0
PreviousSource returns the source before the current one, or Default (lowest priority) if there isn't one
type StringifyConfig ¶ added in v0.67.0
StringifyConfig defines configuration options for the Stringify method
type StringifyOption ¶ added in v0.67.0
type StringifyOption func(*StringifyConfig)
StringifyOption sets an option on the StringifyConfig
func FilterSettings ¶ added in v0.67.0
func FilterSettings(filters []string) StringifyOption
FilterSettings will filter the output of Stringify to only show the given settings
type ValueWithSource ¶ added in v0.51.0
type ValueWithSource struct {
Source Source
Value interface{}
}
ValueWithSource is a tuple for a source and a value, not necessarily the applied value in the main config
type Writer ¶
type Writer interface {
Set(key string, value interface{}, source Source)
SetInTest(key string, value interface{})
UnsetForSource(key string, source Source)
// DirectBulkSet writes settings already resolved by another config, keeping each one in the
// source layer it came from so the result mirrors the sender. It exists for config streaming
// and nothing else should call it: unlike Set it accepts SourceEnvVar, which makes it unfit
// for applying a live change. shouldNotify notifies receivers for every setting whose resolved
// value changed, which a snapshot replacing a config the process already runs on requires.
DirectBulkSet(settings []DirectSetting, shouldNotify bool)
}
Writer is a subset of Config that only allows writing the configuration