Skip to content

Commit

Permalink
feat(origin detection): make unified setting as default and implement…
Browse files Browse the repository at this point in the history
… external-data E2E test

Signed-off-by: Wassim DHIF <[email protected]>
  • Loading branch information
wdhif committed Nov 13, 2024
1 parent 288e284 commit a6e0444
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/datadog/agent/kubernetes_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func buildLinuxHelmValues(baseName, agentImagePath, agentImageTag, clusterAgentI
"namespaceLabelsAsTags": pulumi.Map{
"related_team": pulumi.String("team"),
},
"originDetectionUnified": pulumi.Map{
"enabled": pulumi.Bool(true),
},
"namespaceAnnotationsAsTags": pulumi.Map{
"related_email": pulumi.String("email"), // should be overridden by kubernetesResourcesAnnotationsAsTags
},
Expand Down
25 changes: 25 additions & 0 deletions components/datadog/apps/dogstatsd/images/dogstatsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"math"
"net"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -48,6 +49,30 @@ func main() {
nbSeries := flag.Uint("nb-series", 10, "Number of time series to emit")
flag.Parse()

// To test only the external data, we can set the DD_EXTERNAL_DATA_ONLY environment variable to true.
// Instead of using the DogStatsD client, we will send data directly to the agent.
// We need to do this as is it not possible to disable local data in the DogStatsD client.
if v, ok := os.LookupEnv("DD_EXTERNAL_DATA_ONLY"); ok && v == "true" {
conn, err := net.Dial("udp", os.Getenv("STATSD_URL"))
if err != nil {
log.Fatal(err)
return
}
defer conn.Close()

for {
for i := uint(0); i < *nbSeries; i++ {
value := math.Sin(2 * math.Pi * (float64(time.Now().Unix())/period.Seconds() + float64(i)/float64(*nbSeries)))
_, err = conn.Write([]byte(fmt.Sprintf("custom.metric:%f|g|e:%s|series:%d", value, os.Getenv("DD_EXTERNAL_ENV"), i)))
if err != nil {
log.Fatal(err)
return
}
time.Sleep(1 * time.Second)
}
}
}

c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGUSR1, syscall.SIGUSR2)

Expand Down
72 changes: 72 additions & 0 deletions components/datadog/apps/dogstatsd/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,77 @@ func K8sAppDefinition(e config.Env, kubeProvider *kubernetes.Provider, namespace
return nil, err
}

if _, err := appsv1.NewDeployment(e.Ctx(), fmt.Sprintf("dogstatsd-udp-external-data-only-%d", statsdPort), &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("dogstatsd-udp-external-data-only"),
Namespace: pulumi.String(namespace),
Labels: pulumi.StringMap{
"app": pulumi.String("dogstatsd-udp-external-data-only"),
},
},
Spec: &appsv1.DeploymentSpecArgs{
Replicas: pulumi.Int(1),
Selector: &metav1.LabelSelectorArgs{
MatchLabels: pulumi.StringMap{
"app": pulumi.String("dogstatsd-udp-external-data-only"),
},
},
Template: &corev1.PodTemplateSpecArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: pulumi.StringMap{
"app": pulumi.String("dogstatsd-udp-external-data-only"),
"admission.datadoghq.com/enabled": pulumi.String("true"),
},
},
Spec: &corev1.PodSpecArgs{
Containers: corev1.ContainerArray{
&corev1.ContainerArgs{
Name: pulumi.String("dogstatsd"),
Image: pulumi.String("ghcr.io/datadog/apps-dogstatsd:main"),
Env: &corev1.EnvVarArray{
&corev1.EnvVarArgs{
Name: pulumi.String("HOST_IP"),
ValueFrom: &corev1.EnvVarSourceArgs{
FieldRef: &corev1.ObjectFieldSelectorArgs{
FieldPath: pulumi.String("status.hostIP"),
},
},
},
&corev1.EnvVarArgs{
Name: pulumi.String("STATSD_URL"),
Value: pulumi.Sprintf("$(HOST_IP):%d", statsdPort),
},
&corev1.EnvVarArgs{
Name: pulumi.String("DD_ENTITY_ID"),
ValueFrom: &corev1.EnvVarSourceArgs{
FieldRef: &corev1.ObjectFieldSelectorArgs{
FieldPath: pulumi.String("metadata.uid"),
},
},
},
&corev1.EnvVarArgs{
Name: pulumi.String("DD_EXTERNAL_DATA_ONLY"),
Value: pulumi.String("true"),
},
},
Resources: &corev1.ResourceRequirementsArgs{
Limits: pulumi.StringMap{
"cpu": pulumi.String("10m"),
"memory": pulumi.String("32Mi"),
},
Requests: pulumi.StringMap{
"cpu": pulumi.String("2m"),
"memory": pulumi.String("32Mi"),
},
},
},
},
},
},
},
}, opts...); err != nil {
return nil, err
}

return k8sComponent, nil
}

0 comments on commit a6e0444

Please sign in to comment.