Skip to content

Commit

Permalink
fix: k6runner: add level=error to deferred log reporting code from ru…
Browse files Browse the repository at this point in the history
…nner
  • Loading branch information
nadiamoe authored and Nadia Santalla committed Nov 8, 2024
1 parent ce90bfb commit dde3046
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/k6runner/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand Down
7 changes: 6 additions & 1 deletion internal/k6runner/k6runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit dde3046

Please sign in to comment.