Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM Onboarding] Use creation timestamp and UID of DatadogAgent as env vars for APM Telemetry KPIs #1157

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions apis/datadoghq/v1alpha1/test/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ package test

import (
"fmt"
"strconv"
"time"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
Expand All @@ -20,6 +22,7 @@ import (
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/pkg/controller/utils/comparison"
"github.com/DataDog/datadog-operator/pkg/defaulting"
"github.com/google/uuid"

edsdatadoghqv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
Expand All @@ -30,6 +33,9 @@ var (
apiVersion = fmt.Sprintf("%s/%s", datadoghqv1alpha1.GroupVersion.Group, datadoghqv1alpha1.GroupVersion.Version)
pullPolicy = corev1.PullIfNotPresent
defaultImage = defaulting.GetLatestAgentImage()
// AgentInstallTime records the Agent install time
AgentInstallTime = metav1.NewTime(time.Now())
AgentInstallId = types.UID(uuid.New().String())
)

// NewDatadogAgentOptions set of option for the DatadogAgent creation
Expand Down Expand Up @@ -108,10 +114,12 @@ func NewDefaultedDatadogAgent(ns, name string, options *NewDatadogAgentOptions)
APIVersion: apiVersion,
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
Labels: map[string]string{},
Finalizers: []string{"finalizer.agent.datadoghq.com"},
Namespace: ns,
Name: name,
Labels: map[string]string{},
Finalizers: []string{"finalizer.agent.datadoghq.com"},
CreationTimestamp: AgentInstallTime,
UID: AgentInstallId,
},
}
ad.Spec = datadoghqv1alpha1.DatadogAgentSpec{
Expand Down Expand Up @@ -310,11 +318,11 @@ func NewDefaultedDatadogAgent(ns, name string, options *NewDatadogAgentOptions)
ad.Spec.Agent.Apm.Env = []corev1.EnvVar{
{
Name: apicommon.DDAPMInstrumentationInstallId,
Value: component.AgentInstallId,
Value: string(ad.GetUID()),
},
{
Name: apicommon.DDAPMInstrumentationInstallTime,
Value: component.AgentInstallTime,
Value: strconv.FormatInt(ad.GetCreationTimestamp().Unix(), 10),
},
{
Name: apicommon.DDAPMInstrumentationInstallType,
Expand Down
4 changes: 2 additions & 2 deletions controllers/datadogagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,15 +948,15 @@ func defaultAPMContainerEnvVars() []corev1.EnvVar {
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TIME",
Value: component.AgentInstallTime,
Value: strconv.FormatInt(test.AgentInstallTime.Unix(), 10),
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TYPE",
Value: component.DefaultAgentInstallType,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_ID",
Value: component.AgentInstallId,
Value: string(test.AgentInstallId),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/datadogagent/clusteragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ func clusterAgentDefaultEnvVars() []corev1.EnvVar {
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TIME",
Value: component.AgentInstallTime,
Value: strconv.FormatInt(test.AgentInstallTime.Time.Unix(), 10),
},
{
Name: "DD_INSTRUMENTATION_INSTALL_TYPE",
Value: component.DefaultAgentInstallType,
},
{
Name: "DD_INSTRUMENTATION_INSTALL_ID",
Value: component.AgentInstallId,
Value: string(test.AgentInstallId),
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/datadogagent/component/agent/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
componentdca "github.com/DataDog/datadog-operator/controllers/datadogagent/component/clusteragent"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
"github.com/DataDog/datadog-operator/pkg/controller/utils"
"github.com/DataDog/datadog-operator/pkg/defaulting"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -311,11 +312,11 @@ func envVarsForTraceAgent(dda metav1.Object) []corev1.EnvVar {
envs := []corev1.EnvVar{
{
Name: apicommon.DDAPMInstrumentationInstallId,
Value: component.AgentInstallId,
Value: utils.GetDatadogAgentResourceUID(dda),
},
{
Name: apicommon.DDAPMInstrumentationInstallTime,
Value: component.AgentInstallTime,
Value: utils.GetDatadogAgentResourceCreationTime(dda),
},
{
Name: apicommon.DDAPMInstrumentationInstallType,
Expand Down
5 changes: 2 additions & 3 deletions controllers/datadogagent/component/clusteragent/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
// NewDefaultClusterAgentDeployment return a new default cluster-agent deployment
func NewDefaultClusterAgentDeployment(dda metav1.Object) *appsv1.Deployment {
deployment := component.NewDeployment(dda, apicommon.DefaultClusterAgentResourceSuffix, GetClusterAgentName(dda), GetClusterAgentVersion(dda), nil)

podTemplate := NewDefaultClusterAgentPodTemplateSpec(dda)
for key, val := range deployment.GetLabels() {
podTemplate.Labels[key] = val
Expand Down Expand Up @@ -147,11 +146,11 @@ func defaultEnvVars(dda metav1.Object) []corev1.EnvVar {
},
{
Name: apicommon.DDAPMInstrumentationInstallId,
Value: component.AgentInstallId,
Value: utils.GetDatadogAgentResourceUID(dda),
},
{
Name: apicommon.DDAPMInstrumentationInstallTime,
Value: component.AgentInstallTime,
Value: utils.GetDatadogAgentResourceCreationTime(dda),
},
{
Name: apicommon.DDAPMInstrumentationInstallType,
Expand Down
10 changes: 0 additions & 10 deletions controllers/datadogagent/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ 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 @@ -34,13 +31,6 @@ const (
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
func GetVolumeForConfig() corev1.Volume {
return corev1.Volume{
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/utils/shared_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package utils

import (
"fmt"
"strconv"

"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand All @@ -32,3 +33,13 @@ func GetDatadogAgentResourceNamespace(dda metav1.Object) string {
func GetDatadogTokenResourceName(dda metav1.Object) string {
return fmt.Sprintf("%stoken", dda.GetName())
}

// GetDatadogAgentResourceNamespace returns the UID of the Datadog Agent Resource
func GetDatadogAgentResourceUID(dda metav1.Object) string {
return string(dda.GetUID())
}

// GetDatadogAgentResourceCreationTime returns the creation timestamp of the Datadog Agent Resource
func GetDatadogAgentResourceCreationTime(dda metav1.Object) string {
return strconv.FormatInt(dda.GetCreationTimestamp().Unix(), 10)
}
Loading