Skip to content

Commit

Permalink
chore(origin detection): add External Data E2E test
Browse files Browse the repository at this point in the history
Signed-off-by: Wassim DHIF <[email protected]>
  • Loading branch information
wdhif committed Nov 22, 2024
1 parent c33fab7 commit 646bcca
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/new-e2e/tests/containers/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
kubeNamespaceDogstatsStandaloneWorkload = "workload-dogstatsd-standalone"
kubeNamespaceTracegenWorkload = "workload-tracegen"
kubeDeploymentDogstatsdUDPOrigin = "dogstatsd-udp-origin-detection"
kubeDeploymentDogstatsdUDPExternalData = "dogstatsd-udp-external-data-only"
kubeDeploymentDogstatsdUDS = "dogstatsd-uds"
kubeDeploymentTracegenTCPWorkload = "tracegen-tcp"
kubeDeploymentTracegenUDSWorkload = "tracegen-uds"
Expand Down Expand Up @@ -800,6 +801,8 @@ func (suite *k8sSuite) TestDogstatsdInAgent() {
suite.testDogstatsdContainerID(kubeNamespaceDogstatsWorkload, kubeDeploymentDogstatsdUDPOrigin)
// Test with UDP + DD_ENTITY_ID
suite.testDogstatsdPodUID(kubeNamespaceDogstatsWorkload)
// Test with UDP + External Data
suite.testDogstatsdExternalData(kubeNamespaceDogstatsWorkload, kubeDeploymentDogstatsdUDPExternalData)
}

func (suite *k8sSuite) TestDogstatsdStandalone() {
Expand Down Expand Up @@ -836,6 +839,78 @@ func (suite *k8sSuite) testDogstatsdPodUID(kubeNamespace string) {
})
}

// testDogstatsdExternalData tests that the External Data origin resolution works for the dogstatsd.
func (suite *k8sSuite) testDogstatsdExternalData(kubeNamespace, kubeDeployment string) {
ctx := context.Background()

// Record old pod, so we can be sure we are not looking at the incorrect one after deletion
oldPods, err := suite.K8sClient.CoreV1().Pods(kubeNamespace).List(ctx, metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", kubeDeployment).String(),
})
suite.Require().NoError(err)
suite.Require().Len(oldPods.Items, 1)
oldPod := oldPods.Items[0]

// Delete the pod to ensure it is recreated after the admission controller is deployed
err = suite.K8sClient.CoreV1().Pods(kubeNamespace).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", kubeDeployment).String(),
})
suite.Require().NoError(err)

// Wait for the fresh pod to be created
var pod corev1.Pod
suite.Require().EventuallyWithTf(func(c *assert.CollectT) {
pods, err := suite.K8sClient.CoreV1().Pods(kubeNamespace).List(ctx, metav1.ListOptions{
LabelSelector: fields.OneTermEqualSelector("app", kubeDeployment).String(),
})
if !assert.NoError(c, err) {
return
}
if !assert.Len(c, pods.Items, 1) {
return
}
pod = pods.Items[0]
if !assert.NotEqual(c, oldPod.Name, pod.Name) {
return
}
}, 2*time.Minute, 10*time.Second, "Failed to witness the creation of pod with name %s in namespace %s", kubeDeployment, kubeNamespace)

suite.Require().Len(pod.Spec.Containers, 1)

suite.testMetric(&testMetricArgs{
Filter: testMetricFilterArgs{
Name: "custom.metric",
Tags: []string{
"^kube_deployment:" + regexp.QuoteMeta(kubeDeployment) + "$",
"^kube_namespace:" + regexp.QuoteMeta(kubeNamespace) + "$",
},
},
Expect: testMetricExpectArgs{
Tags: &[]string{
`^container_id:`,
`^container_name:dogstatsd$`,
`^display_container_name:dogstatsd`,
`^git.commit.sha:`, // org.opencontainers.image.revision docker image label
`^git.repository_url:https://github.com/DataDog/test-infra-definitions$`, // org.opencontainers.image.source docker image label
`^image_id:ghcr.io/datadog/apps-dogstatsd@sha256:`,
`^image_name:ghcr.io/datadog/apps-dogstatsd$`,
`^image_tag:main$`,
`^kube_container_name:dogstatsd$`,
`^kube_deployment:` + regexp.QuoteMeta(kubeDeployment) + `$`,
"^kube_namespace:" + regexp.QuoteMeta(kubeNamespace) + "$",
`^kube_ownerref_kind:replicaset$`,
`^kube_ownerref_name:` + regexp.QuoteMeta(kubeDeployment) + `-[[:alnum:]]+$`,
`^kube_qos:Burstable$`,
`^kube_replica_set:` + regexp.QuoteMeta(kubeDeployment) + `-[[:alnum:]]+$`,
`^pod_name:` + regexp.QuoteMeta(kubeDeployment) + `-[[:alnum:]]+-[[:alnum:]]+$`,
`^pod_phase:running$`,
`^series:`,
`^short_image:apps-dogstatsd$`,
},
},
})
}

func (suite *k8sSuite) testDogstatsdContainerID(kubeNamespace, kubeDeployment string) {
suite.testMetric(&testMetricArgs{
Filter: testMetricFilterArgs{
Expand Down

0 comments on commit 646bcca

Please sign in to comment.