K6<->Datadog Docker Container Connectivity Error

$ pwd

Step 1) I started the datadog docker agent with the below Linux command:

$ docker run --name datadog -e DD_LOGS_ENABLED=true -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true -e
-e DD_API_KEY=<DD_API_KEY> -e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=1 -p 8125:8125/udp datadog/agent:latest

$ docker ps
58afc8d90e04 datadog/agent:latest Up 21 minutes (healthy)>8125/udp, :::8125->8125/udp, 8126/tcp datadog

Step 2) However I ran the sample k6 script after k6 login cloud,
$ k6 run --out statsd samplescript.js
in standalone it captured metrics properly in the default datadog dashboard and k6 run successfully.

Step3) But when I ran the docker k6 container using the below command, even after linking K6 CONTAINER with datadog/agent
it throws below error and none of the metrics are captured in datadog but K6 ran successfully.

$ docker run -i -e “K6_DATADOG_ADDR=datadog:8125” --link datadog:datadog -e K6_CLOUD_TOKEN=<K6_CLOUD_TOKEN_AFTERLOGIN>
-v /home/test/:/test -i loadimpact/k6 run --out statsd --out cloud /test/samplescript.js

time=“2021-06-29T12:29:15Z” level=warning msg=“Couldn’t send 70266 out of 1476642 metrics. Enable debug logging to see individual errors” output=statsd
time=“2021-06-29T12:29:15Z” level=error msg=“Couldn’t flush a batch” error=“write udp> write: connection refused” output=statsd
time=“2021-06-29T12:29:15Z” level=warning msg=“Couldn’t send 921 out of 19366 metrics. Enable debug logging to see individual errors” output=statsd

How to fix 1)the above connection refused error and 2)the location to check logs and 3)enable debugging?

Hi there,

since you’re using the statsd output, you should specify K6_STATSD_ADDR=datadog:8125 instead, which worked in my test.

That said, note that Docker’s --link option is a legacy feature that might be removed, so you’d be better off creating a separate bridge network that both containers connect to (see Networking with standalone containers | Docker Documentation), or starting both containers with a Docker Compose file where you can specify the shared network more easily.

Regarding your 2nd question, which logs do you need? You can redirect k6’s output to a file or use the run --console-output option. If you’re doing this in a container you could save this to a directory on the host with a bind mount.

And which debug information do you need? You can use the --verbose and --http-debug options.

1 Like

This resolved my issue as well with New Relic.
Missing thing was setting K6_STATSD_ADDR in k6 run command.
You don’t need it when you run k6 as a direct binary but when you run it through a container, it needs this key explicitly

After I run

docker run \
  -d --restart unless-stopped \
  --name newrelic-statsd \
  -h $(hostname) \
  -p 8125:8125/udp \

In order for my k6 container to talk to this statsd I should run
K6_STATSD_ADDR=newrelic-statsd:8125 k6 run --out statsd mytest.js

Im trying to run the same but from a Github Actions pipeline, and Its not woking. Its seems that the k6 cant communicate with NR docker port or something like that. Do you have any idea how can I do it? Thanks!

Couldn't flush a batch" error="write udp> write: connection refused" output=statsd