diff --git a/apmproxy/apmserver_test.go b/apmproxy/apmserver_test.go index 19d58b49..a907f5b1 100644 --- a/apmproxy/apmserver_test.go +++ b/apmproxy/apmserver_test.go @@ -83,7 +83,7 @@ func TestPostToApmServerDataCompressed(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) } func TestPostToApmServerDataNotCompressed(t *testing.T) { @@ -129,7 +129,7 @@ func TestPostToApmServerDataNotCompressed(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) } func TestGracePeriod(t *testing.T) { @@ -178,7 +178,7 @@ func TestSetHealthyTransport(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) assert.Equal(t, apmproxy.Healthy, apmClient.Status) assert.Equal(t, apmClient.ReconnectionCount, -1) } @@ -192,7 +192,7 @@ func TestSetFailingTransport(t *testing.T) { ) require.NoError(t, err) apmClient.ReconnectionCount = 0 - apmClient.UpdateStatus(context.Background(), apmproxy.Failing) + apmClient.UpdateStatus(t.Context(), apmproxy.Failing) assert.Equal(t, apmproxy.Failing, apmClient.Status) assert.Equal(t, 1, apmClient.ReconnectionCount) } @@ -203,8 +203,8 @@ func TestSetPendingTransport(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), apmproxy.Failing) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Failing) require.Eventually(t, func() bool { return !apmClient.IsUnhealthy() }, 7*time.Second, 50*time.Millisecond) @@ -218,8 +218,8 @@ func TestSetPendingTransportExplicitly(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), apmproxy.Started) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Started) assert.Equal(t, apmproxy.Healthy, apmClient.Status) assert.Equal(t, apmClient.ReconnectionCount, -1) } @@ -230,8 +230,8 @@ func TestSetInvalidTransport(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), "Invalid") + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), "Invalid") assert.Equal(t, apmproxy.Healthy, apmClient.Status) assert.Equal(t, apmClient.ReconnectionCount, -1) } @@ -274,12 +274,12 @@ func TestEnterBackoffFromHealthy(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) // Close the APM server early so that POST requests fail and that backoff is enabled apmServer.Close() - if err := apmClient.PostToApmServer(context.Background(), agentData); err != nil { + if err := apmClient.PostToApmServer(t.Context(), agentData); err != nil { return } // No way to know for sure if failing or pending (0 sec grace period) @@ -329,14 +329,14 @@ func TestEnterBackoffFromFailing(t *testing.T) { ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), apmproxy.Failing) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Failing) require.Eventually(t, func() bool { return !apmClient.IsUnhealthy() }, 7*time.Second, 50*time.Millisecond) assert.Equal(t, apmproxy.Started, apmClient.Status) - require.Error(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.Error(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.Failing, apmClient.Status) assert.Equal(t, 1, apmClient.ReconnectionCount) } @@ -383,14 +383,14 @@ func TestAPMServerRecovery(t *testing.T) { ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), apmproxy.Failing) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Failing) require.Eventually(t, func() bool { return !apmClient.IsUnhealthy() }, 7*time.Second, 50*time.Millisecond) assert.Equal(t, apmproxy.Started, apmClient.Status) - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.Healthy, apmClient.Status) } @@ -428,13 +428,13 @@ func TestAPMServerAuthFails(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), apmproxy.Failing) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Failing) require.Eventually(t, func() bool { return !apmClient.IsUnhealthy() }, 7*time.Second, 50*time.Millisecond) assert.Equal(t, apmproxy.Started, apmClient.Status) - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.NotEqual(t, apmproxy.Healthy, apmClient.Status) } @@ -482,11 +482,11 @@ func TestAPMServerRatelimit(t *testing.T) { assert.Equal(t, apmproxy.Started, apmClient.Status) // First request fails but does not trigger the backoff - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.RateLimited, apmClient.Status) // Followup request is successful - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.Healthy, apmClient.Status) } @@ -534,11 +534,11 @@ func TestAPMServerClientFail(t *testing.T) { assert.Equal(t, apmproxy.Started, apmClient.Status) // First request fails but does not trigger the backoff - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.ClientFailing, apmClient.Status) // Followup request is successful - require.NoError(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.NoError(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.Healthy, apmClient.Status) } @@ -581,13 +581,13 @@ func TestContinuedAPMServerFailure(t *testing.T) { apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()), ) require.NoError(t, err) - apmClient.UpdateStatus(context.Background(), apmproxy.Healthy) - apmClient.UpdateStatus(context.Background(), apmproxy.Failing) + apmClient.UpdateStatus(t.Context(), apmproxy.Healthy) + apmClient.UpdateStatus(t.Context(), apmproxy.Failing) require.Eventually(t, func() bool { return !apmClient.IsUnhealthy() }, 7*time.Second, 50*time.Millisecond) assert.Equal(t, apmproxy.Started, apmClient.Status) - require.Error(t, apmClient.PostToApmServer(context.Background(), agentData)) + require.Error(t, apmClient.PostToApmServer(t.Context(), agentData)) assert.Equal(t, apmproxy.Failing, apmClient.Status) } @@ -628,7 +628,7 @@ func TestForwardApmData(t *testing.T) { require.NoError(t, err) // Start forwarding APM data - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) var wg sync.WaitGroup wg.Add(1) go func() { @@ -703,7 +703,7 @@ func BenchmarkFlushAPMData(b *testing.B) { for j := 0; j < 99; j++ { apmClient.LambdaDataChannel <- []byte(`{"log":{"message":this is test log"}}`) } - apmClient.FlushAPMData(context.Background()) + apmClient.FlushAPMData(b.Context()) } } @@ -742,7 +742,7 @@ func BenchmarkPostToAPM(b *testing.B) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - if err := apmClient.PostToApmServer(context.Background(), agentData); err != nil { + if err := apmClient.PostToApmServer(b.Context(), agentData); err != nil { b.Fatal(err) } } diff --git a/e2e-testing/e2e_util.go b/e2e-testing/e2e_util.go index ea22e9f0..f180c49e 100644 --- a/e2e-testing/e2e_util.go +++ b/e2e-testing/e2e_util.go @@ -56,12 +56,12 @@ func RunCommandInDir(l *zap.SugaredLogger, command string, args []string, dir st scannerOut := bufio.NewScanner(stdout) for scannerOut.Scan() { m := scannerOut.Text() - l.Debugf(m) + l.Debug(m) } scannerErr := bufio.NewScanner(stderr) for scannerErr.Scan() { m := scannerErr.Text() - l.Debugf(m) + l.Debug(m) } if err := e.Wait(); err != nil { l.Errorf("Could not wait for the execution of %s : %v", command, err) diff --git a/extension/client_test.go b/extension/client_test.go index db08d91f..bd0e6443 100644 --- a/extension/client_test.go +++ b/extension/client_test.go @@ -18,7 +18,6 @@ package extension import ( - "context" "io" "net/http" "net/http/httptest" @@ -30,8 +29,6 @@ import ( ) func TestRegister(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() extensionName := "helloWorld" expectedRequest := `{"events":["INVOKE","SHUTDOWN"]}` response := []byte(` @@ -53,7 +50,7 @@ func TestRegister(t *testing.T) { defer runtimeServer.Close() client := NewClient(runtimeServer.Listener.Addr().String(), zaptest.NewLogger(t).Sugar()) - res, err := client.Register(ctx, extensionName) + res, err := client.Register(t.Context(), extensionName) require.NoError(t, err) assert.Equal(t, "helloWorld", res.FunctionName) assert.Equal(t, "$LATEST", res.FunctionVersion) @@ -61,8 +58,6 @@ func TestRegister(t *testing.T) { } func TestNextEvent(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() response := []byte(` { "eventType": "INVOKE", @@ -85,7 +80,7 @@ func TestNextEvent(t *testing.T) { defer runtimeServer.Close() client := NewClient(runtimeServer.Listener.Addr().String(), zaptest.NewLogger(t).Sugar()) - res, err := client.NextEvent(ctx) + res, err := client.NextEvent(t.Context()) require.NoError(t, err) assert.Equal(t, Invoke, res.EventType) assert.Equal(t, int64(1646394703586), res.DeadlineMs) diff --git a/go.mod b/go.mod index 93f93cc6..0a990789 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/elastic/apm-aws-lambda -go 1.23.8 +go 1.24.2 require ( github.com/aws/aws-sdk-go-v2 v1.36.3 diff --git a/main_test.go b/main_test.go index 27ccd952..699e71cc 100644 --- a/main_test.go +++ b/main_test.go @@ -162,16 +162,14 @@ func newMockLambdaServer(t *testing.T, logsapiAddr string, eventsChannel chan Mo var lambdaServerInternals MockServerInternals // A big queue that can hold all the events required for a test mockLogEventQ := make(chan logsapi.LogEvent, 100) - ctx, cancel := context.WithCancel(context.Background()) var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() - startLogSender(ctx, mockLogEventQ, logsapiAddr, l) + startLogSender(t.Context(), mockLogEventQ, logsapiAddr, l) }() t.Cleanup(func() { - cancel() wg.Wait() }) @@ -867,7 +865,7 @@ func runApp(t *testing.T, logsapiAddr string) <-chan struct{} { } func runAppFull(t *testing.T, logsapiAddr string, disableLogsAPI bool) <-chan struct{} { - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) opts := []app.ConfigOption{ app.WithExtensionName("apm-lambda-extension"), app.WithLambdaRuntimeAPI(os.Getenv("AWS_LAMBDA_RUNTIME_API")), diff --git a/tools/go.mod b/tools/go.mod index 80d32e94..222887a7 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -1,6 +1,6 @@ module github.com/elastic/apm-aws-lambda/tools -go 1.23.8 +go 1.24.2 require github.com/terraform-docs/terraform-docs v0.20.0