Skip to content

Commit

Permalink
[PROCS-1464] Add Process Discovery Feature to Operator (#927)
Browse files Browse the repository at this point in the history
* initial commit

* add tests
  • Loading branch information
just-chillin authored Sep 26, 2023
1 parent e81840e commit b1e69ec
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Operator `1.0.0` contains several changes users need to be aware of:
- Live Container Collection
- Orchestrator Explorer
- UnixDomainSocket transport for DogStatsD (and APM if enabled)
- Process Discovery

## Functionalities

Expand Down
1 change: 1 addition & 0 deletions apis/datadoghq/common/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (
DDProcessCollectionEnabled = "DD_PROCESS_CONFIG_PROCESS_COLLECTION_ENABLED"
DDProcessConfigScrubArgs = "DD_PROCESS_CONFIG_SCRUB_ARGS"
DDProcessConfigStripArgs = "DD_PROCESS_CONFIG_STRIP_PROC_ARGUMENTS"
DDProcessDiscoveryEnabled = "DD_PROCESS_CONFIG_PROCESS_DISCOVERY_ENABLED"
DDPrometheusScrapeChecks = "DD_PROMETHEUS_SCRAPE_CHECKS"
DDPrometheusScrapeEnabled = "DD_PROMETHEUS_SCRAPE_ENABLED"
DDPrometheusScrapeServiceEndpoints = "DD_PROMETHEUS_SCRAPE_SERVICE_ENDPOINTS"
Expand Down
9 changes: 9 additions & 0 deletions apis/datadoghq/v2alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
// defaultLiveProcessCollectionEnabled bool = false
defaultLiveContainerCollectionEnabled bool = true

defaultProcessDiscoveryEnabled bool = true

// defaultOOMKillEnabled bool = false
// defaultTCPQueueLengthEnabled bool = false

Expand Down Expand Up @@ -153,6 +155,13 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) {
}
}

// ProcessDiscovery Feature
if ddaSpec.Features.ProcessDiscovery == nil || apiutils.IsEqualStruct(*ddaSpec.Features.ProcessDiscovery, ProcessDiscoveryFeatureConfig{}) {
ddaSpec.Features.ProcessDiscovery = &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
}
}

