Skip to content

Commit 74ac029

Browse files
chore(ssi): add e2e tests
This commit adds several e2e tests for SSI. These tests focus on configuration options for SSI and how they impact mutation.
1 parent d0fa856 commit 74ac029

File tree

12 files changed

+449
-0
lines changed

12 files changed

+449
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@
777777
/test/new-e2e/tests/windows @DataDog/windows-products @DataDog/windows-products
778778
/test/new-e2e/tests/apm @DataDog/agent-apm
779779
/test/new-e2e/tests/remote-config @DataDog/remote-config
780+
/test/new-e2e/tests/ssi @DataDog/injection-platform
780781
/test/new-e2e/tests/fleet @DataDog/fleet @DataDog/windows-products
781782
/test/new-e2e/tests/installer @DataDog/fleet @DataDog/windows-products
782783
/test/new-e2e/tests/installer/script @DataDog/fleet @DataDog/data-jobs-monitoring

.gitlab-ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,22 @@ workflow:
968968
compare_to: $COMPARE_TO_BRANCH
969969
when: on_success
970970

971+
.on_ssi_or_e2e_changes:
972+
- !reference [.on_e2e_main_release_or_rc]
973+
- changes:
974+
paths:
975+
- pkg/clusteragent/admission/mutate/autoinstrumentation/**/*
976+
- pkg/clusteragent/admission/mutate/common/**/*
977+
- pkg/clusteragent/admission/mutate/config/**/*
978+
- pkg/clusteragent/admission/mutate/tagsfromlabels/**/*
979+
- pkg/clusteragent/admission/common/**/*
980+
- pkg/clusteragent/admission/controllers/webhook/**/*
981+
- comp/core/workloadmeta/collectors/internal/kubeapiserver/**/*
982+
- comp/languagedetection/**/*
983+
- test/new-e2e/tests/ssi/**/*
984+
compare_to: $COMPARE_TO_BRANCH
985+
when: on_success
986+
971987
.on_windows_service_or_e2e_changes:
972988
- !reference [.on_e2e_main_release_or_rc]
973989
- changes:

.gitlab/e2e/e2e.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,20 @@ new-e2e-otel:
956956
TEAM: otel
957957
ON_NIGHTLY_FIPS: "true"
958958

959+
new-e2e-ssi:
960+
extends: .new_e2e_template
961+
rules:
962+
- !reference [.on_ssi_or_e2e_changes]
963+
- !reference [.manual]
964+
needs:
965+
- !reference [.needs_new_e2e_template]
966+
- qa_dca
967+
- qa_agent
968+
- qa_agent_full
969+
variables:
970+
TARGETS: ./tests/ssi
971+
TEAM: injection-platform
972+
959973
.new-e2e_package_signing:
960974
variables:
961975
TARGETS: ./tests/agent-platform/package-signing

test/new-e2e/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ require (
226226
github.com/DataDog/datadog-agent/comp/otelcol/ddflareextension/types v0.64.0
227227
github.com/DataDog/datadog-agent/pkg/metrics v0.64.0
228228
github.com/DataDog/datadog-agent/pkg/networkpath/payload v0.0.0-20250128160050-7ac9ccd58c07
229+
github.com/DataDog/datadog-agent/pkg/ssi/testutils v0.0.0-00010101000000-000000000000
229230
github.com/DataDog/datadog-agent/pkg/trace v0.71.0
230231
github.com/DataDog/datadog-go/v5 v5.8.1
231232
github.com/DataDog/dd-trace-go/v2 v2.4.1

test/new-e2e/tests/ssi/doc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
// Package ssi provides end to end tests for Single Step Instrumentation. It focuses on user configuration and how that
7+
// impacts targeting in Kubernetes.
8+
package ssi
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
package ssi
6+
7+
import (
8+
"os"
9+
"testing"
10+
"time"
11+
12+
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
13+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
14+
"github.com/stretchr/testify/require"
15+
16+
"github.com/DataDog/datadog-agent/pkg/ssi/testutils"
17+
"github.com/DataDog/datadog-agent/test/e2e-framework/common/config"
18+
"github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/apps/singlestep"
19+
"github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/kubernetesagentparams"
20+
compkube "github.com/DataDog/datadog-agent/test/e2e-framework/components/kubernetes"
21+
"github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/kindvm"
22+
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/e2e"
23+
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments"
24+
provkindvm "github.com/DataDog/datadog-agent/test/e2e-framework/testing/provisioners/aws/kubernetes/kindvm"
25+
)
26+
27+
type localSDKInjectionSuite struct {
28+
e2e.BaseSuite[environments.Kubernetes]
29+
}
30+
31+
func TestLocalSDKInjectionSuite(t *testing.T) {
32+
helmValues, err := os.ReadFile("testdata/local_sdk_injection.yaml")
33+
require.NoError(t, err, "Could not open helm values file for test")
34+
e2e.Run(t, &localSDKInjectionSuite{}, e2e.WithProvisioner(provkindvm.Provisioner(
35+
provkindvm.WithRunOptions(
36+
kindvm.WithAgentDependentWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider, dependsOnAgent pulumi.ResourceOption) (*compkube.Workload, error) {
37+
return singlestep.Scenario(e, kubeProvider, "workload-selection", []singlestep.Namespace{
38+
{
39+
Name: "application",
40+
Apps: []singlestep.App{
41+
{
42+
Name: DefaultAppName,
43+
Image: "registry.ddbuild.io/ci/injector-dev/python",
44+
Version: "2cd78ded",
45+
Port: 8080,
46+
PodLabels: map[string]string{
47+
"admission.datadoghq.com/enabled": "true",
48+
},
49+
PodAnnotations: map[string]string{
50+
"dmission.datadoghq.com/python-lib.version": "v3.18.1",
51+
},
52+
},
53+
{
54+
Name: "expect-no-injection",
55+
Image: "registry.ddbuild.io/ci/injector-dev/python",
56+
Version: "2cd78ded",
57+
Port: 8080,
58+
},
59+
},
60+
},
61+
}, dependsOnAgent)
62+
}),
63+
kindvm.WithAgentOptions(kubernetesagentparams.WithHelmValues(string(helmValues))),
64+
),
65+
)))
66+
}
67+
68+
func (v *localSDKInjectionSuite) TestClusterAgentInstalled() {
69+
FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "datadog", "cluster-agent")
70+
}
71+
72+
func (v *localSDKInjectionSuite) TestExpectInjection() {
73+
// Get clients.
74+
intake := v.Env().FakeIntake.Client()
75+
k8s := v.Env().KubernetesCluster.Client()
76+
77+
// Ensure the pod was injected.
78+
pod := FindPodInNamespace(v.T(), k8s, "application", DefaultAppName)
79+
podValidator := testutils.NewPodValidator(pod)
80+
podValidator.RequireInjection(v.T(), DefaultExpectedContainers)
81+
podValidator.RequireLibraryVersions(v.T(), map[string]string{
82+
"python": "v3.18.1",
83+
})
84+
podValidator.RequireInjectorVersion(v.T(), "0.52.0")
85+
86+
// Ensure the service has traces.
87+
require.Eventually(v.T(), func() bool {
88+
traces := FindTracesForService(v.T(), intake, DefaultAppName)
89+
return len(traces) != 0
90+
}, 1*time.Minute, 10*time.Second, "did not find any traces at intake for DD_SERVICE %s", DefaultAppName)
91+
}
92+
93+
func (v *localSDKInjectionSuite) TestExpectNoInjection() {
94+
pod := FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "application", "expect-no-injection")
95+
podValidator := testutils.NewPodValidator(pod)
96+
podValidator.RequireNoInjection(v.T())
97+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
package ssi
7+
8+
import (
9+
"os"
10+
"testing"
11+
"time"
12+
13+
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes"
14+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
15+
"github.com/stretchr/testify/require"
16+
17+
"github.com/DataDog/datadog-agent/pkg/ssi/testutils"
18+
"github.com/DataDog/datadog-agent/test/e2e-framework/common/config"
19+
"github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/apps/singlestep"
20+
"github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/kubernetesagentparams"
21+
compkube "github.com/DataDog/datadog-agent/test/e2e-framework/components/kubernetes"
22+
"github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/kindvm"
23+
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/e2e"
24+
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments"
25+
provkindvm "github.com/DataDog/datadog-agent/test/e2e-framework/testing/provisioners/aws/kubernetes/kindvm"
26+
)
27+
28+
type namespaceSelectionSuite struct {
29+
e2e.BaseSuite[environments.Kubernetes]
30+
}
31+
32+
func TestNamespaceSelectionSuite(t *testing.T) {
33+
helmValues, err := os.ReadFile("testdata/namespace_selection.yaml")
34+
require.NoError(t, err, "Could not open helm values file for test")
35+
e2e.Run(t, &namespaceSelectionSuite{}, e2e.WithProvisioner(provkindvm.Provisioner(
36+
provkindvm.WithRunOptions(
37+
kindvm.WithAgentDependentWorkloadApp(func(e config.Env, kubeProvider *kubernetes.Provider, dependsOnAgent pulumi.ResourceOption) (*compkube.Workload, error) {
38+
return singlestep.Scenario(e, kubeProvider, "workload-selection", []singlestep.Namespace{
39+
{
40+
Name: "expect-injection",
41+
Apps: []singlestep.App{
42+
{
43+
Name: DefaultAppName,
44+
Image: "registry.ddbuild.io/ci/injector-dev/python",
45+
Version: "2cd78ded",
46+
Port: 8080,
47+
},
48+
},
49+
},
50+
{
51+
Name: "expect-no-injection",
52+
Apps: []singlestep.App{
53+
{
54+
Name: DefaultAppName,
55+
Image: "registry.ddbuild.io/ci/injector-dev/python",
56+
Version: "2cd78ded",
57+
Port: 8080,
58+
},
59+
},
60+
},
61+
}, dependsOnAgent)
62+
}),
63+
kindvm.WithAgentOptions(kubernetesagentparams.WithHelmValues(string(helmValues))),
64+
),
65+
)))
66+
}
67+
68+
func (v *namespaceSelectionSuite) TestClusterAgentInstalled() {
69+
FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "datadog", "cluster-agent")
70+
}
71+
72+
func (v *namespaceSelectionSuite) TestExpectInjection() {
73+
// Get clients.
74+
intake := v.Env().FakeIntake.Client()
75+
k8s := v.Env().KubernetesCluster.Client()
76+
77+
// Ensure the pod was injected.
78+
pod := FindPodInNamespace(v.T(), k8s, "expect-injection", DefaultAppName)
79+
podValidator := testutils.NewPodValidator(pod)
80+
podValidator.RequireInjection(v.T(), DefaultExpectedContainers)
81+
podValidator.RequireLibraryVersions(v.T(), map[string]string{
82+
"python": "v3.18.1",
83+
})
84+
podValidator.RequireInjectorVersion(v.T(), "0.52.0")
85+
86+
// Ensure the service has traces.
87+
require.Eventually(v.T(), func() bool {
88+
traces := FindTracesForService(v.T(), intake, DefaultAppName)
89+
return len(traces) != 0
90+
}, 1*time.Minute, 10*time.Second, "did not find any traces at intake for DD_SERVICE %s", DefaultAppName)
91+
}
92+
93+
func (v *namespaceSelectionSuite) TestExpectNoInjection() {
94+
pods := GetPodsInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "expect-no-injection")
95+
for _, pod := range pods {
96+
podValidator := testutils.NewPodValidator(&pod)
97+
podValidator.RequireNoInjection(v.T())
98+
}
99+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
clusterAgent:
3+
admissionController:
4+
configMode: "hostip"
5+
datadog:
6+
apm:
7+
instrumentation:
8+
enabled: false
9+
enabledNamespaces: []
10+
injector:
11+
imageTag: "0.52.0"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
clusterAgent:
3+
admissionController:
4+
configMode: "hostip"
5+
datadog:
6+
apm:
7+
instrumentation:
8+
enabled: true
9+
injector:
10+
imageTag: "0.52.0"
11+
enabledNamespaces:
12+
- "expect-injection"
13+
libVersions:
14+
python: "v3.18.1"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
clusterAgent:
3+
admissionController:
4+
configMode: "hostip"
5+
datadog:
6+
apm:
7+
instrumentation:
8+
enabled: true
9+
injector:
10+
imageTag: "0.52.0"
11+
enabledNamespaces: []
12+
targets:
13+
- name: "python-apps"
14+
podSelector:
15+
matchLabels:
16+
language: "python"
17+
namespaceSelector:
18+
matchLabels:
19+
injection: "yes"
20+
ddTraceVersions:
21+
python: "v3.18.1"
22+
ddTraceConfigs:
23+
- name: "DD_PROFILING_ENABLED"
24+
value: "true"

0 commit comments

Comments
 (0)