From b5860a57c397eb626b5176abc714fbe17abcea17 Mon Sep 17 00:00:00 2001 From: Stan Rozenraukh Date: Wed, 4 Dec 2024 13:23:07 -0500 Subject: [PATCH] fix lint, update call site with old fn --- .../auto_instrumentation.go | 37 +++++++++++-------- .../auto_instrumentation_test.go | 8 ++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go index e01dd05ca3891d..ff01aabef99883 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go @@ -226,6 +226,26 @@ func profilingClientLibraryConfigMutators(config *webhookConfig) []podMutator { return podMutators } +func injectApmTelemetryConfig(pod *corev1.Pod) { + // inject DD_INSTRUMENTATION_INSTALL_TIME with current Unix time + instrumentationInstallTime := os.Getenv(instrumentationInstallTimeEnvVarName) + if instrumentationInstallTime == "" { + instrumentationInstallTime = common.ClusterAgentStartTime + } + instrumentationInstallTimeEnvVar := corev1.EnvVar{ + Name: instrumentationInstallTimeEnvVarName, + Value: instrumentationInstallTime, + } + _ = mutatecommon.InjectEnv(pod, instrumentationInstallTimeEnvVar) + + // inject DD_INSTRUMENTATION_INSTALL_ID with UUID created during the Agent install time + instrumentationInstallIDEnvVar := corev1.EnvVar{ + Name: instrumentationInstallIDEnvVarName, + Value: os.Getenv(instrumentationInstallIDEnvVarName), + } + _ = mutatecommon.InjectEnv(pod, instrumentationInstallIDEnvVar) +} + type libInfoLanguageDetection struct { libs []libInfo injectionEnabled bool @@ -343,23 +363,8 @@ func (s libInfoSource) mutatePod(pod *corev1.Pod) error { Value: s.injectionType(), }) - // inject DD_INSTRUMENTATION_INSTALL_TIME with current Unix time - instrumentationInstallTime := os.Getenv(instrumentationInstallTimeEnvVarName) - if instrumentationInstallTime == "" { - instrumentationInstallTime = common.ClusterAgentStartTime - } - instrumentationInstallTimeEnvVar := corev1.EnvVar{ - Name: instrumentationInstallTimeEnvVarName, - Value: instrumentationInstallTime, - } - _ = mutatecommon.InjectEnv(pod, instrumentationInstallTimeEnvVar) + injectApmTelemetryConfig(pod) - // inject DD_INSTRUMENTATION_INSTALL_ID with UUID created during the Agent install time - instrumentationInstallIDEnvVar := corev1.EnvVar{ - Name: instrumentationInstallIDEnvVarName, - Value: os.Getenv(instrumentationInstallIDEnvVarName), - } - _ = mutatecommon.InjectEnv(pod, instrumentationInstallIDEnvVar) return nil } diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go index dcf65c4d69d17d..97dda98d331743 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go @@ -2307,7 +2307,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { "admission.datadoghq.com/enabled": "false", }, }.Create(), - expectedEnvs: nil, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, @@ -2406,7 +2406,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { ParentKind: "replicaset", ParentName: "test-deployment-123", }.Create(), - expectedEnvs: nil, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, @@ -2477,7 +2477,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { ParentKind: "replicaset", ParentName: "test-deployment-123", }.Create(), - expectedEnvs: nil, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, @@ -2490,7 +2490,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { ParentKind: "replicaset", ParentName: "test-deployment-123", }.Create(), - expectedEnvs: nil, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false,