Skip to content

Commit

Permalink
[Onboarding telemetry] Set install id, install time and install type …
Browse files Browse the repository at this point in the history
…env variables (#1034)

* [Onboarding telemetry] Set install id, install time and install type env variables

* Add APM prefix to env variables
  • Loading branch information
liliyadd authored Jan 9, 2024
1 parent a1cadfe commit cd7b487
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apis/datadoghq/common/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (
DDAdmissionControllerWebhookName = "DD_ADMISSION_CONTROLLER_WEBHOOK_NAME"
DDAPIKey = "DD_API_KEY"
DDAPMEnabled = "DD_APM_ENABLED"
DDAPMInstrumentationInstallTime = "DD_INSTRUMENTATION_INSTALL_TIME"
DDAPMInstrumentationInstallId = "DD_INSTRUMENTATION_INSTALL_ID"
DDAPMInstrumentationInstallType = "DD_INSTRUMENTATION_INSTALL_TYPE"
DDAPMNonLocalTraffic = "DD_APM_NON_LOCAL_TRAFFIC"
DDAPMReceiverPort = "DD_APM_RECEIVER_PORT"
DDAPMReceiverSocket = "DD_APM_RECEIVER_SOCKET"
Expand Down
15 changes: 15 additions & 0 deletions apis/datadoghq/v1alpha1/test/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
datadoghqv1alpha1 "github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/pkg/controller/utils/comparison"
"github.com/DataDog/datadog-operator/pkg/defaulting"

Expand Down Expand Up @@ -306,6 +307,20 @@ func NewDefaultedDatadogAgent(ns, name string, options *NewDatadogAgentOptions)

if options.APMEnabled {
ad.Spec.Agent.Apm.Enabled = apiutils.NewBoolPointer(true)
ad.Spec.Agent.Apm.Env = []corev1.EnvVar{
{
Name: apicommon.DDAPMInstrumentationInstallId,
Value: component.AgentInstallId,
},
{
Name: apicommon.DDAPMInstrumentationInstallTime,
Value: component.AgentInstallTime,
},
{
Name: apicommon.DDAPMInstrumentationInstallType,
Value: component.DefaultAgentInstallType,
},
}
}

if options.ProcessEnabled {
Expand Down
13 changes: 13 additions & 0 deletions controllers/datadogagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
datadoghqv1alpha1 "github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1"
test "github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1/test"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component/agent"
"github.com/DataDog/datadog-operator/controllers/datadogagent/orchestrator"
"github.com/DataDog/datadog-operator/pkg/defaulting"
Expand Down Expand Up @@ -941,6 +942,18 @@ func defaultAPMContainerEnvVars() []corev1.EnvVar {
Name: apicommon.DDAuthTokenFilePath,
Value: "/etc/datadog-agent/auth/token",
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TIME",
Value: component.AgentInstallTime,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TYPE",
Value: component.DefaultAgentInstallType,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_ID",
Value: component.AgentInstallId,
},
}
}

Expand Down
13 changes: 13 additions & 0 deletions controllers/datadogagent/clusteragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
datadoghqv1alpha1 "github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1/test"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/controllers/datadogagent/orchestrator"
"github.com/DataDog/datadog-operator/pkg/defaulting"
"github.com/DataDog/datadog-operator/pkg/testutils"
Expand Down Expand Up @@ -205,6 +206,18 @@ func clusterAgentDefaultEnvVars() []corev1.EnvVar {
Name: "DD_KUBE_RESOURCES_NAMESPACE",
Value: testDdaNamespace,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TIME",
Value: component.AgentInstallTime,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TYPE",
Value: component.DefaultAgentInstallType,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_ID",
Value: component.AgentInstallId,
},
}
}

Expand Down
21 changes: 20 additions & 1 deletion controllers/datadogagent/component/agent/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func traceAgentContainer(dda metav1.Object) corev1.Container {
"trace-agent",
fmt.Sprintf("--config=%s", apicommon.AgentCustomConfigVolumePath),
},
Env: commonEnvVars(dda),
Env: envVarsForTraceAgent(dda),
VolumeMounts: volumeMountsForTraceAgent(),
LivenessProbe: apicommon.GetDefaultTraceAgentProbe(),
}
Expand Down Expand Up @@ -307,6 +307,25 @@ func envVarsForCoreAgent(dda metav1.Object) []corev1.EnvVar {
return append(envs, commonEnvVars(dda)...)
}

func envVarsForTraceAgent(dda metav1.Object) []corev1.EnvVar {
envs := []corev1.EnvVar{
{
Name: apicommon.DDAPMInstrumentationInstallId,
Value: component.AgentInstallId,
},
{
Name: apicommon.DDAPMInstrumentationInstallTime,
Value: component.AgentInstallTime,
},
{
Name: apicommon.DDAPMInstrumentationInstallType,
Value: component.DefaultAgentInstallType,
},
}

return append(envs, commonEnvVars(dda)...)
}

func envVarsForSecurityAgent(dda metav1.Object) []corev1.EnvVar {
envs := []corev1.EnvVar{
{
Expand Down
13 changes: 13 additions & 0 deletions controllers/datadogagent/component/clusteragent/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"

"github.com/DataDog/datadog-operator/controllers/datadogagent/common"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/pkg/controller/utils"
Expand Down Expand Up @@ -144,6 +145,18 @@ func defaultEnvVars(dda metav1.Object) []corev1.EnvVar {
Name: apicommon.DDHealthPort,
Value: strconv.Itoa(int(apicommon.DefaultAgentHealthPort)),
},
{
Name: apicommon.DDAPMInstrumentationInstallId,
Value: component.AgentInstallId,
},
{
Name: apicommon.DDAPMInstrumentationInstallTime,
Value: component.AgentInstallTime,
},
{
Name: apicommon.DDAPMInstrumentationInstallType,
Value: component.DefaultAgentInstallType,
},
}

return envVars
Expand Down
12 changes: 12 additions & 0 deletions controllers/datadogagent/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import (
"fmt"
"strconv"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/version"

"github.com/google/uuid"

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
Expand All @@ -27,6 +30,15 @@ import (

const (
localServiceDefaultMinimumVersion = "1.22-0"

DefaultAgentInstallType = "k8s_manual"
)

var (
// AgentInstallTime records the Agent install time
AgentInstallTime = strconv.FormatInt(time.Now().Unix(), 10)

AgentInstallId = uuid.NewString()
)

// GetVolumeForConfig return the volume that contains the agent config
Expand Down

0 comments on commit cd7b487

Please sign in to comment.