3

I'm trying to use K6 to load test prometheus pushgateway and it wants posts in the following format.

http_request_duration_seconds_bucket{le="0.05"} 24054
http_request_duration_seconds_bucket{le="0.1"} 33444
http_request_duration_seconds_bucket{le="0.2"} 100392

there has to be a linefeed at the end of each line (and one extra at the end) - however I seem to only get url encoded strings like %20 for space etc. Is it possible somehow to post raw strings?

1 Answers1

1

If you just construct the body as a string yourself and pass it that way to http.post(), it should be sent as-is, without any modifications. This code should illustrate this, using httpbin.org:

import http from "k6/http";
import crypto from "k6/crypto";

let payload = `http_request_duration_seconds_bucket{le="0.05"} 24054
http_request_duration_seconds_bucket{le="0.1"} 33444
http_request_duration_seconds_bucket{le="0.2"} 100392
`;

export default function (data) {
    console.log(crypto.sha256(payload, "hex"));
    let resp = http.post("https://httpbin.org/anything", payload);
    console.log(crypto.sha256(resp.json().data, "hex"));
    console.log(resp.body);
}

it will output something like this:

INFO[0000] 773f0d81713fca0663ad7a01135bf674b93b0859854b2248368125af3f070d29 
INFO[0001] 773f0d81713fca0663ad7a01135bf674b93b0859854b2248368125af3f070d29 
INFO[0001] {
  "args": {}, 
  "data": "http_request_duration_seconds_bucket{le=\"0.05\"} 24054\nhttp_request_duration_seconds_bucket{le=\"0.1\"} 33444\nhttp_request_duration_seconds_bucket{le=\"0.2\"} 100392\n", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Connection": "close", 
    "Content-Length": "161", 
    "Host": "httpbin.org", 
    "User-Agent": "k6/0.23.1 (https://k6.io/)"
  }, 
  "json": null, 
  "method": "POST", 
  "url": "https://httpbin.org/anything"
}

na--
  • 1,016
  • 7
  • 9