Skip to content

Commit

Permalink
[PROCS-4294] Add ability to run Language Detection in Core Agent (#1366)
Browse files Browse the repository at this point in the history
* Add ability to run language detection on core agent

* update version check for run in core agent feature

---------

Co-authored-by: levan-m <116471169+levan-m@users.noreply.github.com>
  • Loading branch information
daniel-taf and levan-m committed Aug 27, 2024
1 parent a473ab0 commit dd7bff3
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 18 deletions.
18 changes: 17 additions & 1 deletion controllers/datadogagent/feature/apm/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/DataDog/datadog-operator/controllers/datadogagent/common"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component/objects"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
featutils "github.com/DataDog/datadog-operator/controllers/datadogagent/feature/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/merger"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object/volume"
cilium "github.com/DataDog/datadog-operator/pkg/cilium/v1"
Expand All @@ -38,6 +39,10 @@ func init() {
func buildAPMFeature(options *feature.Options) feature.Feature {
apmFeat := &apmFeature{}

if options != nil {
apmFeat.processCheckRunsInCoreAgent = options.ProcessChecksInCoreAgentEnabled
}

return apmFeat
}

Expand All @@ -60,6 +65,8 @@ type apmFeature struct {
createCiliumNetworkPolicy bool

singleStepInstrumentation *instrumentationConfig

processCheckRunsInCoreAgent bool
}

type instrumentationConfig struct {
Expand Down Expand Up @@ -151,7 +158,8 @@ func (f *apmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ
}
}

if f.shouldEnableLanguageDetection() {
f.processCheckRunsInCoreAgent = featutils.OverrideRunInCoreAgent(dda, f.processCheckRunsInCoreAgent)
if f.shouldEnableLanguageDetection() && !f.processCheckRunsInCoreAgent {
reqComp.Agent.Containers = append(reqComp.Agent.Containers, apicommonv1.ProcessAgentContainerName)
}
}
Expand Down Expand Up @@ -370,6 +378,14 @@ func (f *apmFeature) manageNodeAgent(agentContainerName apicommonv1.AgentContain
Name: apicommon.DDLanguageDetectionEnabled,
Value: "true",
})

// Always add this envvar to Core and Process containers
runInCoreAgentEnvVar := &corev1.EnvVar{
Name: apicommon.DDProcessConfigRunInCoreAgent,
Value: apiutils.BoolToString(&f.processCheckRunsInCoreAgent),
}
managers.EnvVar().AddEnvVarToContainer(apicommonv1.ProcessAgentContainerName, runInCoreAgentEnvVar)
managers.EnvVar().AddEnvVarToContainer(apicommonv1.CoreAgentContainerName, runInCoreAgentEnvVar)
}

// uds
Expand Down
48 changes: 41 additions & 7 deletions controllers/datadogagent/feature/apm/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
v2alpha1test "github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1/test"
"github.com/DataDog/datadog-operator/apis/utils"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/dependencies"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
Expand Down Expand Up @@ -311,7 +312,7 @@ func TestAPMFeature(t *testing.T) {
WantConfigure: true,
FeatureOptions: &feature.Options{ProcessChecksInCoreAgentEnabled: false},
ClusterAgent: testAPMInstrumentationWithLanguageDetectionEnabledForClusterAgent(),
Agent: testAPMInstrumentationWithLanguageDetectionForNodeAgent(true),
Agent: testAPMInstrumentationWithLanguageDetectionForNodeAgent(true, false),
WantDependenciesFunc: func(t testing.TB, store dependencies.StoreClient) {
_, found := store.Get(kubernetes.ClusterRoleBindingKind, "", "-apm-cluster-agent")
if !found {
Expand All @@ -330,14 +331,41 @@ func TestAPMFeature(t *testing.T) {
Build(),
WantConfigure: true,
ClusterAgent: testAPMInstrumentation(),
Agent: testAPMInstrumentationWithLanguageDetectionForNodeAgent(false),
Agent: testAPMInstrumentationWithLanguageDetectionForNodeAgent(false, false),
WantDependenciesFunc: func(t testing.TB, store dependencies.StoreClient) {
_, found := store.Get(kubernetes.ClusterRoleBindingKind, "", "-apm-cluster-agent")
if found {
t.Error("Should not have created RBAC for language detection")
}
},
},
{
Name: "single step instrumentation with language detection enabled, process check runs in core agent",
DDA: v2alpha1test.NewDatadogAgentBuilder().
WithAPMEnabled(true).
WithAPMHostPortEnabled(true, apiutils.NewInt32Pointer(8126)).
WithAPMUDSEnabled(true, apmSocketHostPath).
WithAPMSingleStepInstrumentationEnabled(true, nil, nil, nil, true).
WithAdmissionControllerEnabled(true).
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "true"}},
},
).
Build(),
WantConfigure: true,
FeatureOptions: &feature.Options{ProcessChecksInCoreAgentEnabled: true},
ClusterAgent: testAPMInstrumentationWithLanguageDetectionEnabledForClusterAgent(),
Agent: testAPMInstrumentationWithLanguageDetectionForNodeAgent(true, true),
WantDependenciesFunc: func(t testing.TB, store dependencies.StoreClient) {
_, found := store.Get(kubernetes.ClusterRoleBindingKind, "", "-apm-cluster-agent")
if !found {
t.Error("Should have created proper RBAC for language detection")
}
},
},
}

tests.Run(t, buildAPMFeature)
Expand Down Expand Up @@ -613,7 +641,7 @@ func testAPMInstrumentationWithLanguageDetectionEnabledForClusterAgent() *test.C
)
}

func testAPMInstrumentationWithLanguageDetectionForNodeAgent(languageDetectionEnabled bool) *test.ComponentTest {
func testAPMInstrumentationWithLanguageDetectionForNodeAgent(languageDetectionEnabled bool, processChecksInCoreAgent bool) *test.ComponentTest {
return test.NewDefaultComponentTest().WithWantFunc(
func(t testing.TB, mgrInterface feature.PodTemplateManagers) {
mgr := mgrInterface.(*fake.PodTemplateManagers)
Expand All @@ -623,10 +651,16 @@ func testAPMInstrumentationWithLanguageDetectionForNodeAgent(languageDetectionEn

var expectedEnvVars []*corev1.EnvVar
if languageDetectionEnabled {
expectedEnvVars = []*corev1.EnvVar{{
Name: apicommon.DDLanguageDetectionEnabled,
Value: "true",
}}
expectedEnvVars = []*corev1.EnvVar{
{
Name: apicommon.DDLanguageDetectionEnabled,
Value: "true",
},
{
Name: apicommon.DDProcessConfigRunInCoreAgent,
Value: utils.BoolToString(&processChecksInCoreAgent),
},
}
}

// Assert Env Vars Added to Core Agent Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestLiveContainerFeature(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "true"}},
},
).
Expand All @@ -64,7 +64,7 @@ func TestLiveContainerFeature(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
},
).
Build(),
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestLiveContainerFeature(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "false"}},
},
).
Expand Down
6 changes: 3 additions & 3 deletions controllers/datadogagent/feature/liveprocess/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "true"}},
},
).
Expand All @@ -71,7 +71,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
},
).
Build(),
Expand Down Expand Up @@ -101,7 +101,7 @@ func Test_liveProcessFeature_Configure(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "false"}},
},
).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "true"}},
},
).
Expand All @@ -64,7 +64,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
},
).
Build(),
Expand Down Expand Up @@ -94,7 +94,7 @@ func Test_processDiscoveryFeature_Configure(t *testing.T) {
WithComponentOverride(
v2alpha1.NodeAgentComponentName,
v2alpha1.DatadogAgentComponentOverride{
Image: &apicommonv1.AgentImageConfig{Tag: "7.53.0"},
Image: &apicommonv1.AgentImageConfig{Tag: "7.57.0"},
Env: []corev1.EnvVar{{Name: "DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED", Value: "false"}},
},
).
Expand Down
2 changes: 1 addition & 1 deletion controllers/datadogagent/feature/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// Process Checks utils

const RunInCoreAgentMinVersion = "7.53.0-0"
const RunInCoreAgentMinVersion = "7.57.0-0"

func agentSupportsRunInCoreAgent(dda *v2alpha1.DatadogAgent) bool {
// Agent version must >= 7.53.0 to run feature in core agent
Expand Down

0 comments on commit dd7bff3

Please sign in to comment.