Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k6runner: handle errors reported by http runners #694

Merged
merged 3 commits into from Apr 30, 2024
Merged

Conversation

roobre
Copy link
Contributor

@roobre roobre commented Apr 29, 2024

Previously, k6 runners used to communicate errors by returning a non-200 status code, and not returning the logs of the execution. mq proxy, in addition to returning non-200 status codes, also includes an error code and description for errors that occur while running the script.

With the introduction of https://github.com/grafana/sm-k6-runner/pull/153, we now report as errors exceptions being thrown on the script, such as trying to access undefined variables, or invocations of fail(). In this scenario, users likely expect to see the check reported as a failure, but also to see the logs and metrics produced by it.

This PR changes the error-handling logic, so that the response is always parsed for status code that (should) include it, and the success of the check is calculated by checking if there response contains an error.

@roobre roobre force-pushed the http-runner-statuses branch 2 times, most recently from ce6fae7 to c12ccda Compare April 30, 2024 09:54
@roobre roobre force-pushed the http-runner-statuses branch 2 times, most recently from 465dd58 to 37f228f Compare April 30, 2024 10:19
@roobre roobre marked this pull request as ready for review April 30, 2024 10:20
@roobre roobre requested a review from a team as a code owner April 30, 2024 10:20
@@ -111,7 +112,8 @@ func (r Script) Run(ctx context.Context, registry *prometheus.Registry, logger l
return false, err
}

return !resultCollector.failure, nil
success := result.Error == "" && result.ErrorCode == ""
return success, nil
Copy link
Contributor Author

@roobre roobre Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if at this point we should create an error with result.Error and return it 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to do I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delved a bit more on what this error is used for, and it seems like it is just log.Warned?

func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) bool {
success, err := p.script.Run(ctx, registry, logger, p.logger)
if err != nil {
p.logger.Warn().Err(err).Msg("running probe")
return false
}
return success
}

If this is the case we might want to return an error when the code is something that is not-on-us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refined (slang for "made more complicated") the error handling logic in the latest commit, LMK what you think :)

@roobre roobre merged commit a800987 into main Apr 30, 2024
4 checks passed
@roobre roobre deleted the http-runner-statuses branch April 30, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants