Skip to content

Commit 52f1d36

Browse files
betterengineeringmwdd146980
authored andcommitted
chore(ssi): add e2e tests (#44034)
### What does this PR do? This commit adds several e2e tests for SSI. These tests focus on configuration options for SSI and how they impact mutation. ### Motivation We have e2e test coverage through the Kubernetes tests that run on every platform: https://github.com/DataDog/datadog-agent/blob/35e4f67132c64cf58c989fe20762878efcc5ebc1/test/new-e2e/tests/containers/k8s_test.go#L1196-L1206 However, these tests don't allow us to test more advanced configuration scenarios and more nuanced assertions. We want to add dedicated SSI end to end tests that focus on user configuration. For now, these new tests will be in addtion to the existing tests that focus on basic functionality on every platform we support. See [SSI Kubernetes | Platform Stability](https://docs.google.com/document/d/1NqrPEUn3RfcdS_hQUQB-pJFJN9N-x5I202CB7s7CnwQ/edit?usp=sharing) for how this change fits into a larger initiative. ### Describe how you validated your changes The attached build. Locally, these can be run like so: ```bash inv new-e2e-tests.run --targets=./tests/ssi --run='^TestWorkloadSelectionSuite$' ``` ```bash inv new-e2e-tests.run --targets=./tests/ssi --run='^TestLocalSDKInjectionSuite$' ``` ```bash inv new-e2e-tests.run --targets=./tests/ssi --run='^TestNamespaceSelectionSuite$' ``` ### Additional Notes Every version is pinned. The injector is pinned, the python tracer is pinned, and the test app is pinned. So nothing should change outside of a commit for these tests. Co-authored-by: mark.spicer <mark.spicer@datadoghq.com>
1 parent 1d69a9d commit 52f1d36

File tree

13 files changed

+461
-6
lines changed

13 files changed

+461
-6
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@
776776
/test/new-e2e/tests/windows @DataDog/windows-products @DataDog/windows-products
777777
/test/new-e2e/tests/apm @DataDog/agent-apm
778778
/test/new-e2e/tests/remote-config @DataDog/remote-config
779+
/test/new-e2e/tests/ssi @DataDog/injection-platform
779780
/test/new-e2e/tests/fleet @DataDog/fleet @DataDog/windows-products
780781
/test/new-e2e/tests/installer @DataDog/fleet @DataDog/windows-products
781782
/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
@@ -955,6 +955,20 @@ new-e2e-otel:
955955
TEAM: otel
956956
ON_NIGHTLY_FIPS: "true"
957957

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

test/e2e-framework/scenarios/aws/kindvm/run.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func RunWithEnv(ctx *pulumi.Context, awsEnv resAws.Environment, env *environment
185185
if err != nil {
186186
return err
187187
}
188+
dependsOnDDAgent = utils.PulumiDependsOn(operatorComp)
188189
}
189190

190191
if params.deployDogstatsd {
@@ -236,12 +237,6 @@ func RunWithEnv(ctx *pulumi.Context, awsEnv resAws.Environment, env *environment
236237
if _, err := cpustress.K8sAppDefinition(&awsEnv, kubeProvider, "workload-cpustress"); err != nil {
237238
return err
238239
}
239-
for _, appFunc := range params.depWorkloadAppFuncs {
240-
_, err := appFunc(&awsEnv, kubeProvider, dependsOnDDAgent)
241-
if err != nil {
242-
return err
243-
}
244-
}
245240
}
246241

247242
if params.deployArgoRollout {
@@ -250,6 +245,16 @@ func RunWithEnv(ctx *pulumi.Context, awsEnv resAws.Environment, env *environment
250245
}
251246
}
252247
}
248+
249+
if dependsOnDDAgent != nil {
250+
for _, appFunc := range params.depWorkloadAppFuncs {
251+
_, err := appFunc(&awsEnv, kubeProvider, dependsOnDDAgent)
252+
if err != nil {
253+
return err
254+
}
255+
}
256+
}
257+
253258
for _, appFunc := range params.workloadAppFuncs {
254259
_, err := appFunc(&awsEnv, kubeProvider)
255260
if err != nil {

test/new-e2e/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ require (
220220
github.com/DataDog/datadog-agent/comp/otelcol/ddflareextension/types v0.65.0-devel
221221
github.com/DataDog/datadog-agent/pkg/metrics v0.73.0-rc.9
222222
github.com/DataDog/datadog-agent/pkg/networkpath/payload v0.0.0-20250128160050-7ac9ccd58c07
223+
github.com/DataDog/datadog-agent/pkg/ssi/testutils v0.0.0-00010101000000-000000000000
223224
github.com/DataDog/datadog-agent/pkg/trace v0.73.0-rc.9
224225
github.com/DataDog/datadog-go/v5 v5.8.2
225226
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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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, "local-sdk-injection", []singlestep.Namespace{
38+
{
39+
Name: "application",
40+
Apps: []singlestep.App{
41+
{
42+
Name: DefaultAppName,
43+
Image: "gcr.io/datadoghq/injector-dev/python",
44+
Version: "d425e7df",
45+
Port: 8080,
46+
PodLabels: map[string]string{
47+
"admission.datadoghq.com/enabled": "true",
48+
"tags.datadoghq.com/service": DefaultAppName,
49+
},
50+
PodAnnotations: map[string]string{
51+
"admission.datadoghq.com/python-lib.version": "v3.18.1",
52+
},
53+
},
54+
{
55+
Name: "expect-no-injection",
56+
Image: "gcr.io/datadoghq/injector-dev/python",
57+
Version: "d425e7df",
58+
Port: 8080,
59+
},
60+
},
61+
},
62+
}, dependsOnAgent)
63+
}),
64+
kindvm.WithAgentOptions(kubernetesagentparams.WithHelmValues(string(helmValues))),
65+
),
66+
)))
67+
}
68+
69+
func (v *localSDKInjectionSuite) TestClusterAgentInstalled() {
70+
FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "datadog", "cluster-agent")
71+
}
72+
73+
func (v *localSDKInjectionSuite) TestExpectInjection() {
74+
// Get clients.
75+
intake := v.Env().FakeIntake.Client()
76+
k8s := v.Env().KubernetesCluster.Client()
77+
78+
// Ensure the pod was injected.
79+
pod := FindPodInNamespace(v.T(), k8s, "application", DefaultAppName)
80+
podValidator := testutils.NewPodValidator(pod)
81+
podValidator.RequireInjection(v.T(), DefaultExpectedContainers)
82+
podValidator.RequireLibraryVersions(v.T(), map[string]string{
83+
"python": "v3.18.1",
84+
})
85+
podValidator.RequireInjectorVersion(v.T(), "0.52.0")
86+
87+
// Ensure the service has traces.
88+
require.Eventually(v.T(), func() bool {
89+
traces := FindTracesForService(v.T(), intake, DefaultAppName)
90+
return len(traces) != 0
91+
}, 1*time.Minute, 10*time.Second, "did not find any traces at intake for DD_SERVICE %s", DefaultAppName)
92+
}
93+
94+
func (v *localSDKInjectionSuite) TestExpectNoInjection() {
95+
pod := FindPodInNamespace(v.T(), v.Env().KubernetesCluster.Client(), "application", "expect-no-injection")
96+
podValidator := testutils.NewPodValidator(pod)
97+
podValidator.RequireNoInjection(v.T())
98+
}
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, "namespace-selection", []singlestep.Namespace{
39+
{
40+
Name: "expect-injection",
41+
Apps: []singlestep.App{
42+
{
43+
Name: DefaultAppName,
44+
Image: "gcr.io/datadoghq/injector-dev/python",
45+
Version: "d425e7df",
46+
Port: 8080,
47+
},
48+
},
49+
},
50+
{
51+
Name: "expect-no-injection",
52+
Apps: []singlestep.App{
53+
{
54+
Name: DefaultAppName,
55+
Image: "gcr.io/datadoghq/injector-dev/python",
56+
Version: "d425e7df",
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"

0 commit comments

Comments
 (0)