K6 is unable to send the data to influxdb

Scenario

Running a basic k6 test and send the test output to influxdb. Both the k6 and influxdb are running in docker container.

Artifacts

The docker-compose file is located here at https://github.com/subhendu-de/k6-demo/blob/dev/docker-compose.yml
The script file is located here at https://github.com/subhendu-de/k6-demo/blob/dev/scripts/loadtest1.js
Please change the test url accordingly.

Issue

ERRO[0061] InfluxDB: Couldn't write stats                error="{\"code\":\"unauthorized\",\"message\":\"Unauthorized\"}"
ERRO[0061] InfluxDB: Couldn't write stats                error="Post \"http://localhost:8086/write?consistency=&db=k6-bucket&precision=ns&rp=\": dial tcp 127.0.0.1:8086: connect: connection refused"

Please note I can access the influxdb ui while the container is up and running.

Any help is really appreciated to guide me why the k6 container is unable to send the data to influxdb instance running in a container.

Regards
Subhendu

I see you already were answered on GitHub, but I’ll link the response here in case anyone else stumbles on your forum question: K6 is unable to send the data to influxdb · Issue #1883 · grafana/k6 · GitHub

In the future, please use only one place to ask your questions, no need to spam all available avenues, we read both the forum and all github issues. If you’re sure something is a bug - open an issue. If you think it’s something you may be doing wrong - open a thread in the forum, we can always open an issue if it proves to be a bug.

Noted @ned and Thanks a lot!

I have similar error:
level=error msg="InfluxDB: Couldn't write stats" error="Post \"http://localhost:8086/write?consistency=&db=myk6db&precision=ns&rp=\": dial tcp 127.0.0.1:8086: connect: connection refused"

I’m using the docker-compose solution from here Grafana dashboards

I’ve checked the github link with the “pin to version 1.8” solution and as i see the docker-compose.yaml already has 1.8 set explicitely, but i still have the error. Im trying it on MacOS (if that makes any difference).

What am i missing here?

Could you try to change the endpoint from localhost to the service name defined in the docker-compose file?

http://localhost:8086/write

A sample is given here

Sorry, not quite sure what you mean. Atm i use the following command to start the test:
docker run -i loadimpact/k6 run --out influxdb=http://localhost:8086/myk6db - <../test/test.js

Did you create the influxdb container before creating the k6 container and run the tests? Could you please share the script that you’re using to create the influxdb container?

I’m using the “official” docker-compose solution: Grafana dashboards

I am assuming you are using this docker-compose.
After that, you’re using the following command to run the k6.

Is my understanding correct?

Yes, correct. Using docker-compose.yml from the official repo.

You can test using the following folder structure and use the same docker-compose.yml from here
Please create the folders and add your k6 scripts inside samples directory

test-k6
|_ grafana
|_ samples
   |__ loadtest.js
|_ docker-compose.yml

Run the influxdb and grafana container by running the following query

docker-compose up influxdb grafana

Run the k6 script named loadtest.js by running the following query

docker-compose run k6 run /scripts/loadtest.js

Thanks, but i don’t think changing directory structure would solve this problem.

In the meantime it looks like i managed to search properly for the error message and found this: docker - InfluxDB: Couldn't write stats" error getsockopt: connection refused" - Stack Overflow
So if query the internal IP adress with ifconfig and use that one for InfluxDB, then it works. I don’t really understand why, since Grafana is jus fine with localhost…