Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions apmproxy/apmserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions e2e-testing/e2e_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions extension/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package extension

import (
"context"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -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(`
Expand All @@ -53,16 +50,14 @@ 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)
assert.Equal(t, "lambda_function.lambda_handler", res.Handler)
}

func TestNextEvent(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
response := []byte(`
{
"eventType": "INVOKE",
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down Expand Up @@ -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")),
Expand Down
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
@@ -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

Expand Down