Skip to content

Commit 91491c2

Browse files
committed
fix(test): embed cluster-agent Helm values as testdata yaml, trim comments
1 parent 8cdd60a commit 91491c2

3 files changed

Lines changed: 39 additions & 66 deletions

File tree

test/new-e2e/tests/agent-telemetry/errortracking_cluster_agent_test.go

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package agenttelemetry
77

88
import (
99
"context"
10+
_ "embed"
1011
"fmt"
1112
"io"
1213
"strings"
@@ -32,47 +33,28 @@ import (
3233
// the datadog-agent Helm release into.
3334
const clusterAgentDatadogNamespace = "datadog"
3435

35-
// leaderElectionErrorMessage is logged by KubeASCheck.Run at ERROR level on
36-
// every check run (~15s, no rate limiter) once leader election is disabled —
37-
// a deterministic trigger for a binary that runs no Python checks.
36+
// leaderElectionErrorMessage is logged at ERROR on every check run once
37+
// leader election is disabled, a deterministic trigger for this suite.
3838
const leaderElectionErrorMessage = "Leader Election not enabled"
3939

40-
// clusterAgentErrorTrackingEnabledHelmValues disables leader election (to
41-
// generate a repeating ERROR log) and enables the errortracking pipeline
42-
// with a fast flush so the wire-shape assertions below run quickly.
43-
const clusterAgentErrorTrackingEnabledHelmValues = `
44-
datadog:
45-
leaderElection: false
46-
clusterAgent:
47-
envDict:
48-
DD_AGENT_TELEMETRY_ENABLED: "true"
49-
DD_AGENT_TELEMETRY_ERRORTRACKING_ENABLED: "true"
50-
DD_AGENT_TELEMETRY_ERRORTRACKING_FLUSH_INTERVAL_SECONDS: "1"
51-
DD_AGENT_TELEMETRY_ERRORTRACKING_BOUNCER_WINDOW_SECONDS: "0"
52-
DD_AGENT_TELEMETRY_ERRORTRACKING_STARTUP_JITTER_SECONDS: "0"
53-
`
40+
// clusterAgentErrorTrackingEnabledHelmValues disables leader election and
41+
// enables the errortracking pipeline with a fast flush.
42+
//
43+
//go:embed testdata/errortracking-cluster-agent-enabled.yaml
44+
var clusterAgentErrorTrackingEnabledHelmValues string
5445

5546
// clusterAgentErrorTrackingDisabledHelmValues mirrors the enabled config but
56-
// omits errortracking.enabled, which defaults to false, while still forcing
57-
// the leader-election error so the negative assertion is meaningful.
58-
const clusterAgentErrorTrackingDisabledHelmValues = `
59-
datadog:
60-
leaderElection: false
61-
clusterAgent:
62-
envDict:
63-
DD_AGENT_TELEMETRY_ENABLED: "true"
64-
DD_AGENT_TELEMETRY_ERRORTRACKING_FLUSH_INTERVAL_SECONDS: "1"
65-
DD_AGENT_TELEMETRY_ERRORTRACKING_BOUNCER_WINDOW_SECONDS: "0"
66-
DD_AGENT_TELEMETRY_ERRORTRACKING_STARTUP_JITTER_SECONDS: "0"
67-
`
47+
// omits errortracking.enabled, which defaults to false.
48+
//
49+
//go:embed testdata/errortracking-cluster-agent-disabled.yaml
50+
var clusterAgentErrorTrackingDisabledHelmValues string
6851

6952
type errorTrackingClusterAgentSuite struct {
7053
e2e.BaseSuite[environments.Kubernetes]
7154
}
7255

7356
// TestErrorTrackingClusterAgentSuite is the cluster-agent variant of
74-
// TestAgentTelemetryErrorTrackingSuite, exercising the same
75-
// pkg/util/log/errortracking → comp/core/agenttelemetry pipeline.
57+
// TestAgentTelemetryErrorTrackingSuite.
7658
func TestErrorTrackingClusterAgentSuite(t *testing.T) {
7759
e2e.Run(t, &errorTrackingClusterAgentSuite{},
7860
e2e.WithProvisioner(provkind.Provisioner(
@@ -86,11 +68,7 @@ func TestErrorTrackingClusterAgentSuite(t *testing.T) {
8668
}
8769

8870
// getClusterAgentPodNames returns the names of all running cluster-agent
89-
// pods. This suite's Helm deployment runs clusterAgent.replicas: 2 for HA
90-
// (see test/e2e-framework's kindvm base values), so callers must not assume
91-
// a single pod. The leader-election error asserted on below is logged by
92-
// each replica's own local corecheck runner independently of DCA-level
93-
// leader election, so any one replica emitting it is sufficient.
71+
// pods. This suite runs clusterAgent.replicas: 2, so callers must not assume a single pod.
9472
func (s *errorTrackingClusterAgentSuite) getClusterAgentPodNames() []string {
9573
t := s.T()
9674
pods, err := s.Env().KubernetesCluster.Client().CoreV1().Pods(clusterAgentDatadogNamespace).List(t.Context(), metav1.ListOptions{
@@ -106,12 +84,7 @@ func (s *errorTrackingClusterAgentSuite) getClusterAgentPodNames() []string {
10684
}
10785

10886
// getClusterAgentContainerLogs returns the "cluster-agent" container's stdout
109-
// for podName, restricted to entries logged at or after since. The Kubelet's
110-
// log endpoint filters this server-side, so unlike a PodExec'd file read there
111-
// is no local file, offset, or rolling-writer state to reconcile: cluster-agent
112-
// runs containerized (via this suite's kind provisioner) and, like every other
113-
// binary in a Helm-deployed pod, relies on the container runtime to capture its
114-
// stdout rather than writing a log file to disk.
87+
// for podName, restricted to entries logged at or after since.
11588
func (s *errorTrackingClusterAgentSuite) getClusterAgentContainerLogs(ctx context.Context, podName string, since time.Time) (string, error) {
11689
sinceTime := metav1.NewTime(since)
11790
stream, err := s.Env().KubernetesCluster.Client().CoreV1().Pods(clusterAgentDatadogNamespace).GetLogs(podName, &corev1.PodLogOptions{
@@ -127,12 +100,8 @@ func (s *errorTrackingClusterAgentSuite) getClusterAgentContainerLogs(ctx contex
127100
}
128101

129102
// TestPayloadShape verifies the cluster-agent's own leader-election-gated
130-
// ERROR log reaches FakeIntake with the expected wire shape and an
131-
// agent.flavor tag identifying the emitter as cluster_agent rather than agent.
103+
// ERROR log reaches FakeIntake with an agent.flavor tag of cluster_agent.
132104
func (s *errorTrackingClusterAgentSuite) TestPayloadShape() {
133-
// BeforeTest already reset the environment to the suite's original
134-
// (enabled) provisioner regardless of run order, and the leader-election
135-
// error recurs on every check run, so no re-provisioning is needed here.
136105
require.NoError(s.T(), s.Env().FakeIntake.Client().FlushServerAndResetAggregators())
137106

138107
var logs []*aggregator.AgentTelemetryLog
@@ -148,9 +117,8 @@ func (s *errorTrackingClusterAgentSuite) TestPayloadShape() {
148117
}
149118
}
150119

151-
// TestDisabledByDefault verifies that when the errortracking stanza omits
152-
// `enabled` (defaulting to false), no agent-logs records reach FakeIntake even
153-
// though the leader-election error keeps firing locally.
120+
// TestDisabledByDefault verifies that when errortracking omits `enabled`
121+
// (defaulting to false), no agent-logs records reach FakeIntake.
154122
func (s *errorTrackingClusterAgentSuite) TestDisabledByDefault() {
155123
s.UpdateEnv(provkind.Provisioner(
156124
provkind.WithRunOptions(
@@ -165,17 +133,8 @@ func (s *errorTrackingClusterAgentSuite) TestDisabledByDefault() {
165133
podNames := s.getClusterAgentPodNames()
166134
since := time.Now()
167135

168-
// Wait until the leader-election error appears in at least one replica's own
169-
// stdout, confirming the error is generated locally before asserting it is
170-
// not forwarded to telemetry. Only the elected DCA replica is guaranteed to
171-
// run the check that emits it, so all replicas are polled and any one of
172-
// them containing the message satisfies the wait.
173-
//
174-
// The window is generous (matching TestPayloadShape's FakeIntake wait)
175-
// because this runs right after a Helm upgrade rolls the deployment: on a
176-
// resource-constrained CI node, the new pods' corecheck scheduler can take
177-
// longer to get its first tick in than the default-check interval alone
178-
// would suggest.
136+
// Wait until the leader-election error appears in at least one replica's
137+
// stdout before asserting it is not forwarded to telemetry.
179138
ok := assert.EventuallyWithT(s.T(), func(c *assert.CollectT) {
180139
statuses := make([]string, 0, len(podNames))
181140
for _, podName := range podNames {
@@ -192,8 +151,7 @@ func (s *errorTrackingClusterAgentSuite) TestDisabledByDefault() {
192151
assert.Fail(c, "leader-election error not yet found in any cluster-agent replica's log: "+strings.Join(statuses, "; "))
193152
}, 2*time.Minute, 5*time.Second, "timed out waiting for leader-election error to appear in cluster-agent log")
194153

195-
// On failure, dump each replica's actual log tail so a re-run shows what the
196-
// check runner was doing instead of just a stale/zero count.
154+
// On failure, dump each replica's log tail for debugging.
197155
if !ok {
198156
for _, podName := range podNames {
199157
out, err := s.getClusterAgentContainerLogs(ctx, podName, since)
@@ -206,9 +164,7 @@ func (s *errorTrackingClusterAgentSuite) TestDisabledByDefault() {
206164
s.T().FailNow()
207165
}
208166

209-
// Confirm nothing is forwarded. The config sets flush_interval_seconds: 1, so
210-
// 5 s covers five flush cycles: if a regression enabled the forwarder, it would
211-
// flush within this window and the assertion would catch it.
167+
// Confirm nothing is forwarded across five flush cycles (flush_interval_seconds: 1).
212168
assert.Never(s.T(), func() bool {
213169
logs, err := s.Env().FakeIntake.Client().GetAgentTelemetryLogs()
214170
require.NoError(s.T(), err)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
datadog:
2+
leaderElection: false
3+
clusterAgent:
4+
envDict:
5+
DD_AGENT_TELEMETRY_ENABLED: "true"
6+
DD_AGENT_TELEMETRY_ERRORTRACKING_FLUSH_INTERVAL_SECONDS: "1"
7+
DD_AGENT_TELEMETRY_ERRORTRACKING_BOUNCER_WINDOW_SECONDS: "0"
8+
DD_AGENT_TELEMETRY_ERRORTRACKING_STARTUP_JITTER_SECONDS: "0"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
datadog:
2+
leaderElection: false
3+
clusterAgent:
4+
envDict:
5+
DD_AGENT_TELEMETRY_ENABLED: "true"
6+
DD_AGENT_TELEMETRY_ERRORTRACKING_ENABLED: "true"
7+
DD_AGENT_TELEMETRY_ERRORTRACKING_FLUSH_INTERVAL_SECONDS: "1"
8+
DD_AGENT_TELEMETRY_ERRORTRACKING_BOUNCER_WINDOW_SECONDS: "0"
9+
DD_AGENT_TELEMETRY_ERRORTRACKING_STARTUP_JITTER_SECONDS: "0"

0 commit comments

Comments
 (0)