Skip to content

Commit

Permalink
Merge pull request #48 from zapier/add-k6-benchmark
Browse files Browse the repository at this point in the history
Add a k6.io benchmark
  • Loading branch information
sontek authored Jan 2, 2023
2 parents 886a10d + 1da6c30 commit 4ae121d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
7 changes: 7 additions & 0 deletions benchmarking/README.md
Original file line number Diff line number Diff line change
@@ -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/labels.js
```
60 changes: 60 additions & 0 deletions benchmarking/labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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;
}

function randChoice(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}

export default function () {
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)
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 });
}
36 changes: 36 additions & 0 deletions benchmarking/no_labels.js
Original file line number Diff line number Diff line change
@@ -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 });
}

0 comments on commit 4ae121d

Please sign in to comment.