agent

package
v0.79.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package agent includes helpers related to the Datadog Agent on Windows

Package agent includes helpers related to the Datadog Agent on Windows

Index

Constants

View Source
const (
	// RegistryKeyPath is the root registry key that the Datadog Agent uses to store some state
	RegistryKeyPath = "HKLM:\\SOFTWARE\\Datadog\\Datadog Agent"
	// DefaultInstallPath is the default install path for the Datadog Agent
	DefaultInstallPath = `C:\Program Files\Datadog\Datadog Agent`
	// DefaultConfigRoot is the default config root for the Datadog Agent
	DefaultConfigRoot = `C:\ProgramData\Datadog`
	// DefaultAgentUserName is the default user name for the Datadog Agent
	DefaultAgentUserName = `ddagentuser`
	// AutologgerRegistryKeyPath is the path to the Autologger registry key
	AutologgerRegistryKeyPath = `HKLM:\SYSTEM\CurrentControlSet\Control\WMI\Autologger\Datadog Logon Duration`
)

Variables

This section is empty.

Functions

func GetAgentUserFromRegistry

func GetAgentUserFromRegistry(host *components.RemoteHost) (string, string, error)

GetAgentUserFromRegistry gets the domain and username that the agent was installed with from the registry

func GetBetaMSIURL

func GetBetaMSIURL(version string, arch string, flavor string) (string, error)

GetBetaMSIURL returns the URL for the beta agent MSI

majorVersion: 6, 7 arch: x86_64 flavor: base, fips

func GetChannelURL

func GetChannelURL(channel string) (string, error)

GetChannelURL returns the URL for the channel name

channel: beta, stable

func GetCodeSignatureThumbprints added in v0.57.0

func GetCodeSignatureThumbprints() map[string]struct{}

GetCodeSignatureThumbprints returns the allowed code detached thumbprint used for Windows signing

func GetConfigRootFromRegistry

func GetConfigRootFromRegistry(host *components.RemoteHost) (string, error)

GetConfigRootFromRegistry gets the config root from the registry, e.g. C:\ProgramData\Datadog

func GetDatadogAgentProductCode

func GetDatadogAgentProductCode(host *components.RemoteHost) (string, error)

GetDatadogAgentProductCode returns the product code GUID for the Datadog Agent

func GetDatadogProductVersion added in v0.63.0

func GetDatadogProductVersion(host *components.RemoteHost) (string, error)

GetDatadogProductVersion returns the product version for the Datadog Agent

func GetFlavorProductName added in v0.62.0

func GetFlavorProductName(flavor string) (string, error)

GetFlavorProductName returns the product name for the flavor

flavor: base, fips

func GetInstallPathFromRegistry

func GetInstallPathFromRegistry(host *components.RemoteHost) (string, error)

GetInstallPathFromRegistry gets the install path from the registry, e.g. C:\Program Files\Datadog\Datadog Agent

func GetLatestMSIURL

func GetLatestMSIURL(majorVersion string, arch string, flavor string) (string, error)

GetLatestMSIURL returns the URL for the latest agent MSI

majorVersion: 6, 7 arch: x86_64

func GetMSIURL

func GetMSIURL(channel string, version string, arch string, flavor string) (string, error)

GetMSIURL returns the URL for the agent MSI

channel: beta, stable majorVersion: 6, 7 arch: x86_64 flavor: base, fips

func GetPipelineMSIURL

func GetPipelineMSIURL(pipelineID string, majorVersion string, arch string, flavor string, nameSuffix string) (string, error)

GetPipelineMSIURL returns the URL for the agent MSI built by the pipeline

majorVersion: 6, 7 arch: x86_64 flavor: base, fips

func GetStableMSIURL

func GetStableMSIURL(version string, arch string, flavor string) (string, error)

GetStableMSIURL returns the URL for the stable agent MSI

majorVersion: 6, 7 arch: x86_64 flavor: base, fips

