Skip to content

Allow trends to be recorded as histograms instead of summaries via options argument - #20

Draft
ahinh43 wants to merge 5 commits into
szkiba:mainfrom
ahinh43:main
Draft

Allow trends to be recorded as histograms instead of summaries via options argument#20
ahinh43 wants to merge 5 commits into
szkiba:mainfrom
ahinh43:main

Conversation

@ahinh43

@ahinh43 ahinh43 commented Dec 12, 2025

Copy link
Copy Markdown

Closes #17

This PR adds the ability to optionally record trend metrics as Prometheus Histograms instead of Summary types. This is controlled with a new option argument named -o usehistogramfortime=yes (name suggestions are welcome 😅)

This can be tested by passing the argument into the K6 binary when calling it after build:

Command:

./k6 run -o 'prometheus=usehistogramfortime=yes' script.js

Which then the metrics endpoint will output this example in the trend related metrics

# TYPE http_req_duration histogram
...
http_req_duration_bucket{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",le="2.5"} 0
http_req_duration_bucket{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",le="5"} 0
...
http_req_duration_bucket{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",le="+Inf"} 2

If you don't pass usehistogramfortime=yes then the default summary type is still used.

Command:

./k6 run -o prometheus script.js

Output:

# TYPE http_req_duration summary
http_req_duration{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",quantile="0.5"} 31.079
http_req_duration{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",quantile="0.9"} 32.001
http_req_duration{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",quantile="0.95"} 32.001
http_req_duration{expected_response="true",group="",method="GET",name="http://test.k6.io",proto="HTTP/1.1",scenario="default",status="301",tls_version="",url="http://test.k6.io",quantile="1"} 32.001

I've updated the README where I thought would be necessary but if there's any other places that should be updated please let me know. Thanks!

Signed-off-by: Alec Hinh <alec.hinh@zapier.com>
Signed-off-by: Alec Hinh <alec.hinh@zapier.com>
Signed-off-by: Alec Hinh <alec.hinh@zapier.com>
Signed-off-by: Alec Hinh <alec.hinh@zapier.com>
Signed-off-by: Alec Hinh <alec.hinh@zapier.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optionally Recording time metrics as Prometheus Histograms

1 participant