From dde3046bfb7b611f9896c2a86a17598a6364ae87 Mon Sep 17 00:00:00 2001 From: Nadia Santalla Date: Fri, 8 Nov 2024 14:19:39 +0100 Subject: [PATCH] fix: k6runner: add level=error to deferred log reporting code from runner --- internal/k6runner/http_test.go | 8 ++++---- internal/k6runner/k6runner.go | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/k6runner/http_test.go b/internal/k6runner/http_test.go index 4d505492..da9edf95 100644 --- a/internal/k6runner/http_test.go +++ b/internal/k6runner/http_test.go @@ -191,7 +191,7 @@ func TestScriptHTTPRun(t *testing.T) { expectSuccess: false, expectError: ErrFromRunner, expectLogs: nonDebugLogLine + fmt.Sprintf( - "msg=\"script did not execute successfully\" error=%q errorCode=%q\n", + "level=\"error\" msg=\"script did not execute successfully\" error=%q errorCode=%q\n", "something went wrong", "something-wrong", ), @@ -209,7 +209,7 @@ func TestScriptHTTPRun(t *testing.T) { expectSuccess: false, expectError: nil, expectLogs: nonDebugLogLine + fmt.Sprintf( - "msg=\"script did not execute successfully\" error=%q errorCode=%q\n", + "level=\"error\" msg=\"script did not execute successfully\" error=%q errorCode=%q\n", "syntax error somewhere or something", "aborted", ), @@ -226,7 +226,7 @@ func TestScriptHTTPRun(t *testing.T) { expectSuccess: false, expectErrorAs: &logfmt.SyntaxError{}, expectLogs: `level="error"` + "\n" + fmt.Sprintf( - "msg=\"script did not execute successfully\" error=%q errorCode=%q\n", + "level=\"error\" msg=\"script did not execute successfully\" error=%q errorCode=%q\n", "we killed k6", "aborted", ), @@ -243,7 +243,7 @@ func TestScriptHTTPRun(t *testing.T) { expectSuccess: false, expectErrorAs: expfmt.ParseError{}, expectLogs: nonDebugLogLine + fmt.Sprintf( - "msg=\"script did not execute successfully\" error=%q errorCode=%q\n", + "level=\"error\" msg=\"script did not execute successfully\" error=%q errorCode=%q\n", "we killed k6", "aborted", ), diff --git a/internal/k6runner/k6runner.go b/internal/k6runner/k6runner.go index 00855c2e..6b00fbb3 100644 --- a/internal/k6runner/k6runner.go +++ b/internal/k6runner/k6runner.go @@ -151,7 +151,12 @@ func (r Processor) Run(ctx context.Context, registry *prometheus.Registry, logge // other logs. if result.ErrorCode != "" { defer func() { - err := logger.Log("msg", "script did not execute successfully", "error", result.Error, "errorCode", result.ErrorCode) + err := logger.Log( + "level", "error", + "msg", "script did not execute successfully", + "error", result.Error, + "errorCode", result.ErrorCode, + ) if err != nil { internalLogger.Error(). Err(err).