func HasValidDatadogCodeSignature

func HasValidDatadogCodeSignature(host *components.RemoteHost, path string) error

HasValidDatadogCodeSignature an error if the file at the given path is not validy signed by the Datadog Code Signing certificate

func InstallAgent

func InstallAgent(host *components.RemoteHost, options ...InstallAgentOption) (string, error)

InstallAgent installs the agent and returns the remote MSI path and any errors

func RepairAllAgent

func RepairAllAgent(host *components.RemoteHost, args string, logPath string) error

RepairAllAgent repairs the Datadog Agent

func TestAgentHasNoWorldWritablePaths added in v0.72.0

func TestAgentHasNoWorldWritablePaths(t *testing.T, host *components.RemoteHost) bool

TestAgentHasNoWorldWritablePaths tests that the Agent install and config paths do not contain world-writable paths

func TestAgentVersion

func TestAgentVersion(t *testing.T, expected string, actual string) bool

TestAgentVersion compares the major.minor.patch-prefix parts of two agent versions

func TestHasNoWorldWritablePaths added in v0.72.0

func TestHasNoWorldWritablePaths(t *testing.T, host *components.RemoteHost, paths []string) bool

TestHasNoWorldWritablePaths tests that the given paths do not contain world-writable paths

func TestValidDatadogCodeSignatures

func TestValidDatadogCodeSignatures(t *testing.T, host *components.RemoteHost, paths []string) bool

TestValidDatadogCodeSignatures verifies that the files at the given paths are validly signed by the Datadog Code Signing certificate This test is skipped if the verify_code_signature parameter is set to false.

func UninstallAgent

func UninstallAgent(host *components.RemoteHost, logPath string) error

UninstallAgent uninstalls the Datadog Agent

Types

type InstallAgentOption

type InstallAgentOption = func(*InstallAgentParams) error

InstallAgentOption is an optional function parameter type for InstallAgentParams options

func WithAPIKey

func WithAPIKey(apiKey string) InstallAgentOption

WithAPIKey specifies the APIKEY parameter.

func WithAPMEnabled added in v0.54.0

func WithAPMEnabled(apmEnabled string) InstallAgentOption

WithAPMEnabled specifies the APM_ENABLED parameter.

func WithAddLocal added in v0.56.0

func WithAddLocal(addLocal string) InstallAgentOption

WithAddLocal specifies the ADDLOCAL parameter.

func WithAgentUser

func WithAgentUser(username string) InstallAgentOption

WithAgentUser specifies the DDAGENTUSER_NAME parameter.

func WithAgentUserPassword

func WithAgentUserPassword(password string) InstallAgentOption

WithAgentUserPassword specifies the DDAGENTUSER_PASSWORD parameter.

func WithApplicationDataDirectory added in v0.54.0

func WithApplicationDataDirectory(applicationDataDirectory string) InstallAgentOption

WithApplicationDataDirectory specifies the APPLICATIONDATADIRECTORY parameter.

func WithCmdPort added in v0.54.0

func WithCmdPort(cmdPort string) InstallAgentOption

WithCmdPort specifies the CMD_PORT parameter.

func WithDdURL

func WithDdURL(ddURL string) InstallAgentOption

WithDdURL specifies the DD_URL parameter.

func WithDownloadMSIBackoff added in v0.59.0

func WithDownloadMSIBackoff(backoff backoff.BackOff) InstallAgentOption

WithDownloadMSIBackoff specifies the backoff strategy for downloading the MSI.

func WithFakeIntake

func WithFakeIntake(fakeIntake *components.FakeIntake) InstallAgentOption

WithFakeIntake configures the Agent to use a fake intake URL.

func WithHostname added in v0.54.0

func WithHostname(hostname string) InstallAgentOption

WithHostname specifies the HOSTNAME parameter.

func WithInfrastructureMode added in v0.73.0

func WithInfrastructureMode(infrastructureMode string) InstallAgentOption

