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

REST API: get total and current duration, iterations, etc. #1111

Closed
xshrim opened this issue Aug 11, 2019 · 2 comments
Closed

REST API: get total and current duration, iterations, etc. #1111

xshrim opened this issue Aug 11, 2019 · 2 comments

Comments

@xshrim
Copy link

xshrim commented Aug 11, 2019

How can i get the current and total duration/iterations of a load testing from the rest api?

@na--
Copy link
Member

na-- commented Aug 12, 2019

You currently can't get them directly, sorry, though with some simple workarounds, you might be able to get what you need. You can get the total duration/iteration/etc. options by returning them from setup() like this:

import http from "k6/http";
import { sleep } from "k6";

export let options = {};

export function setup() {
    return {
        myOptions: {
            vus: options.vus,
            duration: options.duration,
            // ...
        }
    }
}

export default function () {
    http.get(`https://test.loadimpact.com/`);
    sleep(1);
}

This works because the consolidated k6 options (CLI flags + env vars + JS options + JSON options) will be propagated back to the JS options object before the setup() or VU execution. So, running that script with k6 run --vus 5 --duration 20m and then running curl http://localhost:6565/v1/setup will get you something like:

{"data":{"type":"setupData","id":"default","attributes":{"data":{"myOptions":{"duration":"20m0s","vus":5}}}}}

And running curl http://localhost:6565/v1/metrics/iterations (to get the value of the iterations metric) will get you something like:

{"data":{"type":"metrics","id":"iterations","attributes":{"type":"counter","contains":"default","tainted":null,"sample":{"count":19,"rate":3.457626896665038}}}}

You can get the current VUs (useful for when you have ramping up or down of VUs via stages) via curl http://localhost:6565/v1/status or curl http://localhost:6565/v1/metrics/vus. However, there isn't a metric for the current elapsed test duration, and while you can probably create a custom one that you update in the script, you might be better off with just an external timer.

I'll leave this issue open, since it makes sense to have these directly and in a single place the API, but because of the somewhat easy workarounds, it's definitely going to be a low priority one. And it's definitely going to be after #1007 is merged, because otherwise we'd have to do it twice...

@na-- na-- changed the title How to get duration and iterations from rest api REST API: get total and current duration, iterations, etc. Aug 12, 2019
@mstoykov
Copy link
Contributor

I am closing this due to lack of interest.

We are very unlikely to put this in v1 and v2 likely will have similar functionality as it will need to supported distributed execution.

see #3497

@mstoykov mstoykov closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants