Documentation
¶
Overview ¶
Package utils offers a number of high level helpers to work with the configuration
Index ¶
- Constants
- func APIEndpointFromURL(rawURL string) string
- func AddAgentVersionToDomain(DDURL string, app string) (string, error)
- func AddAgentVersionToSite(site, app string) string
- func BuildURLWithPrefix(prefix, site string) string
- func ConfFileDirectory(c pkgconfigmodel.Reader) string
- func DedupAPIKeys(endpoints []APIKeys) []string
- func ExtractSiteFromURL(rawURL string) string
- func GetBindHost(cfg pkgconfigmodel.Reader) string
- func GetClusterAgentEndpoint() (string, error)
- func GetConfiguredDCATags(c pkgconfigmodel.Reader) []string
- func GetConfiguredTags(c pkgconfigmodel.Reader, includeDogstatsd bool) []string
- func GetInfraEndpoint(c pkgconfigmodel.Reader) string
- func GetMRFEndpoint(c pkgconfigmodel.Reader, prefix, ddMRFURLKey string) (string, error)
- func GetMRFInfraEndpoint(c pkgconfigmodel.Reader) (string, error)
- func GetMRFLogsEndpoint(c pkgconfigmodel.Reader, prefix string) (string, error)
- func GetMainEndpoint(c pkgconfigmodel.Reader, prefix string, ddURLKey string) string
- func GetMainEndpointBackwardCompatible(c pkgconfigmodel.Reader, prefix string, ddURLKey string, backwardKey string) string
- func GetTraceAgentDefaultEnv(c pkgconfigmodel.Reader) string
- func IsAPMEnabled(cfg pkgconfigmodel.Reader) bool
- func IsAgentTelemetryEnabled(cfg pkgconfigmodel.Reader) bool
- func IsCheckTelemetryEnabled(checkName string, cfg pkgconfigmodel.Reader) bool
- func IsCloudProviderEnabled(cloudProviderName string, config pkgconfigmodel.Reader) bool
- func IsCoreAgentEnabled(cfg pkgconfigmodel.Reader) bool
- func IsDataSecurityEnabled(cfg pkgconfigmodel.Reader) bool
- func IsDatadogLogsHost(host string) bool
- func IsDatadogURL(rawURL string) bool
- func IsDelaDirective(value string) bool
- func IsErrorTrackingEnabled(cfg pkgconfigmodel.Reader) bool
- func IsFed(cfg pkgconfigmodel.Reader) bool
- func IsMRFAliasURL(rawURL string) bool
- func IsRemoteConfigEnabled(cfg pkgconfigmodel.Reader) bool
- func IsTelemetryEnabled(cfg pkgconfigmodel.Reader) bool
- func MakeEndpoints(endpoints map[string][]string, root string) map[string][]APIKeys
- func MarkedInfraMode(c pkgconfigmodel.Reader) string
- func MarkedInfraModeTags(c pkgconfigmodel.Reader) []string
- func PartitionRealAndPendingKeys(keys []string) (realKeys []string, hasPendingDelegatedAuth bool)
- func ResolveInfrastructureMode(c pkgconfigmodel.Reader) string
- func SanitizeAPIKey(key string) string
- func SetLogLevel(level string, config pkgconfigmodel.Writer, source pkgconfigmodel.Source) error
- func WithoutInfraModeTags(tags []string) []string
- type APIKeys
- type EndpointDescriptor
- type EndpointDescriptorSet
- type MetadataAsTags
- type MetadataProviders
- type MetricsEndpointRouting
Constants ¶
const ( // InfraURLPrefix is the default infra URL prefix for datadog InfraURLPrefix = "https://app." // MRFLogsPrefix is the logs-specific MRF site prefix. This is used for both pure logs as well as EvP-based payloads (Database // Monitoring, Netflow, etc) MRFLogsPrefix = "logs.mrf." // MRFInfraPrefix is the infrastructure-specific MRF site prefix. This is used for metadata, metrics, etc. MRFInfraPrefix = "mrf." )
const ( InfraModeFull = constants.InfraModeFull InfraModeEndUserDevice = constants.InfraModeEndUserDevice )
const InfraModeTagKey = "infra_mode"
InfraModeTagKey is the tag key that marks a payload with the infrastructure mode of the Agent that produced it. It differs from the `infrastructure_mode` setting name on purpose: the setting name is not a tag key.
const MetricsEndpointRoutingKey = "experimental.metrics_endpoint_routing"
MetricsEndpointRoutingKey is the configuration namespace for per-endpoint metric policies.
Variables ¶
This section is empty.
Functions ¶
func APIEndpointFromURL ¶ added in v0.85.0
APIEndpointFromURL returns the base URL for API calls (e.g., API key validation) related to the given endpoint URL.
If the URL belongs to a Datadog site, the API endpoint for that site is returned: "https://app.us3.datadoghq.com" returns "https://api.us3.datadoghq.com". Otherwise, such as for proxies or customer-specific Multi-Region Failover aliases, the URL is returned unchanged.
func AddAgentVersionToDomain ¶
AddAgentVersionToDomain prefixes the domain with the agent version: X-Y-Z.domain
func AddAgentVersionToSite ¶ added in v0.86.0
AddAgentVersionToSite builds the versioned Agent host URL for a site and app.
func BuildURLWithPrefix ¶ added in v0.52.0
BuildURLWithPrefix will return an HTTP(s) URL for a site given a certain prefix. If the site is a datadog well-known one, it is suffixed with a dot to make it a FQDN. Using FQDN will prevent useless DNS queries built with the search domains of `/etc/resolv.conf`. https://docs.datadoghq.com/getting_started/site/#access-the-datadog-site
func ConfFileDirectory ¶
func ConfFileDirectory(c pkgconfigmodel.Reader) string
ConfFileDirectory returns the absolute path to the folder containing the config file used to populate the registry
func DedupAPIKeys ¶ added in v0.66.0
DedupAPIKeys takes a single array of endpoints and returns an array of unique api keys that they contain. This needs to be a separate process to loading because we need to keep track of the endpoints with the API config location to know when they have been refreshed.
func ExtractSiteFromURL ¶ added in v0.77.0
ExtractSiteFromURL extracts the Datadog site from a URL. For example:
"https://intake.profile.us3.datadoghq.com/v1/input" returns "us3.datadoghq.com" "https://intake.profile.datadoghq.com/v1/input" returns "datadoghq.com" "https://intake.profile.datadoghq.eu/v1/input" returns "datadoghq.eu"
Returns an empty string if the URL cannot be parsed or does not contain a recognized Datadog domain.
func GetBindHost ¶ added in v0.73.0
func GetBindHost(cfg pkgconfigmodel.Reader) string
GetBindHost returns the `bind_host` value. Callers that need to distinguish "user explicitly set bind_host" from "default applied" must check `cfg.IsConfigured("bind_host")` directly (see trace-agent's containerized auto-`0.0.0.0` logic).
func GetClusterAgentEndpoint ¶ added in v0.60.0
GetClusterAgentEndpoint provides a validated https endpoint from configuration keys in datadog.yaml: 1st. configuration key "cluster_agent.url" (or the DD_CLUSTER_AGENT_URL environment variable),
add the https prefix if the scheme isn't specified
2nd. environment variables associated with "cluster_agent.kubernetes_service_name"
${dcaServiceName}_SERVICE_HOST and ${dcaServiceName}_SERVICE_PORT
func GetConfiguredDCATags ¶ added in v0.61.0
func GetConfiguredDCATags(c pkgconfigmodel.Reader) []string
GetConfiguredDCATags returns list of tags from a configuration, based on `cluster_checks.extra_tags` (DD_CLUSTER_CHECKS_EXTRA_TAGS) and `orchestrator_explorer.extra_tags (DD_ORCHESTRATOR_EXPLORER_EXTRA_TAGS).
func GetConfiguredTags ¶
func GetConfiguredTags(c pkgconfigmodel.Reader, includeDogstatsd bool) []string
GetConfiguredTags returns list of tags from a configuration, based on `tags` (DD_TAGS) and `extra_tags“ (DD_EXTRA_TAGS), with `dogstatsd_tags` (DD_DOGSTATSD_TAGS) if includeDogdstatsd is true.
func GetInfraEndpoint ¶
func GetInfraEndpoint(c pkgconfigmodel.Reader) string
GetInfraEndpoint returns the main DD Infra URL defined in config, based on the value of `site` and `dd_url`
func GetMRFEndpoint ¶ added in v0.54.0
func GetMRFEndpoint(c pkgconfigmodel.Reader, prefix, ddMRFURLKey string) (string, error)
GetMRFEndpoint returns the generic MRF endpoint to use.
This is based on the `multi_region_failover.site` setting. If `ddMRFURLKey` is not empty, we attempt to use it as a lookup key in the configuration. If a valid is set at the given key, it is used as an override URL that takes precedence over `multi_region_failover.site`.
func GetMRFInfraEndpoint ¶ added in v0.54.0
func GetMRFInfraEndpoint(c pkgconfigmodel.Reader) (string, error)
GetMRFInfraEndpoint returns the infrastructure-specific MRF endpoint to use.
This is based on the `multi_region_failover.site` setting. If `ddMRFURLKey` is not empty, we attempt to use it as a lookup key in the configuration. If a valid is set at the given key, it is used as an override URL that takes precedence over `multi_region_failover.site`.
func GetMRFLogsEndpoint ¶ added in v0.60.0
func GetMRFLogsEndpoint(c pkgconfigmodel.Reader, prefix string) (string, error)
GetMRFLogsEndpoint returns the logs-specific MRF endpoint to use.
This is based on the `multi_region_failover.site` setting. If `ddMRFURLKey` is not empty, we attempt to use it as a lookup key in the configuration. If a valid is set at the given key, it is used as an override URL that takes precedence over `multi_region_failover.site`.
func GetMainEndpoint ¶
func GetMainEndpoint(c pkgconfigmodel.Reader, prefix string, ddURLKey string) string
GetMainEndpoint returns the main DD URL defined in the config, based on `site` and the prefix, or ddURLKey
func GetMainEndpointBackwardCompatible ¶
func GetMainEndpointBackwardCompatible(c pkgconfigmodel.Reader, prefix string, ddURLKey string, backwardKey string) string
GetMainEndpointBackwardCompatible implements the logic to extract the DD URL from a config, based on `site`,ddURLKey and a backward compatible key
func GetTraceAgentDefaultEnv ¶
func GetTraceAgentDefaultEnv(c pkgconfigmodel.Reader) string
GetTraceAgentDefaultEnv returns the default env for the trace agent
func IsAPMEnabled ¶ added in v0.61.0
func IsAPMEnabled(cfg pkgconfigmodel.Reader) bool
IsAPMEnabled checks if APM is enabled or if Error Tracking standalone is enabled, simplifying the setup for Error Tracking standalone only via the apm_config.error_tracking_standalone.enabled option instead of requiring to enable also apm_config.enabled.
func IsAgentTelemetryEnabled ¶ added in v0.73.0
func IsAgentTelemetryEnabled(cfg pkgconfigmodel.Reader) bool
IsAgentTelemetryEnabled returns true if Agent Telemetry is enabled
func IsCheckTelemetryEnabled ¶
func IsCheckTelemetryEnabled(checkName string, cfg pkgconfigmodel.Reader) bool
IsCheckTelemetryEnabled returns if we want telemetry for the given check. Returns true if a * is present in the telemetry.checks list.
func IsCloudProviderEnabled ¶ added in v0.73.0
func IsCloudProviderEnabled(cloudProviderName string, config pkgconfigmodel.Reader) bool
IsCloudProviderEnabled checks the cloud provider family provided in pkg/util/<cloud_provider>.go against the value for cloud_provider: on the global config object Datadog
func IsCoreAgentEnabled ¶ added in v0.61.0
func IsCoreAgentEnabled(cfg pkgconfigmodel.Reader) bool
IsCoreAgentEnabled checks if the Agent is able to send the payloads it and other Agents need to function with
func IsDataSecurityEnabled ¶ added in v0.83.0
func IsDataSecurityEnabled(cfg pkgconfigmodel.Reader) bool
IsDataSecurityEnabled returns true if Data Security is enabled. It requires both data_security.enabled and shared_library_check.enabled, as it relies on the datasecurity shared-library check.
func IsDatadogLogsHost ¶ added in v0.86.0
IsDatadogLogsHost reports whether host is rooted under the logs subdomain of a Datadog site: "<labels>.logs.<site>". For example, it accepts "agent-http-intake.logs.datadoghq.com", "foobar.logs.datad0g.com" and "http-intake.logs.us3.datadoghq.com", but not "logs.datadoghq.com", "agent-http-intake.logs.x.us3.datadoghq.com" or "agent-http-intake.logs.datadoghq.com.evil". The comparison is case-insensitive and allows a single trailing dot (FQDN form).
func IsDatadogURL ¶ added in v0.81.0
IsDatadogURL reports whether the given URL's host is a known Datadog site or any subdomain of one (e.g. app.datadoghq.com, metrics.agent.us5.datadoghq.com).
func IsDelaDirective ¶ added in v0.84.0
IsDelaDirective reports whether a value is a delegated-auth directive (e.g. "DELA[<org_uuid>, aws]") rather than a literal API key. The delegatedauth component writes the real key back into the same config slot once fetched; until then consumers must skip (not send) values where this returns true.
func IsErrorTrackingEnabled ¶ added in v0.82.0
func IsErrorTrackingEnabled(cfg pkgconfigmodel.Reader) bool
IsErrorTrackingEnabled returns true when both the parent agent-telemetry gate and the errortracking feature flag are enabled. The gov/FIPS exclusion from IsAgentTelemetryEnabled applies automatically.
func IsFed ¶ added in v0.72.0
func IsFed(cfg pkgconfigmodel.Reader) bool
IsFed returns true if the Agent is running in a gov environment
func IsMRFAliasURL ¶ added in v0.86.0
IsMRFAliasURL reports whether the given URL points at a customer-specific Multi-Region Failover alias.
func IsRemoteConfigEnabled ¶ added in v0.72.0
func IsRemoteConfigEnabled(cfg pkgconfigmodel.Reader) bool
IsRemoteConfigEnabled returns true if Remote Configuration should be enabled
func IsTelemetryEnabled ¶
func IsTelemetryEnabled(cfg pkgconfigmodel.Reader) bool
IsTelemetryEnabled returns whether or not telemetry is enabled
func MakeEndpoints ¶ added in v0.66.0
MakeEndpoints takes a map of domain to apikeys and a config path root and converts this to a map of domain to Endpoint structs.
func MarkedInfraMode ¶ added in v0.86.0
func MarkedInfraMode(c pkgconfigmodel.Reader) string
MarkedInfraMode returns the `infra_mode` tag value for the Agent, or the empty string when the resolved mode carries no mark.
The value describes the Agent process and not an entity, so it is stored under a dedicated Tagger entity and appended where a payload the Agent itself produces is serialized. Eligible Agent integration metrics use the same value via pkg/util/infratags (check-name gated). It must never reach a customer custom metric or plain DogStatsD sample: the metrics intake renames series tagged `infra_mode:cloud_cost_only` into the `dd.cloud_cost` namespace, so a mark that leaks onto a customer series removes that metric from dashboards, monitors and metering.
func MarkedInfraModeTags ¶ added in v0.86.0
func MarkedInfraModeTags(c pkgconfigmodel.Reader) []string
MarkedInfraModeTags returns []{"infra_mode:<mode>"} when the Agent is in a marked mode, otherwise nil.
func PartitionRealAndPendingKeys ¶ added in v0.84.0
PartitionRealAndPendingKeys splits keys from an `additional_endpoints`-style config list into real API keys and reports whether at least one pending DELA[...] directive was present. A caller that builds one endpoint per real key should still keep a placeholder entry for the domain when hasPendingDelegatedAuth is true and no real keys are returned, so the domain still gets a config-update watcher/resolver and can pick up the real key once delegated auth resolves it and writes it back into the same config slot - otherwise a fully-pending domain would be dropped and never see the key.
func ResolveInfrastructureMode ¶ added in v0.86.0
func ResolveInfrastructureMode(c pkgconfigmodel.Reader) string
ResolveInfrastructureMode returns the validated `infrastructure_mode` of the Agent. A value outside the declared set resolves to full, so that a typo cannot produce a mark that no consumer expects. The invalid value itself is reported once when the configuration loads, so this does not log.
func SanitizeAPIKey ¶
SanitizeAPIKey strips newlines and other control characters from a given string.
func SetLogLevel ¶ added in v0.57.0
func SetLogLevel(level string, config pkgconfigmodel.Writer, source pkgconfigmodel.Source) error
SetLogLevel validates and sets the "log_level" setting in the configuration. The logger will automatically react to this configuration change. It takes a `level` string representing the desired log level — a single level or a per-package level specification — and a `source` model.Source indicating where the new level came from (CLI, Remote Config, ...). It returns an error if the log level is invalid
func WithoutInfraModeTags ¶ added in v0.86.0
WithoutInfraModeTags returns a copy of tags with every infra_mode:* entry removed.
Types ¶
type APIKeys ¶ added in v0.66.0
type APIKeys struct {
// The path of the config used to get the API key. This path is used to listen for configuration updates from
// the config.
ConfigSettingPath string
// the apiKey to use for this endpoint
Keys []string
// HasPendingDelegatedAuth keeps a legacy endpoint usable while a DELA[...] directive
// is waiting for the delegatedauth component to write its resolved API key.
HasPendingDelegatedAuth bool
}
APIKeys contains a list of API keys together with the path within the config that this API key were configured.
func NewAPIKeys ¶ added in v0.66.0
NewAPIKeys creates an endpoint
type EndpointDescriptor ¶ added in v0.74.0
type EndpointDescriptor struct {
BaseURL string
APIKeySet []APIKeys
IsMRF bool
// ConfigName is the endpoint URL as it appears in the configuration, if it differs from BaseURL.
ConfigName string
// HasPendingDelegatedAuth is true when this domain has no real API keys yet but is known to
// be waiting on one from the delegatedauth component (a DELA[...] directive in
// additional_endpoints). Consumers (e.g. the forwarder's resolver.IsUsable()) should treat
// such a domain as usable so it isn't dropped before delegated auth has a chance to deliver
// a real key.
HasPendingDelegatedAuth bool
}
EndpointDescriptor holds configuration about a single endpoint (aka domain) for infra pipelines.
func NewEndpointDescriptorWithConfigName ¶ added in v0.86.0
func NewEndpointDescriptorWithConfigName(configName, baseURL string, apiKeySet []APIKeys) EndpointDescriptor
NewEndpointDescriptorWithConfigName creates an EndpointDescriptor whose resolver tracks configuration updates under configName rather than baseURL.
type EndpointDescriptorSet ¶ added in v0.74.0
type EndpointDescriptorSet = map[string]EndpointDescriptor
EndpointDescriptorSet is a collection of all endpoints for infra pipelines keyed by base URL.
func EndpointDescriptorSetFromKeysPerDomain ¶ added in v0.74.0
func EndpointDescriptorSetFromKeysPerDomain(keysPerDomain map[string][]APIKeys) EndpointDescriptorSet
EndpointDescriptorSetFromKeysPerDomain converts legacy endpoint configuration into EndpointDescriptorSet.
func GetMultipleEndpoints ¶
func GetMultipleEndpoints(c pkgconfigmodel.Reader) (EndpointDescriptorSet, error)
GetMultipleEndpoints returns the api keys per domain specified in the main agent config
type MetadataAsTags ¶ added in v0.58.0
type MetadataAsTags interface {
// GetPodLabelsAsTags returns pod labels as tags
GetPodLabelsAsTags() map[string]string
// GetPodAnnotationsAsTags returns pod annotations as tags
GetPodAnnotationsAsTags() map[string]string
// GetNodeLabelsAsTags returns node labels as tags
GetNodeLabelsAsTags() map[string]string
// GetNodeAnnotationsAsTags returns node annotations as tags
GetNodeAnnotationsAsTags() map[string]string
// GetNamespaceLabelsAsTags returns namespace labels as tags
GetNamespaceLabelsAsTags() map[string]string
// GetNamespaceAnnotationsAsTags returns namespace annotations as tags
GetNamespaceAnnotationsAsTags() map[string]string
// GetResourcesLabelsAsTags returns resources labels as tags
GetResourcesLabelsAsTags() map[string]map[string]string
// GetResourcesAnnotationsAsTags returns resources annotations as tags
GetResourcesAnnotationsAsTags() map[string]map[string]string
}
MetadataAsTags contains the labels as tags and annotations as tags for each kubernetes resource based on the user configurations of the following options ordered in increasing order of priority:
kubernetes_pod_labels_as_tags kubernetes_pod_annotations_as_tags kubernetes_node_labels_as_tags kubernetes_node_annotations_as_tags kubernetes_namespace_labels_as_tags kubernetes_namespace_annotations_as_tags kubernetes_resources_labels_as_tags kubernetes_resources_anotations_as_tags
In case of conflict, higher priority configuration value takes precedences For example, if kubernetes_pod_labels_as_tags = {`l1`: `v1`, `l2`: `v2`} and kubernetes_resources_labels_as_tags = {`pods`: {`l1`: `x`}}, the resulting labels as tags for pods will be {`l1`: `x`, `l2`: `v2`}
When gpu.enabled is true, the pod label/annotation configured in gpu.jobs is then added to the pod tags, unless that key is already mapped by one of the options above.
func GetMetadataAsTags ¶ added in v0.58.0
func GetMetadataAsTags(c pkgconfigmodel.Reader) MetadataAsTags
GetMetadataAsTags returns a merged configuration of all labels and annotations as tags set by the user
type MetadataProviders ¶
type MetadataProviders struct {
Name string `mapstructure:"name"`
Interval time.Duration `mapstructure:"interval"`
EarlyInterval time.Duration `mapstructure:"early_interval"`
}
MetadataProviders helps unmarshalling `metadata_providers` config param
func GetMetadataProviders ¶
func GetMetadataProviders(c pkgconfigmodel.Reader) ([]MetadataProviders, error)
GetMetadataProviders returns the "metadata_providers" set in the configuration
type MetricsEndpointRouting ¶ added in v0.86.0
type MetricsEndpointRouting struct {
MetricAllowlist map[string][]string
MetricPrefixAllowlist map[string][]string
// PrimaryEndpointURL is the URL used by the forwarder.
PrimaryEndpointURL string
}
MetricsEndpointRouting defines metric allowlists for primary and additional endpoints. Endpoints without a policy receive all metrics. Empty policies send none.
func ReadMetricsEndpointRouting ¶ added in v0.86.0
func ReadMetricsEndpointRouting(c model.Reader) (MetricsEndpointRouting, error)
ReadMetricsEndpointRouting reads policies and validates their endpoint URLs.