K6: Specifying both duration and stages is deprecated

Created on 17 Apr 2020  路  3Comments  路  Source: loadimpact/k6

Environment

  • k6 version: k6 v0.26.2 (2020-03-18T12:07:04+0000/v0.26.2-0-g459da79e, go1.13.8, linux/amd64)
  • OS and version: Ubuntu 19.10
  • Docker version and image, if applicable:
podman version 
Version:            1.9.0
RemoteAPI Version:  1
Go Version:         go1.12.10
OS/Arch:            linux/amd64

Expected Behavior

I have used the snipplet from the doc https://k6.io/docs/getting-started/running-k6#stages-ramping-up-down-vus
script002.js

import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
  stages: [
    { duration: '30s', target: 20 },
    { duration: '1m30s', target: 10 },
    { duration: '20s', target: 0 },
  ],
};

export default function() {
  let res = http.get('https://httpbin.org/');
  check(res, { 'status was 200': r => r.status == 200 });
  sleep(1);
}

I expect to get rid of the warning below, what's the right syntax for the future?

Actual Behavior

I get the following warning when I execute k6 docker image

time="2020-04-16T22:35:41Z" \
level=warning \
msg="Specifying both duration and stages is deprecated and won't be supported in the future k6 versions"

Steps to Reproduce the Problem

  1. create script002.js with the javascript code above
  2. podman run -i loadimpact/k6 run --vus 10 --duration 30s -
question

All 3 comments

Hi @git001

thanks for the report!

Your command k6 run --vus 10 --duration 30s specifies vus and duration while the script specifies stages. In the current k6 version this is allowed, but will be deprecated in the future release.

Please either remove stages from the script or remove the --vus 10 --duration 30s from the command line.

Okay thanks.

For reference if anyone else stumbles onto this in the future, this warning isn't technically _fully_ accurate, in this specific case, but in general it is. Here's a more complete explanation:

  • In the current k6 version (v0.26.2) and previous ones, specifying both stages and duration options is technically allowed, but it behaves strangely, because it doesn't make sense. After all, the stages options contains an implicit test run duration - the sum of the duration values of its elements... So the two options conflict. There are other similar issues with the current execution options as well, like https://github.com/loadimpact/k6/issues/812.
  • We've known about these bugs and logic issues for a while, and we decided to fix them (and a lot of other things) in a huge upcoming refactoring and improvement of how k6 schedules script execution, #1007. In preparation for that, we started emitting these warnings about incompatible options in the last few k6 releases, so users can fix their scripts and we hopefully minimize the amount of breaking changes in whenever we release #1007.
  • After #1007 is merged, so probably from k6 v0.27.0 onwards, specifying both stages and duration (or stages and iterations) in your script options will be a validation error - you wouldn't be able to run such scripts.
  • That said, in _this_ specific case, the script will still work, even post-#1007, because of another minor change in that PR. From now on, any execution-related option (i.e. duration, stages, iterations, execution) from a "higher" config tier will overwrite _any_ execution-related option from a "lower" tier. Config tiers are CLI flags > environment variables > script options > JSON config file. So, in your case, the --duration CLI flag would have overwritten the stages exported script option, so the script would have executed normally - with 10 VUs for 30 seconds.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrm2k6 picture jrm2k6  路  4Comments

ppcano picture ppcano  路  3Comments

msznek picture msznek  路  3Comments

kokokenada picture kokokenada  路  4Comments

na-- picture na--  路  3Comments