-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[e2e] bump test-infra #23634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[e2e] bump test-infra #23634
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,37 +8,91 @@ package remoteconfig | |
| import ( | ||
| _ "embed" | ||
| "fmt" | ||
| "github.com/DataDog/datadog-agent/test/new-e2e/pkg/components" | ||
| "github.com/stretchr/testify/assert" | ||
| "os" | ||
| "path" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/DataDog/datadog-agent/test/new-e2e/pkg/components" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // assertLogsEventually will verify that a given `agentName` component's logs contain a pattern. | ||
| // It will continually retry until the `expectedLogPattern` is found or the `maxRetries` is reached, | ||
| // waiting `retryInterval` between each attempt. | ||
| // If the `expectedLogPattern` is not found or an error occurs, the calling test will fail. | ||
| func assertLogsEventually(t *testing.T, rh *components.RemoteHost, agentName string, expectedLogPattern string, waitFor time.Duration, tick time.Duration) { | ||
| func assertAgentLogsEventually(t *testing.T, rh *components.RemoteHost, agentName string, expectedLogs []string, waitFor time.Duration, tick time.Duration) { | ||
| t.Helper() | ||
| foundLogs := make(map[string]bool, len(expectedLogs)) | ||
| missingLogs := make([]string, len(expectedLogs)) | ||
| // initially all logs are missing | ||
| copy(missingLogs, expectedLogs) | ||
| remoteLogsPath := fmt.Sprintf("/var/log/datadog/%s.log", agentName) | ||
| t.Logf("looking for logs in %s", remoteLogsPath) | ||
| assert.EventuallyWithTf(t, func(c *assert.CollectT) { | ||
| output, err := rh.Execute(fmt.Sprintf("cat /var/log/datadog/%s.log", agentName)) | ||
| if assert.NoError(c, err) { | ||
| assert.Contains(c, output, expectedLogPattern) | ||
| // read agent logs | ||
| agentLogs, err := readRemoteFile(rh, remoteLogsPath) | ||
| if !assert.NoError(c, err) { | ||
| return | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess assert.NoError will raise a message so no need to create one here, correct?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would not: assert does not interrupt the go routine execution. I should use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a consequence we might have put a log message to understand the error. But it's unlikely to happen so I guess it's fine
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we log the error out of the |
||
| } | ||
| for _, log := range missingLogs { | ||
| if strings.Contains(agentLogs, log) { | ||
| t.Logf("found log: %s", log) | ||
| foundLogs[log] = true | ||
| } | ||
| } | ||
| }, waitFor, tick, "failed to find log with pattern `%s`", expectedLogPattern) | ||
| // reset missing logs | ||
| missingLogs = make([]string, 0, len(expectedLogs)) | ||
|
chouetz marked this conversation as resolved.
|
||
| for _, log := range expectedLogs { | ||
| if _, ok := foundLogs[log]; ok { | ||
| continue | ||
| } | ||
| missingLogs = append(missingLogs, log) | ||
| } | ||
| assert.Empty(c, missingLogs, "still missing logs") | ||
| t.Logf("missing logs:\n[%s]", strings.Join(missingLogs, ",")) | ||
| }, waitFor, tick, "failed finding logs in agent") | ||
| } | ||
|
|
||
| // mustCurlAgentRcServiceEventually will curl the remote config service's endpoint to get tracer | ||
| // configurations every `tick` until either it is successful (in which case it will return the | ||
| // output of the curl command), or the `waitFor` duration is reached (in which case it will | ||
| // fail the calling test). | ||
| func mustCurlAgentRcServiceEventually(t *testing.T, rh *components.RemoteHost, payload string, waitFor time.Duration, tick time.Duration) string { | ||
| func assertCurlAgentRcServiceContainsEventually(t *testing.T, rh *components.RemoteHost, payload string, expectedKeys []string, waitFor time.Duration, tick time.Duration) string { | ||
|
chouetz marked this conversation as resolved.
|
||
| t.Helper() | ||
| var output string | ||
| missingContents := make([]string, len(expectedKeys)) | ||
| copy(missingContents, expectedKeys) | ||
| foundContents := make(map[string]bool, len(expectedKeys)) | ||
| assert.EventuallyWithTf(t, func(c *assert.CollectT) { | ||
| curl, err := rh.Execute(fmt.Sprintf("curl -sS localhost:8126/v0.7/config -d @- <<EOF\n%sEOF", payload)) | ||
| curlOutput, err := rh.Execute(fmt.Sprintf("curl -sSL localhost:8126/v0.7/config -d @- <<EOF\n%sEOF", payload)) | ||
| assert.NoError(c, err) | ||
| output = curl | ||
| for _, content := range missingContents { | ||
| if strings.Contains(curlOutput, content) { | ||
| t.Logf("found content: %s", content) | ||
| foundContents[content] = true | ||
| } | ||
| } | ||
| // reset missing contents | ||
| missingContents = make([]string, 0, len(expectedKeys)) | ||
| for _, content := range expectedKeys { | ||
| if _, ok := foundContents[content]; ok { | ||
| continue | ||
| } | ||
| missingContents = append(missingContents, content) | ||
| } | ||
| assert.Empty(c, missingContents, "still missing contents") | ||
| }, waitFor, tick, "could not curl remote config service") | ||
| return output | ||
| } | ||
|
|
||
| func readRemoteFile(rh *components.RemoteHost, remotePath string) (string, error) { | ||
|
chouetz marked this conversation as resolved.
|
||
| localPath := path.Join(os.TempDir(), path.Base(remotePath)) | ||
| err := rh.GetFile(remotePath, localPath) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| b, err := os.ReadFile(localPath) | ||
| return string(b), err | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.