WithInfrastructureMode specifies the DD_INFRASTRUCTURE_MODE parameter.

func WithInstallLogFile

func WithInstallLogFile(logFileName string) InstallAgentOption

WithInstallLogFile specifies the file on the local test runner to save the MSI install logs.

func WithInstallOnly added in v0.74.0

func WithInstallOnly(installOnly string) InstallAgentOption

WithInstallOnly specifies the DD_INSTALL_ONLY parameter. When set to "1", the MSI will skip starting the Agent services.

func WithIntegrationsPersistence added in v0.63.0

func WithIntegrationsPersistence(IntegrationsPersistence string) InstallAgentOption

WithIntegrationsPersistence specifies the INSTALL_PYTHON_THIRD_PARTY_DEPS parameter.

func WithLastStablePackage

func WithLastStablePackage() InstallAgentOption

WithLastStablePackage specifies to use the last stable installation package.

func WithLogonDurationAutologger added in v0.78.0

func WithLogonDurationAutologger(enabled string) InstallAgentOption

WithLogonDurationAutologger specifies the DD_LOGON_DURATION_AUTOLOGGER parameter. When set to "true", the MSI will configure the ETW AutoLogger for logon duration monitoring.

func WithLogsDdURL added in v0.54.0

func WithLogsDdURL(logsDdURL string) InstallAgentOption

WithLogsDdURL specifies the LOGS_DD_URL parameter.

func WithLogsEnabled added in v0.54.0

func WithLogsEnabled(logsEnabled string) InstallAgentOption

WithLogsEnabled specifies the LOGS_ENABLED parameter.

func WithPackage

func WithPackage(agentPackage *Package) InstallAgentOption

WithPackage specifies the Agent installation package.

func WithProcessDdURL added in v0.54.0

func WithProcessDdURL(processDdURL string) InstallAgentOption

WithProcessDdURL specifies the PROCESS_DD_URL parameter.

func WithProcessDiscoveryEnabled added in v0.54.0

func WithProcessDiscoveryEnabled(processDiscoveryEnabled string) InstallAgentOption

WithProcessDiscoveryEnabled specifies the PROCESS_DISCOVERY_ENABLED parameter.

func WithProcessEnabled added in v0.54.0

func WithProcessEnabled(processEnabled string) InstallAgentOption

WithProcessEnabled specifies the PROCESS_ENABLED parameter, which controls process_collection.

func WithProjectLocation added in v0.54.0

func WithProjectLocation(projectLocation string) InstallAgentOption

WithProjectLocation specifies the PROJECTLOCATION parameter.

func WithProxyHost added in v0.54.0

func WithProxyHost(proxyHost string) InstallAgentOption

WithProxyHost specifies the PROXY_HOST parameter.

func WithProxyPassword added in v0.54.0

func WithProxyPassword(proxyPassword string) InstallAgentOption

WithProxyPassword specifies the PROXY_PASSWORD parameter.

func WithProxyPort added in v0.54.0

func WithProxyPort(proxyPort string) InstallAgentOption

WithProxyPort specifies the PROXY_PORT parameter.

func WithProxyUser added in v0.54.0

func WithProxyUser(proxyUser string) InstallAgentOption

WithProxyUser specifies the PROXY_USER parameter.

func WithRemoteUpdates added in v0.73.0

func WithRemoteUpdates(remoteUpdates string) InstallAgentOption

WithRemoteUpdates specifies the DD_REMOTE_UPDATES parameter.

func WithSite

func WithSite(site string) InstallAgentOption

WithSite specifies the SITE parameter.

func WithTags added in v0.54.0

func WithTags(tags string) InstallAgentOption

WithTags specifies the TAGS parameter.

func WithTraceDdURL added in v0.54.0

func WithTraceDdURL(traceDdURL string) InstallAgentOption

WithTraceDdURL specifies the TRACE_DD_URL parameter.

