K6_PROMETHEUS_RW_SERVER_URL with token

35 Views Asked by At

Is there any way to pass token to K6_PROMETHEUS_RW_SERVER_URL within header. Running without token like works regarding k6 uses proper rw server:

K6_PROMETHEUS_RW_SERVER_URL=https://uat.org/api/v1/write \                                                                
k6 run -o experimental-prometheus-rw dist/get-all-node-requests-test.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: dist/get-all-node-requests-test.js
        output: Prometheus remote write (https://uat.org/api/v1/write)

     scenarios: (100.00%) 1 scenario, 3 max VUs, 4h22m30s max duration (incl. graceful stop):
              * default: Up to 3 looping VUs for 4h22m0s over 3 stages (gracefulRampDown: 30s, gracefulStop: 30s)


INFO[0000] Wed Mar 13 2024 20:56:58 GMT+0000 (GMT): Response status: 200. Request duration: 137.847  source=console
INFO[0004] Wed Mar 13 2024 20:57:02 GMT+0000 (GMT): Response status: 200. Request duration: 118.392  source=console
ERRO[0006] Failed to send the time series data to the endpoint  error="got status code: 401 instead expected a 2xx successful status code" output="Prometheus remote write"

However I need to provide token in the header.

I tried like it works by curl in vain. Is there any way to pass token to rw server?

Thanks in advance!

************************** RESOLVED **************************

K6_PROMETHEUS_RW_BEARER_TOKEN=<TOKEN> \
K6_PROMETHEUS_RW_SERVER_URL=https://uat.org/api/v1/write \
k6 run -o experimental-prometheus-rw dist/get-all-node-requests-test.js
1

There are 1 best solutions below

0
27P On

To pass a token to RW endpoint works in this way:

K6_PROMETHEUS_RW_BEARER_TOKEN=<TOKEN> \
K6_PROMETHEUS_RW_SERVER_URL=https://uat.org/api/v1/write \
k6 run -o experimental-prometheus-rw dist/get-all-node-requests-test.js