Integrating NewRelic with K6 in kubernetes cluster
k6 is the leading load testing engine developed for the engineering teams. With load test execution in place, it is equally important and critical to have reliable result visualisation. K6 supports many integrations for visualising the data and metrics. Reference
However, here specifically we will focus on, how teams can integrate NewRelic with k6 if whole setup is deployed in kubernetes cluster and visualise the results by preparing k6 dashboards in New Relic.
k6 can send the telemetry data to NewRelic via NewRelic StatsD Integration. Capillary engineering team uses NewRelic extensively for monitoring applications, having performance tests numbers as a NewRelic dashboards is something like “icing on the cake”.
To have this integration to work, we would need to deploy the NewRelic StatsD in k8s cluster that will send the telemetry data to NewRelic server.
Let’s get into it!
First create the config map that will set the configurations for nri-statsd via a “toml” file as following yaml.
nri-statsd is an open source project for “StatsD integration for New Relic”.
“address” and “address-metrics” will contain the event endpoint and metrics endpoint of newRelic.The “api-key” and the “newRelic-accountid” is the actual api key and account id of NewRelic server.
Next is to create a “deployment” for NewRelic StatsD, that will typically use the above config map and uses the latest image “newrelic/nri-statsd:latest” in the container. Following is the yaml.
The environment variables “NR_ACCOUNT_ID”, “NR_API_KEY” has to be set with valid NewRelic api-key and account_id. This can also be added to configMap to use in deployment. The “replicas” and “port” can be customised based on requirement.
Further step would be to create a clusterIP service that will open the connection to StatsD deployment/pods. Following is the yaml.
Exposed service port can be any valid port but protocol has to be UDP, as NewRelic StatsD uses UDP.
To access the configuration files visit the git project here.
Apply the above objects to K8s cluster in sequence, or just create a script for it.
Perfect!! NewRelic StatsD is running via UDP with endpoint “newrelic-statsd-svc:80”. Now to use the StatsD to send the data from k6 to NewRelic server, we would need to use “statsd” as an output and “K6_STATSD_ADDR” as “newrelic-statsd-svc:80” while executing k6 script, as follows —
k6 run --out statsd --env K6_STATSD_ADDR=newrelic-statsd-svc:80
Once this setup is done, k6 will be sending the performance metrics to the New Relic StatsD integration which in turn is sending these metrics to the New Relic Telemetry Data Platform. These will be prefixed with “k6”. So we can search the metrics inside “Data Explorer” as follows
And eventually you can add all the required k6 metrics to the NewRelic Dashboard. For example as below
Hope this helps and provide ease in setting up NewRelic for k6 in K8s cluster, Further there is an interesting setup that Capillary uses to run the load tests in distributed way which is very much needed for any engineering teams to test the system at scale. The “What” and “How” of the setup and architecture of such solution in K8s cluster will come up in next part of this.
Stay Tuned :)