func WithValidAPIKey

func WithValidAPIKey() InstallAgentOption

WithValidAPIKey sets a valid API key fetched from the runner secret store.

func WithWixFailWhenDeferred

func WithWixFailWhenDeferred() InstallAgentOption

WithWixFailWhenDeferred sets the WixFailWhenDeferred parameter.

func WithZeroAPIKey added in v0.64.0

func WithZeroAPIKey() InstallAgentOption

WithZeroAPIKey sets APIKEY=00000000000000000000000000000000

Useful for cases that require api_key to be configured but do not need it to be a real/valid api key.

type InstallAgentParams

type InstallAgentParams struct {
	Package            *Package
	DownloadMSIBackOff backoff.BackOff

	// Path on local test runner to save the MSI install log
	LocalInstallLogFile string

	msi.InstallAgentParams
	// Installer parameters
	WixFailWhenDeferred      string `installer_arg:"WIXFAILWHENDEFERRED"`
	ProjectLocation          string `installer_arg:"PROJECTLOCATION"`
	ApplicationDataDirectory string `installer_arg:"APPLICATIONDATADIRECTORY"`
	AddLocal                 string `installer_arg:"ADDLOCAL"`
	IntegrationsPersistence  string `installer_arg:"INSTALL_PYTHON_THIRD_PARTY_DEPS"`
	// Installer parameters for agent config
	APIKey                  string `installer_arg:"APIKEY"`
	Tags                    string `installer_arg:"TAGS"`
	Hostname                string `installer_arg:"HOSTNAME"`
	CmdPort                 string `installer_arg:"CMD_PORT"`
	ProxyHost               string `installer_arg:"PROXY_HOST"`
	ProxyPort               string `installer_arg:"PROXY_PORT"`
	ProxyUser               string `installer_arg:"PROXY_USER"`
	ProxyPassword           string `installer_arg:"PROXY_PASSWORD"`
	LogsDdURL               string `installer_arg:"LOGS_DD_URL"`
	ProcessDdURL            string `installer_arg:"PROCESS_DD_URL"`
	TraceDdURL              string `installer_arg:"TRACE_DD_URL"`
	LogsEnabled             string `installer_arg:"LOGS_ENABLED"`
	ProcessEnabled          string `installer_arg:"PROCESS_ENABLED"`
	ProcessDiscoveryEnabled string `installer_arg:"PROCESS_DISCOVERY_ENABLED"`
	APMEnabled              string `installer_arg:"APM_ENABLED"`
	RemoteUpdates           string `installer_arg:"DD_REMOTE_UPDATES"`
	InfrastructureMode      string `installer_arg:"DD_INFRASTRUCTURE_MODE"`
	InstallOnly             string `installer_arg:"DD_INSTALL_ONLY"`
	LogonDurationAutologger string `installer_arg:"DD_LOGON_DURATION_AUTOLOGGER"`
}

InstallAgentParams are the parameters used for installing the Agent using msiexec.

type Package

type Package struct {

	// PipelineID is the pipeline ID used to lookup the MSI URL from the CI pipeline artifacts.
	PipelineID string
	// Channel is the channel used to lookup the MSI URL for the Version from the installers_v2.json file.
	Channel string
	// Version is the package version for resolution (e.g. "7.75.0-1", "7.49.0-rc.3-1")
	Version string
	// Arch is the architecture of the MSI, e.g. x86_64
	Arch string
	// URL is the URL the MSI can be downloaded from
	URL string
	// Flavor is the Agent Flavor (e.g. `base`, `fips`, `iot`)
	Flavor string
	// Product is the installers json package name (e.g. `datadog-agent`, `datadog-fips-agent`)
	Product string

	// AssertAgentVersion is the expected agent display version (e.g. "7.75.0").
	// Used by AgentVersion() for test assertions and logging.
	AssertAgentVersion string
	// AssertPackageVersion is the expected url-safe package version (e.g. "7.75.0-1").
	// Used for Fleet status assertions in tests.
	AssertPackageVersion string
}

