Writing response body to an file, K6

I’m currently running a very basic K6 test script, and I’m able to see the response body if I use console.log().

However, it’s a very extensive load test I’m preparing and I need to save all the responses I get to a file, for future analysis.

I’ve currently tried the solutions mentioned in the following posts:

When using docker-compose run k6 run --logformat raw tests.js --console-output=./test.csv it only works on windows but not Ubuntu(Unix/linux) system.
docker-compose run -u "$(id -u):$(id -g)" k6 run --logformat raw --console-output=/scripts/test.csv /scripts/stages.js gives test.csv permission denied

I’ve also tried k6 run test.js 2>responses.csv and different file names, the output file turns out to be empty at the moment. I was logging the response as console.log() and alternatively as console.debug()
docker-compose run k6 run --logformat raw --http-debug=full tests.js 2>test.csv
Also returned an empty file.

Is there any way to be able to save the raw responses we get from a request.

Would also be helpful if we can save responses to influxdb

Trying to run this on Ubuntu

You don’t say anywhere if you use docker volumes, which is the easiest way to have k6 write a file to a filesystem outside of the docker container. See Volumes | Docker Documentation and https://www.baeldung.com/ops/docker-volumes#starting-a-container-with-a-volume for more details.

Hey Ned, thanks for getting back so quick.

I tried following:
docker-compose run -v test_output:/var/opt/project k6 run --logformat raw /scripts/ewoks.js --console-output=var/opt/internal/consoleoutput.txt

and got open /var/opt/project/consoleout.txt: permission denied

test_output is a new docker volume that I created.
also tried a local directory as bind mount, it gave permission denied

Update its working now, just needed a --user $UID tag for docker-compose

1 Like