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

k6 cloud json output of run id to later get status #2972

Open
damienpontifex opened this issue Mar 11, 2023 · 1 comment
Open

k6 cloud json output of run id to later get status #2972

damienpontifex opened this issue Mar 11, 2023 · 1 comment
Labels

Comments

@damienpontifex
Copy link

Feature Description

The use case is being able to start a test run in a CI pipeline, but not wait for execution complete (so as to not block and pay for the pipeline agent). Then at some later time check on the status of the run and pass or fail the stage.

An example pipeline with Azure DevOps might look like this

stages:
- stage: Run
  jobs:
    - job: Run
      steps:
        - script: |
            k6 cloud my-test.js
                --exit-on-running
          env:
            K6_CLOUD_TOKEN: TODO_SUBSTITUTE
          displayName: Schedule load test in k6 cloud
          workingDirectory: $(Pipeline.Workspace)/load-test

# Align this wait time with expected execution time of the k6 run so we don't block an agent to get the results
- stage: WaitForExecution
  jobs:
    - job: WaitForExecution
      pool: server
      steps:
        - task: Delay@1
          inputs:
            delayForMinutes: '30'

- stage: InspectResults
  jobs:
    - job: InspectResults
      steps:
        - script: |
            k6 status .....
          env:
            K6_CLOUD_TOKEN: TODO_SUBSTITUTE
          displayName: Inspect k6 results
  • Be able to initiate a test run, wait a while, and then get status of that run.
  • Today use --exit-on-running so the agent initiating the run isn't blocked
  • Could use Read load test run API to get the result, but CLI doesn't give an indication of the run id

Suggested Solution (optional)

  • k6 cloud my-test.js --exit-on-running --output json would output something such as { "reference_id": 123 }
  • This could then be set as a state in the pipeline so another stage could use this reference
  • Either use Cloud REST API to poll state after some delay, or k6 status command to enable this from CLI

Already existing or connected issues / PRs (optional)

No response

@imiric
Copy link
Contributor

imiric commented Mar 13, 2023

Hi, thanks for opening this issue.

I can definitely see how this would be useful.

We do log a debug event for the cloud output (with k6 run -v -o cloud) that shows the Cloud test run ID (referenceId):

DEBU[0000] Started!                                      duration=50 name="{{stages.js true}}" output=cloud projectId="{{0 false}}" referenceId=150114

I don't think this should be written to the json output, since outputs are meant for metrics, not for logging this type of information.

This log can also be dumped in JSON format with k6 run -v --log-format json:

{"duration":50,"level":"debug","msg":"Started!","name":"stages.js","output":"cloud","projectId":null,"referenceId":"150116","time":"2023-03-13T16:07:58+01:00"}

So maybe also logging the reference ID with the k6 cloud command would be the quickest fix that would help you. Then you could parse the output as JSON and get the referenceId from there. --log-output file might help with that as well.

In the meantime, have you tried listing the load test runs for a particular load test via the API? The load test ID should be static, so if you start the test run, you can poll this API in the background and correlate it with the test run you just started.

You might even parse the URL currently shown by k6 (output: https://k6.io/runs/150118), and just get it from there. It's a bit hacky, but should work.

Finally, I don't see why we can't start a REST API for k6 cloud, just as we do for k6 run. It wouldn't support some features like pause/resume/scale, but it should be able to show you the same as k6 status does with k6 run. We would only need to include the referenceId in the status output. That way you could call it after starting the test, instead of parsing the logging output.

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

No branches or pull requests

2 participants