Package contains identifying information about an Agent MSI package.

func GetLastStablePackageFromEnv

func GetLastStablePackageFromEnv(defaults ...PackageOption) (*Package, error)

GetLastStablePackageFromEnv returns the latest stable agent MSI package.

It delegates to NewPackage with WithArtifactOverrides("STABLE_AGENT"), which reads the STABLE_AGENT_* environment variables to determine the MSI URL.

In CI, these variables are set by the pipeline script from release.json or LAST_STABLE_PIPELINE_ID. See WithArtifactOverrides for the full list of supported environment variables.

Optional PackageOption arguments are applied as defaults before the STABLE_AGENT_* overrides, so environment variables always take priority.

func GetPackageFromEnv

func GetPackageFromEnv(defaults ...PackageOption) (*Package, error)

GetPackageFromEnv looks at environment variables to select the Agent MSI URL.

The returned Package contains the MSI URL and other identifying information. Some Package fields will be populated but may not be related to the returned URL. For example, if a URL is provided directly, the Channel, Version, Arch, and Flavor fields have no effect on the returned URL. They are returned anyway so they can be used for other purposes, such as logging, stack name, instance options, test assertions, etc.

Resolution priority (first match wins):

  1. CURRENT_AGENT_MSI_URL — direct URL override
  2. CURRENT_AGENT_PIPELINE or CURRENT_AGENT_SOURCE_VERSION — explicit package source
  3. E2E_PIPELINE_ID — implicit fallback set by [.new_e2e_template] for all CI jobs

Optional PackageOption arguments are applied as defaults before the CURRENT_AGENT_* overrides, so environment variables always take priority.

If none of the above resolve to a URL, an error is returned.

func GetUpgradeTestPackageFromEnv added in v0.63.0

func GetUpgradeTestPackageFromEnv() (*Package, error)

GetUpgradeTestPackageFromEnv returns the upgrade test package to use in upgrade test.

The upgrade test MSI is a variant of the current agent built by the same pipeline, identified by a "-upgrade-test" suffix in the S3 artifact name.

Resolution priority:

  1. CURRENT_AGENT_MSI_URL (or UPGRADE_AGENT_MSI_URL) -- direct URL
  2. CURRENT_AGENT_PIPELINE (or CURRENT_AGENT_MSI_PIPELINE) -- pipeline lookup with "-upgrade-test" suffix

Arch and flavor are read from the CURRENT_AGENT_MSI_* overrides (see WithArtifactOverrides).

func NewPackage added in v0.66.0

func NewPackage(opts ...PackageOption) (*Package, error)

NewPackage creates a new Package with the provided options.

After all options are applied, Resolve() is called to fill in derived fields (e.g. URL from PipelineID or Version+Channel). Options that set URL directly (WithURL) make Resolve() a no-op.

func (*Package) AgentVersion

func (p *Package) AgentVersion() string

AgentVersion returns the agent display version for assertions (e.g. "7.75.0", "7.78.0-devel").

If AssertAgentVersion is set (via _ASSERT_VERSION), it is returned directly. Otherwise, the version is derived from the resolution Version field by trimming the "-1" suffix and parsing. This fallback supports tests that construct Package structs directly with hardcoded versions.

func (*Package) Resolve added in v0.79.0

func (p *Package) Resolve() error

Resolve fills in derived fields after all options have been applied. It only performs I/O if URL is not already set.

Resolution priority (first match wins):

  1. URL already set -- no-op
  2. PipelineID set -- fetches MSI URL from S3 pipeline artifacts
  3. Version set -- infers channel if needed, fetches URL from installers_v2.json

type PackageOption added in v0.66.0

type PackageOption func(*Package) error

PackageOption defines a function type for modifying a Package

func WithArch added in v0.66.0

func WithArch(arch string) PackageOption

