From bf43bdfccb411b994ef7abc21cacbc346e2de93b Mon Sep 17 00:00:00 2001 From: John Anderson Date: Mon, 2 Jan 2023 17:14:04 -0400 Subject: [PATCH 1/3] Add a k6.io benchmark --- benchmarking/README.md | 7 ++++++ benchmarking/perf1.js | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 benchmarking/README.md create mode 100644 benchmarking/perf1.js diff --git a/benchmarking/README.md b/benchmarking/README.md new file mode 100644 index 0000000..f23a5be --- /dev/null +++ b/benchmarking/README.md @@ -0,0 +1,7 @@ +# Benchmarking +We are using [k6](https://k6.io/) for our benchmarking. To run one of the performance +tests you can do: + +``` +k6 run -e PAG_HOST=http://localhost --vus 10 --duration 30s benchmarking/perf1.js +``` \ No newline at end of file diff --git a/benchmarking/perf1.js b/benchmarking/perf1.js new file mode 100644 index 0000000..5d3f01d --- /dev/null +++ b/benchmarking/perf1.js @@ -0,0 +1,55 @@ +import http from 'k6/http'; +import { check } from 'k6'; + + +const jobs = [ + "job1", + "job2", + "job3", + "job4", +] + +const labels = [ + "foo", + "bar", + "baz", +] + + +const labelValues = [ + "qux", + "fred", + "thud", +] + +function getRandInteger(min, max) { + return Math.floor(Math.random() * (max - min) ) + min; +} + +export default function () { + const randomJob = jobs[Math.floor(Math.random() * jobs.length)]; + const randomLabel = labels[Math.floor(Math.random() * labels.length)]; + const randomValue = labelValues[Math.floor(Math.random() * labelValues.length)]; + const url = `${__ENV.PAG_HOST}/metrics/job/${randomJob}/${randomLabel}/${randomValue}`; + const randomMetric1 = getRandInteger(1, 50) + const randomMetric2 = getRandInteger(1000, 3000) + const randomMetric3 = getRandInteger(3000, 4000) + + const payload = ` + # TYPE some_metric counter + some_metric{label="val1"} ${randomMetric1} + # TYPE another_metric gauge + # HELP another_metric Just an example. + another_metric ${randomMetric2} + k6_http_requests_total{method="post",code="200"} ${randomMetric3} + ` + + const params = { + headers: { + 'Content-Type': 'application/json', + }, + }; + + const res = http.post(url, payload, params); + check(res, { 'status was 202': (r) => r.status < 300 }); +} From 585ecbf9f9701bc53486f57c912bced4a21b8535 Mon Sep 17 00:00:00 2001 From: John Anderson Date: Mon, 2 Jan 2023 17:38:49 -0400 Subject: [PATCH 2/3] refactor the choice code --- benchmarking/perf1.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/benchmarking/perf1.js b/benchmarking/perf1.js index 5d3f01d..8c6aab8 100644 --- a/benchmarking/perf1.js +++ b/benchmarking/perf1.js @@ -26,10 +26,15 @@ function getRandInteger(min, max) { return Math.floor(Math.random() * (max - min) ) + min; } +function randChoice(arr) { + return arr[Math.floor(Math.random() * arr.length)]; +} + export default function () { - const randomJob = jobs[Math.floor(Math.random() * jobs.length)]; - const randomLabel = labels[Math.floor(Math.random() * labels.length)]; - const randomValue = labelValues[Math.floor(Math.random() * labelValues.length)]; + const randomJob = randChoice(jobs); + const randomLabel = randChoice(labels); + const randomValue = randChoice(labelValues); + const url = `${__ENV.PAG_HOST}/metrics/job/${randomJob}/${randomLabel}/${randomValue}`; const randomMetric1 = getRandInteger(1, 50) const randomMetric2 = getRandInteger(1000, 3000) @@ -51,5 +56,5 @@ export default function () { }; const res = http.post(url, payload, params); - check(res, { 'status was 202': (r) => r.status < 300 }); + check(res, { 'status was 200ish': (r) => r.status < 300 }); } From a994323aad023d4db4f52fb9c93956c0a6b8db58 Mon Sep 17 00:00:00 2001 From: John Anderson Date: Mon, 2 Jan 2023 17:56:49 -0400 Subject: [PATCH 3/3] add a no label benchmark --- benchmarking/README.md | 2 +- benchmarking/{perf1.js => labels.js} | 0 benchmarking/no_labels.js | 36 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) rename benchmarking/{perf1.js => labels.js} (100%) create mode 100644 benchmarking/no_labels.js diff --git a/benchmarking/README.md b/benchmarking/README.md index f23a5be..36e8ec6 100644 --- a/benchmarking/README.md +++ b/benchmarking/README.md @@ -3,5 +3,5 @@ We are using [k6](https://k6.io/) for our benchmarking. To run one of the perfor tests you can do: ``` -k6 run -e PAG_HOST=http://localhost --vus 10 --duration 30s benchmarking/perf1.js +k6 run -e PAG_HOST=http://localhost --vus 10 --duration 30s benchmarking/labels.js ``` \ No newline at end of file diff --git a/benchmarking/perf1.js b/benchmarking/labels.js similarity index 100% rename from benchmarking/perf1.js rename to benchmarking/labels.js diff --git a/benchmarking/no_labels.js b/benchmarking/no_labels.js new file mode 100644 index 0000000..072718a --- /dev/null +++ b/benchmarking/no_labels.js @@ -0,0 +1,36 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +function getRandInteger(min, max) { + return Math.floor(Math.random() * (max - min) ) + min; +} + +/* +Original prom-agg-gateway doesn't support labels so this perf test +is here mostly to compare against them. +*/ +export default function () { + const url = `${__ENV.PAG_HOST}/metrics/`; + + const randomMetric1 = getRandInteger(1, 50) + const randomMetric2 = getRandInteger(1000, 3000) + const randomMetric3 = getRandInteger(3000, 4000) + + const payload = ` + # TYPE some_metric counter + some_metric{label="val1"} ${randomMetric1} + # TYPE another_metric gauge + # HELP another_metric Just an example. + another_metric ${randomMetric2} + k6_http_requests_total{method="post",code="200"} ${randomMetric3} + ` + + const params = { + headers: { + 'Content-Type': 'application/json', + }, + }; + + const res = http.post(url, payload, params); + check(res, { 'status was 200ish': (r) => r.status < 300 }); +}