// APM Feature
if ddaSpec.Features.APM != nil && ddaSpec.Features.APM.Enabled != nil && *ddaSpec.Features.APM.Enabled {
if ddaSpec.Features.APM.HostPortConfig == nil {
Expand Down
41 changes: 41 additions & 0 deletions apis/datadoghq/v2alpha1/datadogagent_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -129,6 +132,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueFalse),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueFalse),
},
OOMKill: &OOMKillFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueFalse),
},
Expand Down Expand Up @@ -191,6 +197,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueFalse),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueFalse),
},
OOMKill: &OOMKillFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueFalse),
},
Expand Down Expand Up @@ -274,6 +283,10 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
// The agent will automatically disable process discovery collection in this case
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -339,6 +352,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -396,6 +412,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
APM: &APMFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueTrue),
HostPortConfig: &HostPortConfig{
Expand Down Expand Up @@ -464,6 +483,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
NPM: &NPMFeatureConfig{
Enabled: apiutils.NewBoolPointer(valueTrue),
EnableConntrack: apiutils.NewBoolPointer(defaultNPMEnableConntrack),
Expand Down Expand Up @@ -533,6 +555,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -590,6 +615,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -652,6 +680,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -710,6 +741,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -768,6 +802,9 @@ func Test_defaultFeatures(t *testing.T) {
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultLiveContainerCollectionEnabled),
},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
Dogstatsd: &DogstatsdFeatureConfig{
OriginDetectionEnabled: apiutils.NewBoolPointer(defaultDogstatsdOriginDetectionEnabled),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultDogstatsdHostPortEnabled)},
Expand Down Expand Up @@ -820,6 +857,7 @@ func Test_defaultFeatures(t *testing.T) {
LogCollection: &LogCollectionFeatureConfig{},
LiveProcessCollection: &LiveProcessCollectionFeatureConfig{},
LiveContainerCollection: &LiveContainerCollectionFeatureConfig{},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{},
OOMKill: &OOMKillFeatureConfig{},
TCPQueueLength: &TCPQueueLengthFeatureConfig{},
APM: &APMFeatureConfig{},
Expand All @@ -842,6 +880,9 @@ func Test_defaultFeatures(t *testing.T) {
Features: &DatadogFeatures{
LogCollection: &LogCollectionFeatureConfig{},
LiveProcessCollection: &LiveProcessCollectionFeatureConfig{},
ProcessDiscovery: &ProcessDiscoveryFeatureConfig{
Enabled: apiutils.NewBoolPointer(defaultProcessDiscoveryEnabled),
},
OOMKill: &OOMKillFeatureConfig{},
TCPQueueLength: &TCPQueueLengthFeatureConfig{},
APM: &APMFeatureConfig{},
Expand Down
11 changes: 11 additions & 0 deletions apis/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type DatadogFeatures struct {
LiveProcessCollection *LiveProcessCollectionFeatureConfig `json:"liveProcessCollection,omitempty"`
// LiveContainerCollection configuration.
LiveContainerCollection *LiveContainerCollectionFeatureConfig `json:"liveContainerCollection,omitempty"`
// ProcessDiscovery configuration.
ProcessDiscovery *ProcessDiscoveryFeatureConfig `json:"processDiscovery,omitempty"`
// OOMKill configuration.
OOMKill *OOMKillFeatureConfig `json:"oomKill,omitempty"`
// TCPQueueLength configuration.
Expand Down Expand Up @@ -196,6 +198,15 @@ type LiveContainerCollectionFeatureConfig struct {
Enabled *bool `json:"enabled,omitempty"`
}

// ProcessDiscoveryFeatureConfig contains the configuration for the process discovery check
// ProcessDiscovery is run in the ProcessAgent
type ProcessDiscoveryFeatureConfig struct {
// Enabled enables the Process Discovery check in the Agent.
// Default: true
// +optional
Enabled *bool `json:"enabled,omitempty"`
}

// OOMKillFeatureConfig configures the OOM Kill monitoring feature.
type OOMKillFeatureConfig struct {
// Enables the OOMKill eBPF-based check.
Expand Down
25 changes: 25 additions & 0 deletions apis/datadoghq/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion apis/datadoghq/v2alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogagents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8323,6 +8323,13 @@ spec:
type: object
type: object
type: object
processDiscovery:
description: ProcessDiscovery configuration.
properties:
enabled:
description: 'Enabled enables the Process Discovery check in the Agent. Default: true'
type: boolean
type: object
prometheusScrape:
description: PrometheusScrape configuration.
properties:
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/v1beta1/datadoghq.com_datadogagents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15873,6 +15873,13 @@ spec:
type: object
type: object
type: object
processDiscovery:
description: ProcessDiscovery configuration.
properties:
enabled:
description: 'Enabled enables the Process Discovery check in the Agent. Default: true'
type: boolean
type: object
prometheusScrape:
description: PrometheusScrape configuration.
properties:
Expand Down
1 change: 1 addition & 0 deletions controllers/datadogagent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/oomkill"
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/orchestratorexplorer"
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/otlp"
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/processdiscovery"
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/prometheusscrape"
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/remoteconfig"
_ "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/tcpqueuelength"
Expand Down
2 changes: 2 additions & 0 deletions controllers/datadogagent/feature/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
LiveContainerIDType = "live_container"
// LiveProcessIDType Live Process feature.
LiveProcessIDType = "live_process"
// ProcessDiscoveryIDType Process Discovery feature.
ProcessDiscoveryIDType = "process_discovery"
// OrchestratorExplorerIDType Orchestrator Explorer feature.
OrchestratorExplorerIDType = "orchestrator_explorer"
// LogCollectionIDType Log Collection feature.
Expand Down
77 changes: 77 additions & 0 deletions controllers/datadogagent/feature/processdiscovery/feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package processdiscovery

import (
corev1 "k8s.io/api/core/v1"

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object/volume"
)

func init() {
err := feature.Register(feature.ProcessDiscoveryIDType, buildProcessDiscoveryFeature)
if err != nil {
panic(err)
}
}

func buildProcessDiscoveryFeature(options *feature.Options) feature.Feature {
return &processDiscoveryFeature{}
}

type processDiscoveryFeature struct{}

func (p processDiscoveryFeature) ID() feature.IDType {
return feature.ProcessDiscoveryIDType
}

func (p processDiscoveryFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredComponents {
var reqComp feature.RequiredComponents
if dda.Spec.Features.ProcessDiscovery == nil || apiutils.BoolValue(dda.Spec.Features.ProcessDiscovery.Enabled) {
reqComp = feature.RequiredComponents{
Agent: feature.RequiredComponent{
IsRequired: apiutils.NewBoolPointer(true),
Containers: []apicommonv1.AgentContainerName{
apicommonv1.CoreAgentContainerName,
apicommonv1.ProcessAgentContainerName,
},
},
}
}
return reqComp
}

func (p processDiscoveryFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) feature.RequiredComponents {
return feature.RequiredComponents{}
}

func (p processDiscoveryFeature) ManageDependencies(managers feature.ResourceManagers, components feature.RequiredComponents) error {
return nil
}

func (p processDiscoveryFeature) ManageClusterAgent(managers feature.PodTemplateManagers) error {
return nil
}

func (p processDiscoveryFeature) ManageNodeAgent(managers feature.PodTemplateManagers) error {
passwdVol, passwdVolMount := volume.GetVolumes(apicommon.PasswdVolumeName, apicommon.PasswdHostPath, apicommon.PasswdMountPath, true)
managers.VolumeMount().AddVolumeMountToContainer(&passwdVolMount, apicommonv1.ProcessAgentContainerName)
managers.Volume().AddVolume(&passwdVol)

enableEnvVar := &corev1.EnvVar{
Name: apicommon.DDProcessDiscoveryEnabled,
Value: "true",
}

managers.EnvVar().AddEnvVarToContainer(apicommonv1.ProcessAgentContainerName, enableEnvVar)

return nil
}

func (p processDiscoveryFeature) ManageClusterChecksRunner(managers feature.PodTemplateManagers) error {
return nil
}
Loading

0 comments on commit b1e69ec

Please sign in to comment.