utils

package module
v0.60.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Overview

Package utils offers a number of high level helpers to work with the configuration

Index

Constants

View Source
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."
)

Variables

This section is empty.

Functions

func AddAgentVersionToDomain

func AddAgentVersionToDomain(DDURL string, app string) (string, error)

AddAgentVersionToDomain prefixes the domain with the agent version: X-Y-Z.domain

func BuildURLWithPrefix added in v0.52.0

func BuildURLWithPrefix(prefix, site string) string

BuildURLWithPrefix will return an HTTP(s) URL for a site given a certain prefix

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 GetClusterAgentEndpoint added in v0.60.0

func GetClusterAgentEndpoint() (string, error)

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 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 GetMultipleEndpoints

func GetMultipleEndpoints(c pkgconfigmodel.Reader) (map[string][]string, error)

GetMultipleEndpoints returns the api keys per domain specified in the main agent config

func GetTraceAgentDefaultEnv

func GetTraceAgentDefaultEnv(c pkgconfigmodel.Reader) string

GetTraceAgentDefaultEnv returns the default env for the trace agent

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 IsTelemetryEnabled

func IsTelemetryEnabled(cfg pkgconfigmodel.Reader) bool

IsTelemetryEnabled returns whether or not telemetry is enabled

func SanitizeAPIKey

func SanitizeAPIKey(key string) string

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 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

Types

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`}

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"`
}

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

Jump to

Keyboard shortcuts

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