Skip to content
New issue

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

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

Already on GitHub? # to your account

Make default HTTP request timeout configurable #3932

Open
roobre opened this issue Sep 5, 2024 · 0 comments
Open

Make default HTTP request timeout configurable #3932

roobre opened this issue Sep 5, 2024 · 0 comments
Assignees
Labels

Comments

@roobre
Copy link
Contributor

roobre commented Sep 5, 2024

Feature Description

k6 currently allows configuring the timeout of an HTTP request individually by means of the params argument of http.* methods, e.g.:

const res = http.get('https://k6.io', { timeout: '5s'});

If not specified, this defaults to 60s.

While this 60s value might make sense for some tests, for others the 60s value might be excessive. The current solution for this is of course to manually specify the desired timeout value for each request, however, that approach has a number of drawbacks:

  • Users need to be aware of the default timeout being too high, for them to realize they might want to override it.
  • The resulting code is quite verbose, with every request having this "appendix" to it.
  • In this situation, it's easy to forget to add the parameter, leading to hard to debug situations

For the particular way we are using k6 internally in Grafana Synthetic Monitoring, there's the additional drawback of not being possible for the SM systems to change this default, as we cannot modify the user's script.

Suggested Solution (optional)

I'd propose to make this default configurable from either the options global, config file, and/or a CLI flag (ideally all of them). In particular, I propose it works as follows:

export default function () {
  // This request has a 60s timeout.
  const response = http.get('https://test-api.k6.io/public/crocodiles/');
}
export const options = {
  requestTimeout: '5s',
};

export default function () {
  // This request has a 5s timeout.
  const response = http.get('https://test-api.k6.io/public/crocodiles/');
}
export const options = {
  requestTimeout: '5s',
};

export default function () {
  // This request has a 30s timeout.
  const response = http.get('https://test-api.k6.io/public/crocodiles/', { timeout: '30s' });
}

This follows the pattern of other k6 options, such as maxRedirects.

While not being pictured above, for SM in particular it would be important that this option is also exposed as a CLI flag (e.g. --request-timeout), as that would simplify integration into our system.

Already existing or connected issues / PRs (optional)

No response

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants