Skip to content

Commit

Permalink
Refactor extension
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel González Lopes <[email protected]>
  • Loading branch information
dgzlopes committed Sep 27, 2021
1 parent 69900e2 commit 34ccbe8
Show file tree
Hide file tree
Showing 1,169 changed files with 1,364 additions and 566,700 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
k6
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# xk6-remote-write

This is a [k6](https://go.k6.io/k6) extension using the [xk6](https://github.com/grafana/xk6) system.

| :exclamation: This is a proof of concept, isn't supported by the k6 team, and may break in the future. USE AT YOUR OWN RISK! |
|------|
This is a [k6](https://go.k6.io/k6) extension developed using the [xk6](https://github.com/grafana/xk6) system.

## Build

Expand Down Expand Up @@ -36,16 +33,21 @@ export let options = {
};

const client = new remote.Client({
endpoint: "<your-remote-write-endpoint>"
url: "<your-remote-write-url>"
});

export default function () {
let res = client.storeNow({
"__name__": `foo_bar${__VU}`,
"foo": "bar"
}, Math.random() * 100)
let res = client.store([{
"labels": [
{ "name": "__name__", "value": `my_cool_metric_${__VU}` },
{ "name": "service", "value": "bar" }
],
"samples": [
{ "value": Math.random() * 100, }
]
}]);
check(res, {
'is status 200': (r) => r.status === 200,
'is status 200': (r) => r.status_code === 200,
});
sleep(1)
}
Expand All @@ -54,7 +56,7 @@ export default function () {
Result output:

```
$ ./k6 run example.js
$ ./k6 run examples/basic.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
Expand All @@ -63,7 +65,7 @@ $ ./k6 run example.js
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: ../example.js
script: examples/basic.js
output: -
scenarios: (100.00%) 1 scenario, 10 max VUs, 40s max duration (incl. graceful stop):
Expand All @@ -75,13 +77,14 @@ default ✓ [======================================] 10 VUs 10s
✓ is status 200
checks......................: 100.00% ✓ 90 ✗ 0
checks......................: 100.00% ✓ 90 ✗ 0
data_received...............: 0 B 0 B/s
data_sent...................: 18 EB 18 EB/s
iteration_duration..........: avg=1.14s min=1.12s med=1.13s max=1.25s p(90)=1.23s p(95)=1.25s
iterations..................: 90 8.672493/s
remote_write_req_duration...: avg=145.77ms min=129ms med=132ms max=253ms p(90)=236.1ms p(95)=251.1ms
remote_write_req_total......: 90 8.672493/s
vus.........................: 10 min=10 max=10
vus_max.....................: 10 min=10 max=10
data_sent...................: 6.2 kB 596 B/s
iteration_duration..........: avg=1.14s min=1.13s med=1.13s max=1.26s p(90)=1.23s p(95)=1.24s
iterations..................: 90 8.624555/s
remote_write_num_series.....: 90 8.624555/s
remote_write_req_duration...: avg=146.62ms min=129ms med=132ms max=260ms p(90)=231ms p(95)=242.1ms
remote_write_reqs...........: 90 8.624555/s
vus.........................: 10 min=10 max=10
vus_max.....................: 10 min=10 max=10
```
22 changes: 0 additions & 22 deletions example.js

This file was deleted.

64 changes: 64 additions & 0 deletions examples/advanced.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { check, sleep } from 'k6';
import remote from 'k6/x/remotewrite';

export let options = {
scenarios: {
sendBatch: {
executor: 'constant-vus',
exec: 'sendBatch',
vus: 10,
duration: '1m',
},
increaseCounter: {
executor: 'constant-vus',
exec: 'increaseCounter',
vus: 1,
duration: '1m',
},
}
};

const client = new remote.Client({
url: "<your-remote-write-url>",
});

export function increaseCounter() {
let res = client.store([{
"labels": [
{ "name": "__name__", "value": `my_happy_metric_total` },
],
"samples": [
{ "value": __ITER, }
]
},
]);
check(res, {
'is status 200': (r) => r.status_code === 200,
});
sleep(10);
}
export function sendBatch() {
let res = client.store([{
"labels": [
{ "name": "__name__", "value": `my_cool_metric_${__VU}` },
{ "name": "service", "value": "bar" }
],
"samples": [
{ "value": Math.random() * 100, }
]
},
{
"labels": [
{ "name": "__name__", "value": `my_fancy_metric_${__VU}` },
],
"samples": [
{ "value": Math.random() * 100 },
{ "value": Math.random() * 100 }
]
}
]);
check(res, {
'is status 200': (r) => r.status_code === 200,
});
sleep(1)
}
27 changes: 27 additions & 0 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { check, sleep } from 'k6';
import remote from 'k6/x/remotewrite';

export let options = {
vus: 10,
duration: '10s',
};

const client = new remote.Client({
url: "<your-remote-write-url>"
});

export default function () {
let res = client.store([{
"labels": [
{ "name": "__name__", "value": `my_cool_metric_${__VU}` },
{ "name": "service", "value": "bar" }
],
"samples": [
{ "value": Math.random() * 100, }
]
}]);
check(res, {
'is status 200': (r) => r.status_code === 200,
});
sleep(1)
}
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ module github.com/dgzlopes/xk6-remote-write
go 1.15

require (
github.com/dgzlopes/prometheus_remote_client_golang v0.4.7
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.3
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/onsi/ginkgo v1.15.0 // indirect
github.com/onsi/gomega v1.10.5 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/prometheus v1.8.2-0.20210621150501-ff58416a0b02
go.k6.io/k6 v0.32.0
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
Loading

0 comments on commit 34ccbe8

Please sign in to comment.