WithArch sets the architecture for the Package

Default is x86_64

If using installers_v2.json, the arch must match the arch key in the json file

Example: x86_64

func WithArtifactOverrides added in v0.79.0

func WithArtifactOverrides(prefix string) PackageOption

WithArtifactOverrides applies environment variable overrides to the Package. Overrides are always applied, regardless of whether the code is running in CI.

Use this for default/CI flows where the pipeline controls the version, e.g. GetPackageFromEnv, GetLastStablePackageFromEnv, and the default createStableAgent/createCurrentAgent in base_suite.go.

This is a pure field-setter: it reads environment variables and sets struct fields, but does not perform any I/O. URL resolution is deferred to Package.Resolve, which is called automatically at the end of NewPackage.

Assertion variables (never affect resolution)

{PREFIX}_ASSERT_VERSION         - Agent display version for test assertions (e.g. "7.75.0")
{PREFIX}_ASSERT_PACKAGE_VERSION - URL-safe package version for test assertions (e.g. "7.75.0-1")

Resolution variables (mutually exclusive)

{PREFIX}_SOURCE_VERSION - Package version for lookup (e.g. "7.75.0-1"), clears any pipeline set by prior options
{PREFIX}_PIPELINE       - Pipeline ID, resolves MSI from S3 pipeline artifacts

MSI-specific overrides (take priority over resolution vars)

{PREFIX}_MSI_FLAVOR   - Agent flavor (e.g. "base", "fips")
{PREFIX}_MSI_PRODUCT  - Product name (e.g. "datadog-agent")
{PREFIX}_MSI_ARCH     - Architecture (e.g. "x86_64")
{PREFIX}_MSI_CHANNEL  - Channel (e.g. "stable", "beta")
{PREFIX}_MSI_VERSION  - Package version (e.g. "7.75.0-1")
{PREFIX}_MSI_URL      - Direct MSI URL (skips Resolve)
{PREFIX}_MSI_PIPELINE - Pipeline ID for MSI (overrides _PIPELINE)

Examples:

export STABLE_AGENT_SOURCE_VERSION="7.75.0-1"
export STABLE_AGENT_PIPELINE="123456"
export CURRENT_AGENT_MSI_URL="file:///path/to/msi/package.msi"

func WithChannel added in v0.66.0

func WithChannel(channel string) PackageOption

WithChannel sets the channel for the Package

Example: beta, stable

func WithDevEnvOverrides added in v0.66.0

func WithDevEnvOverrides(prefix string) PackageOption

WithDevEnvOverrides applies environment variable overrides to the Package, but only when not running in CI (i.e. when the CI environment variable is unset).

Use this for tests that pin a specific version and only want local-dev overrides. In CI, the test's hardcoded version is always used; locally, the developer can override anything via environment variables.

The supported environment variables are the same as WithArtifactOverrides.

func WithFlavor added in v0.66.0

func WithFlavor(flavor string) PackageOption

WithFlavor sets the flavor for the Package

Default is empty, which is the base flavor

Example: base, fips

func WithPipelineID added in v0.66.0

func WithPipelineID(pipelineID string) PackageOption

WithPipelineID sets the pipeline ID for the Package

func WithProduct added in v0.66.0

func WithProduct(product string) PackageOption

WithProduct sets the product for the Package

If using installers_v2.json, the product must match the product key in the json file

Example: datadog-agent, datadog-fips-agent

func WithURL added in v0.66.0

func WithURL(url string) PackageOption

WithURL sets the URL for the MSI Package

func WithVersion added in v0.66.0

func WithVersion(version string) PackageOption

WithVersion sets the version for the Package

If using installers_v2.json, the version must match the version key in the json file

Example: 7.65.0-1, 7.65.0-rc.1-1

Directories

Path Synopsis
installers
v2
Package installers processes the installers_v2.json file
Package installers processes the installers_v2.json file

Jump to

Keyboard shortcuts

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