Skip to content

Commit

Permalink
Merge pull request #124 from grafana/feature/moving-subcommands
Browse files Browse the repository at this point in the history
Moving subcommands to separate executable
  • Loading branch information
szkiba authored Dec 20, 2023
2 parents fb37deb + 6a2aa16 commit 99a6146
Show file tree
Hide file tree
Showing 21 changed files with 491 additions and 163 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 Raintank, Inc. dba Grafana Labs
#
# SPDX-License-Identifier: AGPL-3.0-only

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: "1.21"
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: License Check
uses: fsfe/reuse-action@v2

- name: Lint
uses: magefile/mage-action@v1
uses: magefile/mage-action@v3
with:
version: latest
args: tools lint
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2023 Raintank, Inc. dba Grafana Labs
#
# SPDX-License-Identifier: AGPL-3.0-only

name: release-cli
on:
push:
tags:
- "v*"
permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: "1.22.0"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build
id: build
uses: szkiba/xk6bundler@v0
Expand All @@ -39,15 +39,15 @@ jobs:
files: dist/*.tar.gz

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
Expand All @@ -56,7 +56,7 @@ jobs:
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
context: ./${{ steps.build.outputs.dockerdir }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# SPDX-License-Identifier: MIT

/k6
/k6.exe
/k6-web-dashboard
/k6-web-dashboard.exe
/build
/.bin
/.hintrc
41 changes: 41 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2023 Raintank, Inc. dba Grafana Labs
#
# SPDX-License-Identifier: AGPL-3.0-only

project_name: k6-web-dashboard
before:
hooks:
- go mod tidy
dist: build/dist
builds:
- env:
- CGO_ENABLED=0
goos: ["darwin", "linux", "windows"]
goarch: ["amd64"]
ldflags:
- "-s -w -X {{.ModulePath}}/cmd.version={{.Version}} -X {{.ModulePath}}/cmd.appname={{.ProjectName}}"
dir: cmd/k6-web-dashboard
source:
enabled: false

archives:
- id: bundle
format: tar.gz
format_overrides:
- goos: windows
format: zip

checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"

snapshot:
name_template: "{{ incpatch .Version }}-next+{{.ShortCommit}}{{if .IsGitDirty}}.dirty{{else}}{{end}}"

changelog:
sort: asc
abbrev: -1
filters:
exclude:
- "^chore:"
- "^docs:"
- "^test:"
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,3 @@ repos:
rev: v1.54.1
hooks:
- id: golangci-lint

- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-mod-tidy
- id: go-build-mod
# - id: go-test-mod
93 changes: 3 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,97 +217,10 @@ Two kind of events will be emitted:
## Command Line
The xk6-dashboard extension adds a `web-dashboard` command to the k6 command line:
> [!Warning]
> Previous versions of xk6-dashboard added a `dashboard` subcommand to the k6 command line. Currently k6 does not support adding subcommands, xk6-dashboard used a questionable workaround. This workaround was removed from the xk6-dashboard and the dashboard-related subcommands were moved to a separate executable ([k6-web-dashboard](cmd/k6-web-dashboard/README.md)).
```sh
$ ./k6 web-dashboard --help
xk6-dashboard commands
Usage:
k6 web-dashboard [command]
Available Commands:
aggregate convert saved json output to recorded dashboard events
replay load the recorded dashboard events and replay it for the UI
report create report from a recorded event file
Flags:
-h, --help help for dashboard
Use "k6 web-dashboard [command] --help" for more information about a command.
```
At the moment, the `dashboard` command has three subcommand, `replay` (which can be used to play back dashboard events previously saved with `record` parameter), `aggregate` (which can be used to convert test run results previously saved in JSON format from k6 to dashboard events format NDJSON) and `report` (which can be used to generate report from dashboard events previously saved with `record` parameter).
```sh
$ ./k6 web-dashboard replay --help
The replay command load the recorded dashboard events (NDJSON format) and replay it for the dashboard UI.
The compressed file will be automatically decompressed if the file extension is .gz
Usage:
k6 web-dashboard replay file [flags]
Flags:
--host string Hostname or IP address for HTTP endpoint (default: '', empty, listen on all interfaces)
--open Open browser window automatically
--port int TCP port for HTTP endpoint (0=random, -1=no HTTP), example: 8080 (default 5665)
--export string Report file location (default: '', no report)
-h, --help help for replay
```
```
$ ./k6 web-dashboard aggregate --help
The aggregate command converts the file saved by json output to dashboard format events file.
The files will be automatically compressed/decompressed if the file extension is .gz
Usage:
k6 web-dashboard aggregate input-file output-file [flags]
Flags:
--period 1m Event emitting frequency, example: 1m (default 10s)
--tags strings Precomputed metric tags, can be specified more than once (default [group])
-h, --help help for aggregate
```
```
$ ./k6 web-dashboard report --help
The report command loads recorded dashboard events (NDJSON format) and creates a report.
The compressed events file will be automatically decompressed if the file extension is .gz
Usage:
k6 web-dashboard report events-file report-file [flags]
Flags:
--open Open browser window with generated report
-h, --help help for report
```
To visualize the result of a previous test run (using events file):
```
./k6 run --out dashboard=record=test_result.ndjson script.js
./k6 web-dashboard replay test_result.ndjson
```
To visualize the result of a previous test run (using json output):
```sh
./k6 run --out json=test_result.json script.js
./k6 web-dashboard aggregate test_result.json test_result.ndjson
./k6 web-dashboard replay test_result.ndjson
```
To generate report from previous test run (using events file):
```
./k6 run --out web-dashboard=record=test_result.ndjson script.js
./k6 web-dashboard report test_result.ndjson test_result_report.html
```
The CLI tool called [k6-web-dashboard](cmd/k6-web-dashboard/README.md) enables the use of subcommands related to dashboard management (recording playback, creating a report from a recording, etc.) that do not require running k6.
### Docker
Expand Down
Loading

0 comments on commit 99a6146

Please sign in to comment.