Skip to content

Commit f7ced25

Browse files
authored
[e2e] bump test-infra (#23634)
* [e2e] Bump test-infra Changelog: DataDog/test-infra-definitions@6dbc5da...eb67dd1 * [e2e] improve remote config tests * [e2e] add comment to recommend using a valid API key for TestRcTracerSuite * [e2e] add expected log to remote config test
1 parent 2eec69a commit f7ced25

6 files changed

Lines changed: 93 additions & 30 deletions

File tree

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ variables:
186186
# and check the job creating the image to make sure you have the right SHA prefix
187187
TEST_INFRA_DEFINITIONS_BUILDIMAGES_SUFFIX: ""
188188
# Make sure to update test-infra-definitions version in go.mod as well
189-
TEST_INFRA_DEFINITIONS_BUILDIMAGES: a1d921006e35
189+
TEST_INFRA_DEFINITIONS_BUILDIMAGES: eb67dd1667e4
190190
DATADOG_AGENT_BUILDERS: v22276738-b36b132
191191

192192
DATADOG_AGENT_EMBEDDED_PATH: /opt/datadog-agent/embedded

test/new-e2e/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
// `TEST_INFRA_DEFINITIONS_BUILDIMAGES` matches the commit sha in the module version
2828
// Example: github.com/DataDog/test-infra-definitions v0.0.0-YYYYMMDDHHmmSS-0123456789AB
2929
// => TEST_INFRA_DEFINITIONS_BUILDIMAGES: 0123456789AB
30-
github.com/DataDog/test-infra-definitions v0.0.0-20240308103459-6dbc5dad4e60
30+
github.com/DataDog/test-infra-definitions v0.0.0-20240312182905-eb67dd1667e4
3131
github.com/aws/aws-sdk-go-v2 v1.25.2
3232
github.com/aws/aws-sdk-go-v2/config v1.27.6
3333
github.com/aws/aws-sdk-go-v2/service/ec2 v1.138.1

test/new-e2e/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/new-e2e/tests/remote-config/rc_ssl_config_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ package remoteconfig
77

88
import (
99
_ "embed"
10-
"github.com/stretchr/testify/assert"
1110
"testing"
1211
"time"
1312

13+
"github.com/stretchr/testify/assert"
14+
1415
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
1516
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
1617
awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host"
@@ -38,13 +39,15 @@ func TestSslConfigSuite(t *testing.T) {
3839

3940
// TestRemoteConfigSSLConfigMismatch tests the startup condition where the agent's SSL config is disabled but RC's TLS validation is not explicitly disabled
4041
func (s *sslConfigSuite) TestRemoteConfigSSLConfigMismatch() {
41-
// Ensure the remote config service starts
42-
assertLogsEventually(s.T(), s.Env().RemoteHost, "agent", "remote config service started", 2*time.Minute, 5*time.Second)
43-
44-
// Ensure the agent logs a warning about the SSL config mismatch
45-
assertLogsEventually(s.T(), s.Env().RemoteHost, "agent", "remote Configuration does not allow skipping TLS validation by default", 2*time.Minute, 5*time.Second)
46-
// Ensure the remote config service stops, and the client stops because the service is no longer responding
47-
assertLogsEventually(s.T(), s.Env().RemoteHost, "agent", "remote configuration isn't enabled, disabling client", 2*time.Minute, 5*time.Second)
42+
expectedLogs := []string{
43+
// Ensure the agent logs a warning about the SSL config mismatch
44+
"remote Configuration does not allow skipping TLS validation by default",
45+
// Ensure the remote config service stops, and the client stops because the service is no longer responding
46+
"remote configuration isn't enabled, disabling client",
47+
// Ensure the agent logs a warning about the remote config service being unable to start
48+
"unable to create remote config service",
49+
}
50+
assertAgentLogsEventually(s.T(), s.Env().RemoteHost, "agent", expectedLogs, 2*time.Minute, 5*time.Second)
4851

4952
// Ensure the agent remains running despite the remote config service initialization failure
5053
// EventuallyWithT will wait for the duration of the `tick` argument before executing the assertion function,

test/new-e2e/tests/remote-config/tracer_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var rcEnabledConfig string
2828
//go:embed fixtures/tracer-payload.json
2929
var tracerPayloadJSON string
3030

31+
// TestRcTracerSuite tests the remote-config service by attempting to retrieve RC payloads as if a tracer were calling it
32+
// Requires a valid Datadog API key
3133
func TestRcTracerSuite(t *testing.T) {
3234
e2e.Run(t, &tracerSuite{},
3335
e2e.WithProvisioner(
@@ -42,16 +44,20 @@ func TestRcTracerSuite(t *testing.T) {
4244

4345
// TestRemoteConfigTracerUpdate tests the remote-config service by attempting to retrieve RC payloads as if a tracer were calling it
4446
func (s *tracerSuite) TestRemoteConfigTracerUpdate() {
45-
// Ensure the remote config service starts
46-
assertLogsEventually(s.T(), s.Env().RemoteHost, "agent", "remote config service started", 2*time.Minute, 5*time.Second)
47-
48-
// Wait until we've started querying for configs
49-
assertLogsEventually(s.T(), s.Env().RemoteHost, "agent", "/api/v0.1/configurations", 2*time.Minute, 5*time.Second)
47+
expectedAgentLogs := []string{
48+
// Ensure the remote config service starts
49+
"remote config service started",
50+
// Wait until we've started querying for configs
51+
"/api/v0.1/configurations",
52+
}
53+
assertAgentLogsEventually(s.T(), s.Env().RemoteHost, "agent", expectedAgentLogs, 2*time.Minute, 5*time.Second)
5054

5155
// Get configs as though we are a tracer
52-
getConfigsOutput := mustCurlAgentRcServiceEventually(s.T(), s.Env().RemoteHost, tracerPayloadJSON, 2*time.Minute, 5*time.Second)
53-
require.Contains(s.T(), getConfigsOutput, "roots", "expected a roots key in the tracer config output")
54-
require.Contains(s.T(), getConfigsOutput, "targets", "expected a targets key in the tracer config output")
56+
expectedKeys := []string{
57+
"roots",
58+
"targets",
59+
}
60+
assertCurlAgentRcServiceContainsEventually(s.T(), s.Env().RemoteHost, tracerPayloadJSON, expectedKeys, 2*time.Minute, 5*time.Second)
5561

5662
// Check remote-config command output for our e2e test client that we fetched configs for
5763
remoteConfigOutput := s.Env().Agent.Client.RemoteConfig()

test/new-e2e/tests/remote-config/utils_test.go

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,91 @@ package remoteconfig
88
import (
99
_ "embed"
1010
"fmt"
11-
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
12-
"github.com/stretchr/testify/assert"
11+
"os"
12+
"path"
13+
"strings"
1314
"testing"
1415
"time"
16+
17+
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/components"
18+
"github.com/stretchr/testify/assert"
1519
)
1620

1721
// assertLogsEventually will verify that a given `agentName` component's logs contain a pattern.
1822
// It will continually retry until the `expectedLogPattern` is found or the `maxRetries` is reached,
1923
// waiting `retryInterval` between each attempt.
2024
// If the `expectedLogPattern` is not found or an error occurs, the calling test will fail.
21-
func assertLogsEventually(t *testing.T, rh *components.RemoteHost, agentName string, expectedLogPattern string, waitFor time.Duration, tick time.Duration) {
25+
func assertAgentLogsEventually(t *testing.T, rh *components.RemoteHost, agentName string, expectedLogs []string, waitFor time.Duration, tick time.Duration) {
2226
t.Helper()
27+
foundLogs := make(map[string]bool, len(expectedLogs))
28+
missingLogs := make([]string, len(expectedLogs))
29+
// initially all logs are missing
30+
copy(missingLogs, expectedLogs)
31+
remoteLogsPath := fmt.Sprintf("/var/log/datadog/%s.log", agentName)
32+
t.Logf("looking for logs in %s", remoteLogsPath)
2333
assert.EventuallyWithTf(t, func(c *assert.CollectT) {
24-
output, err := rh.Execute(fmt.Sprintf("cat /var/log/datadog/%s.log", agentName))
25-
if assert.NoError(c, err) {
26-
assert.Contains(c, output, expectedLogPattern)
34+
// read agent logs
35+
agentLogs, err := readRemoteFile(rh, remoteLogsPath)
36+
if !assert.NoError(c, err) {
37+
return
38+
}
39+
for _, log := range missingLogs {
40+
if strings.Contains(agentLogs, log) {
41+
t.Logf("found log: %s", log)
42+
foundLogs[log] = true
43+
}
2744
}
28-
}, waitFor, tick, "failed to find log with pattern `%s`", expectedLogPattern)
45+
// reset missing logs
46+
missingLogs = make([]string, 0, len(expectedLogs))
47+
for _, log := range expectedLogs {
48+
if _, ok := foundLogs[log]; ok {
49+
continue
50+
}
51+
missingLogs = append(missingLogs, log)
52+
}
53+
assert.Empty(c, missingLogs, "still missing logs")
54+
t.Logf("missing logs:\n[%s]", strings.Join(missingLogs, ","))
55+
}, waitFor, tick, "failed finding logs in agent")
2956
}
3057

3158
// mustCurlAgentRcServiceEventually will curl the remote config service's endpoint to get tracer
3259
// configurations every `tick` until either it is successful (in which case it will return the
3360
// output of the curl command), or the `waitFor` duration is reached (in which case it will
3461
// fail the calling test).
35-
func mustCurlAgentRcServiceEventually(t *testing.T, rh *components.RemoteHost, payload string, waitFor time.Duration, tick time.Duration) string {
62+
func assertCurlAgentRcServiceContainsEventually(t *testing.T, rh *components.RemoteHost, payload string, expectedKeys []string, waitFor time.Duration, tick time.Duration) string {
3663
t.Helper()
3764
var output string
65+
missingContents := make([]string, len(expectedKeys))
66+
copy(missingContents, expectedKeys)
67+
foundContents := make(map[string]bool, len(expectedKeys))
3868
assert.EventuallyWithTf(t, func(c *assert.CollectT) {
39-
curl, err := rh.Execute(fmt.Sprintf("curl -sS localhost:8126/v0.7/config -d @- <<EOF\n%sEOF", payload))
69+
curlOutput, err := rh.Execute(fmt.Sprintf("curl -sSL localhost:8126/v0.7/config -d @- <<EOF\n%sEOF", payload))
4070
assert.NoError(c, err)
41-
output = curl
71+
for _, content := range missingContents {
72+
if strings.Contains(curlOutput, content) {
73+
t.Logf("found content: %s", content)
74+
foundContents[content] = true
75+
}
76+
}
77+
// reset missing contents
78+
missingContents = make([]string, 0, len(expectedKeys))
79+
for _, content := range expectedKeys {
80+
if _, ok := foundContents[content]; ok {
81+
continue
82+
}
83+
missingContents = append(missingContents, content)
84+
}
85+
assert.Empty(c, missingContents, "still missing contents")
4286
}, waitFor, tick, "could not curl remote config service")
4387
return output
4488
}
89+
90+
func readRemoteFile(rh *components.RemoteHost, remotePath string) (string, error) {
91+
localPath := path.Join(os.TempDir(), path.Base(remotePath))
92+
err := rh.GetFile(remotePath, localPath)
93+
if err != nil {
94+
return "", err
95+
}
96+
b, err := os.ReadFile(localPath)
97+
return string(b), err
98+
}

0 commit comments

Comments
 (0)