This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from grafana/feat/initial
Add initial k6/x/execution module
- Loading branch information
Showing
10 changed files
with
1,387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Test | ||
on: | ||
# Enable manually triggering this workflow via the API or web UI | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- v* | ||
pull_request: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
env: | ||
GOLANG_CI_VERSION: "1.41.1" | ||
GO111MODULE: 'on' | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16.x | ||
- name: Install golangci-lint | ||
working-directory: /tmp | ||
run: go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANG_CI_VERSION" | ||
- name: Run linters | ||
run: | | ||
golangci-lint run --out-format=tab ./... | ||
test: | ||
strategy: | ||
fail-fast: false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16.x | ||
- name: Run tests | ||
run: | | ||
set -x | ||
go version | ||
export GOMAXPROCS=2 | ||
go test -p 2 -race -timeout 60s ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { sleep } from 'k6'; | ||
import exec from 'k6/x/execution'; | ||
|
||
export let options = { | ||
scenarios: { | ||
shared: { | ||
executor: 'shared-iterations', | ||
vus: 50, | ||
iterations: 500, | ||
}, | ||
rar: { | ||
executor: 'ramping-arrival-rate', | ||
startTime: '10s', | ||
startRate: 20, | ||
timeUnit: '1s', | ||
preAllocatedVUs: 0, | ||
maxVUs: 40, | ||
stages: [ | ||
{ target: 50, duration: '5s' }, | ||
{ target: 0, duration: '5s' }, | ||
], | ||
gracefulStop: '0s', | ||
}, | ||
} | ||
} | ||
|
||
function logObj(msg, o) { | ||
console.log(msg, JSON.stringify(o, Object.keys(o).sort())); | ||
} | ||
|
||
export default function () { | ||
const vuStats = exec.getVUStats(); | ||
const scStats = exec.getScenarioStats(); | ||
const testStats = exec.getTestInstanceStats(); | ||
sleep(1); | ||
logObj('VU stats:', vuStats); | ||
logObj('Scenario stats:', scStats); | ||
logObj('Test stats:', testStats); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: xk6 | ||
on: | ||
# Enable manually triggering this workflow via the API or web UI | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
test-xk6: | ||
strategy: | ||
matrix: | ||
go: [stable, tip] | ||
platform: [ubuntu-latest, windows-latest, macos-latest] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16.x | ||
- name: Install Go tip | ||
if: matrix.go == 'tip' | ||
run: | | ||
go install golang.org/dl/gotip@latest | ||
gotip download | ||
echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV" | ||
echo "GOPATH=$HOME/go" >> "$GITHUB_ENV" | ||
echo "$HOME/go/bin" >> "$GITHUB_PATH" | ||
echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH" | ||
- name: Run tests | ||
run: | | ||
set -x | ||
which go | ||
go version | ||
go install go.k6.io/xk6/cmd/xk6@master | ||
GOPROXY="direct" xk6 build master \ | ||
--output ./k6ext \ | ||
--with github.com/k6io/xk6-execution="$(pwd)" | ||
./k6ext version | ||
./k6ext run --quiet --verbose .github/workflows/xk6-test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# xk6-execution | ||
|
||
A [k6](https://github.com/grafana/k6) JavaScript extension using the | ||
[xk6](https://github.com/grafana/xk6) system that returns information about a | ||
test run including VU, scenario and test statistics. | ||
|
||
| :exclamation: This project is in active development and may break in the future.<br>Please report issues and contribute improvements to help. | | ||
|------| | ||
|
||
|
||
## Build | ||
|
||
To build a `k6` binary with this extension, first ensure you have installed the prerequisites: | ||
|
||
- [Go toolchain](https://go101.org/article/go-toolchain.html) | ||
- Git | ||
|
||
Then: | ||
|
||
1. Install `xk6`: | ||
```shell | ||
go install go.k6.io/xk6/cmd/xk6@latest | ||
``` | ||
|
||
2. Build the binary: | ||
```shell | ||
xk6 build master \ | ||
--with github.com/grafana/xk6-execution | ||
``` | ||
|
||
|
||
## Example | ||
|
||
```javascript | ||
import { sleep } from 'k6'; | ||
import exec from 'k6/x/execution'; | ||
|
||
export let options = { | ||
scenarios: { | ||
shared: { | ||
executor: 'shared-iterations', | ||
vus: 50, | ||
iterations: 500, | ||
} | ||
} | ||
} | ||
|
||
function logObj(msg, o) { | ||
console.log(msg, JSON.stringify(o, Object.keys(o).sort())); | ||
} | ||
|
||
export default function () { | ||
const vuStats = exec.getVUStats(); | ||
const scStats = exec.getScenarioStats(); | ||
const testStats = exec.getTestInstanceStats(); | ||
sleep(1); | ||
logObj('VU stats:', vuStats); | ||
logObj('Scenario stats:', scStats); | ||
logObj('Test stats:', testStats); | ||
} | ||
``` | ||
|
||
Sample output: | ||
|
||
```shell | ||
INFO[0009] VU stats: {"id":36,"idGlobal":36,"iteration":8,"iterationScenario":8} source=console | ||
INFO[0009] Scenario stats: {"executor":"shared-iterations","iteration":429,"iterationGlobal":429,"name":"shared","progress":0.858,"startTime":1624262301.1202478} source=console | ||
INFO[0009] Test stats: {"duration":9035.161124,"iterationsCompleted":429,"iterationsInterrupted":0,"vusActive":50,"vusMax":50} source=console | ||
``` | ||
|
||
|
||
TODO: | ||
- [ ] Document all fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/k6io/xk6-execution | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/dop251/goja v0.0.0-20210817151038-07a7fd9355b4 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/spf13/afero v1.1.2 | ||
github.com/stretchr/testify v1.7.0 | ||
go.k6.io/k6 v0.33.1-0.20210825161650-c932a28ff940 | ||
gopkg.in/guregu/null.v3 v3.3.0 | ||
) |
Oops, something went wrong.