diff --git a/pkg/serverless/logs/logs_collector.go b/pkg/serverless/logs/logs_collector.go index 21ab1219f1cf67..03c534385a4d36 100644 --- a/pkg/serverless/logs/logs_collector.go +++ b/pkg/serverless/logs/logs_collector.go @@ -251,6 +251,10 @@ func (lc *LambdaLogsCollector) processMessage( lc.executionContext.UpdateStartTime(lc.invocationStartTime) } + if message.logType == logTypePlatformReport { + message.stringRecord = createStringRecordForReportLog(lc.invocationStartTime, lc.invocationEndTime, message) + } + if lc.enhancedMetricsEnabled { proactiveInit := false coldStart := false @@ -292,7 +296,6 @@ func (lc *LambdaLogsCollector) processMessage( outOfMemoryRequestId = message.objectRecord.requestID } serverlessMetrics.GenerateEnhancedMetricsFromReportLog(args) - message.stringRecord = createStringRecordForReportLog(lc.invocationStartTime, lc.invocationEndTime, message) } if message.logType == logTypePlatformRuntimeDone { serverlessMetrics.GenerateEnhancedMetricsFromRuntimeDoneLog( diff --git a/pkg/serverless/logs/logs_test.go b/pkg/serverless/logs/logs_test.go index 32e563718af85b..0040f6b923295f 100644 --- a/pkg/serverless/logs/logs_test.go +++ b/pkg/serverless/logs/logs_test.go @@ -665,64 +665,69 @@ func TestProcessLogMessageLogsNotEnabled(t *testing.T) { } func TestProcessLogMessagesTimeoutLogFromReportLog(t *testing.T) { - logChannel := make(chan *config.ChannelMessage) - demux := createDemultiplexer(t) - defer demux.Stop(false) - - mockExecutionContext := &executioncontext.ExecutionContext{} - lc := &LambdaLogsCollector{ - arn: "my-arn", - lastRequestID: "myRequestID", - logsEnabled: true, - enhancedMetricsEnabled: true, - out: logChannel, - extraTags: &Tags{ - Tags: []string{"tag0:value0,tag1:value1"}, - }, - executionContext: mockExecutionContext, - demux: demux, - invocationStartTime: time.Now(), - invocationEndTime: time.Now().Add(10 * time.Millisecond), - } + for _, enhancedMetricsEnabled := range []bool{true, false} { + t.Run(fmt.Sprint(enhancedMetricsEnabled), func(t *testing.T) { + + logChannel := make(chan *config.ChannelMessage) + demux := createDemultiplexer(t) + defer demux.Stop(false) + + mockExecutionContext := &executioncontext.ExecutionContext{} + lc := &LambdaLogsCollector{ + arn: "my-arn", + lastRequestID: "myRequestID", + logsEnabled: true, + enhancedMetricsEnabled: enhancedMetricsEnabled, + out: logChannel, + extraTags: &Tags{ + Tags: []string{"tag0:value0,tag1:value1"}, + }, + executionContext: mockExecutionContext, + demux: demux, + invocationStartTime: time.Now(), + invocationEndTime: time.Now().Add(10 * time.Millisecond), + } - reportLogMessage := LambdaLogAPIMessage{ - objectRecord: platformObjectRecord{ - requestID: "myRequestID", - reportLogItem: reportLogMetrics{ - durationMs: 100.00, - billedDurationMs: 100, - memorySizeMB: 128, - maxMemoryUsedMB: 128, - initDurationMs: 50.00, - }, - status: timeoutStatus, - }, - logType: logTypePlatformReport, - stringRecord: "contents to be overwritten", - } + reportLogMessage := LambdaLogAPIMessage{ + objectRecord: platformObjectRecord{ + requestID: "myRequestID", + reportLogItem: reportLogMetrics{ + durationMs: 100.00, + billedDurationMs: 100, + memorySizeMB: 128, + maxMemoryUsedMB: 128, + initDurationMs: 50.00, + }, + status: timeoutStatus, + }, + logType: logTypePlatformReport, + stringRecord: "contents to be overwritten", + } - logMessages := []LambdaLogAPIMessage{ - reportLogMessage, - } + logMessages := []LambdaLogAPIMessage{ + reportLogMessage, + } - go lc.processLogMessages(logMessages) + go lc.processLogMessages(logMessages) - expectedStringRecord := []string{ - createStringRecordForReportLog(lc.invocationStartTime, lc.invocationEndTime, &reportLogMessage), - createStringRecordForTimeoutLog(&reportLogMessage), - } - expectedErrors := []bool{false, true} - for i := 0; i < len(expectedStringRecord); i++ { - select { - case received := <-logChannel: - assert.NotNil(t, received) - assert.Equal(t, "my-arn", received.Lambda.ARN) - assert.Equal(t, "myRequestID", received.Lambda.RequestID) - assert.Equal(t, expectedStringRecord[i], string(received.Content)) - assert.Equal(t, expectedErrors[i], received.IsError) - case <-time.After(100 * time.Millisecond): - assert.Fail(t, "We should have received logs") - } + expectedStringRecord := []string{ + createStringRecordForReportLog(lc.invocationStartTime, lc.invocationEndTime, &reportLogMessage), + createStringRecordForTimeoutLog(&reportLogMessage), + } + expectedErrors := []bool{false, true} + for i := 0; i < len(expectedStringRecord); i++ { + select { + case received := <-logChannel: + assert.NotNil(t, received) + assert.Equal(t, "my-arn", received.Lambda.ARN) + assert.Equal(t, "myRequestID", received.Lambda.RequestID) + assert.Equal(t, expectedStringRecord[i], string(received.Content)) + assert.Equal(t, expectedErrors[i], received.IsError) + case <-time.After(100 * time.Millisecond): + assert.Fail(t, "We should have received logs") + } + } + }) } }