Skip to content

Commit 6e18fb7

Browse files
authored
Merge pull request #114 from grafana/feature/113-rename-report-parameter-to-export
feat: Rename "report" parameter to "export"
2 parents 7eb24d0 + a9754b2 commit 6e18fb7

File tree

8 files changed

+59
-35
lines changed

8 files changed

+59
-35
lines changed

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ See [sample HTML report](screenshot/k6-dashboard-html-report.html) or try the [o
5757
- [Usage](#usage)
5858
- [Exit](#exit)
5959
- [Parameters](#parameters)
60+
- [Environment](#environment)
6061
- [Docker](#docker)
6162
- [Save report](#save-report)
6263
- [Events](#events)
@@ -130,10 +131,27 @@ host | Hostname or IP address for HTTP endpoint (default: "", empty, listen
130131
port | TCP port for HTTP endpoint (default: `5665`; `0` = random, `-1` = no HTTP), example: `8080`
131132
period | Event emitting frequency (default: `10s`), example: `1m`
132133
open | Set to `true` (or empty) to open the browser window automatically
133-
report | File name to save the report (default: "", empty, the report will not be saved)
134+
export | File name to save the report (default: "", empty, the report will not be saved)
134135
record | File name to save the dashboard events (default: "", empty, the events will not be saved)
135136
tag | Precomputed metric tag name(s) (default: "group"), can be specified more than once
136137

138+
*The `export` parameter used to be `report`, for compatibility reasons the name `report` can still be used.*
139+
140+
## Environment
141+
142+
The dashboard parameters can also be specified in environment variables. The name of the environment variable belonging to the given parameter is created by converting the parameter name to uppercase and adding the `K6_WEB_DASHBOARD_` prefix.
143+
144+
environment variable | description
145+
----------|------------
146+
K6_WEB_DASHBOARD_HOST | Hostname or IP address for HTTP endpoint (default: "", empty, listen on all interfaces)
147+
K6_WEB_DASHBOARD_PORT | TCP port for HTTP endpoint (default: `5665`; `0` = random, `-1` = no HTTP), example: `8080`
148+
K6_WEB_DASHBOARD_PERIOD | Event emitting frequency (default: `10s`), example: `1m`
149+
K6_WEB_DASHBOARD_OPEN | Set to `true` (or empty) to open the browser window automatically
150+
K6_WEB_DASHBOARD_EXPORT | File name to save the report (default: "", empty, the report will not be saved)
151+
K6_WEB_DASHBOARD_RECORD | File name to save the dashboard events (default: "", empty, the events will not be saved)
152+
K6_WEB_DASHBOARD_TAG | Precomputed metric tag name(s) (default: "group"), can be specified more than once
153+
154+
137155
## Docker
138156

139157
You can also use pre-built k6 image within a Docker container. In order to do that you will need to execute something like the following:
@@ -154,20 +172,20 @@ The dashboard will accessible on port `5665` with any web browser: http://127.0.
154172

155173
## Save report
156174

157-
The test run report can be exported to a responsive self-contained HTML file. For export, the file name must be specified in the `report` parameter. If the file name ends with `.gz`, the HTML report will automatically be gzip compressed.
175+
The test run report can be exported to a responsive self-contained HTML file. For export, the file name must be specified in the `export` parameter. If the file name ends with `.gz`, the HTML report will automatically be gzip compressed.
158176

159177
```plain
160-
k6 run --out dashboard=report=test-report.html script.js
178+
k6 run --out dashboard=export=test-report.html script.js
161179
```
162180

163181
The exported HTML report file does not contain external dependencies, so it can be displayed even without an Internet connection. Graphs can be zoomed by selecting a time interval. If necessary, the report can be printed or converted to PDF format.
164182

165-
By using the `--report` switch of the `dashboard replay` command, the report can also be generated afterwards from the previously saved JSON format result (`--out json=test-result.json`).
183+
By using the `--export` switch of the `dashboard replay` command, the report can also be generated afterwards from the previously saved JSON format result (`--out json=test-result.json`).
166184

167185
The report can also be viewed and downloaded from the dashboard UI using the buttons on the "Report" tab.
168186

169187
```plain
170-
k6 dashboard replay --report test-report.html test-result.json
188+
k6 dashboard replay --export test-report.html test-result.json
171189
```
172190

173191
*Example HTML report*
@@ -229,7 +247,7 @@ Flags:
229247
--host string Hostname or IP address for HTTP endpoint (default: '', empty, listen on all interfaces)
230248
--open Open browser window automatically
231249
--port int TCP port for HTTP endpoint (0=random, -1=no HTTP), example: 8080 (default 5665)
232-
--report string Report file location (default: '', no report)
250+
--export string Report file location (default: '', no report)
233251
-h, --help help for replay
234252
```
235253

dashboard/command.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
flagPort = "port"
2323
flagPeriod = "period"
2424
flagOpen = "open"
25-
flagReport = "report"
25+
flagExport = "export"
2626
flagTags = "tags"
2727
)
2828

@@ -98,9 +98,9 @@ The compressed file will be automatically decompressed if the file extension is
9898
)
9999
flags.BoolVar(&opts.Open, flagOpen, defaultOpen, "Open browser window automatically")
100100
flags.StringVar(
101-
&opts.Report,
102-
flagReport,
103-
defaultReport,
101+
&opts.Export,
102+
flagExport,
103+
defaultExport,
104104
"Report file location (default: '', no report)",
105105
)
106106

@@ -151,7 +151,7 @@ The compressed events file will be automatically decompressed if the file extens
151151
Args: cobra.ExactArgs(2),
152152
RunE: func(cmd *cobra.Command, args []string) error {
153153
opts.Port = -1
154-
opts.Report = args[1]
154+
opts.Export = args[1]
155155

156156
if err := replay(args[0], opts, assets, proc); err != nil {
157157
return err

dashboard/extension.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (ext *extension) Start() error {
100100
ext.addEventListener(newRecorder(ext.options.Record, ext.proc))
101101
}
102102

103-
brf := newReporter(ext.options.Report, ext.assets, ext.proc)
103+
brf := newReporter(ext.options.Export, ext.assets, ext.proc)
104104

105105
ext.addEventListener(brf)
106106

dashboard/options.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
defaultPort = 5665
2222
defaultPeriod = time.Second * 10
2323
defaultOpen = false
24-
defaultReport = ""
24+
defaultExport = ""
2525
defaultRecord = ""
2626
)
2727

@@ -32,7 +32,7 @@ type options struct {
3232
Host string
3333
Period time.Duration
3434
Open bool
35-
Report string
35+
Export string
3636
Record string
3737
Tags []string
3838
TagsS string
@@ -44,7 +44,7 @@ func envopts(env map[string]string) (*options, error) {
4444
Host: defaultHost,
4545
Period: defaultPeriod,
4646
Open: defaultOpen,
47-
Report: defaultReport,
47+
Export: defaultExport,
4848
Record: defaultRecord,
4949
Tags: defaultTags(),
5050
TagsS: "",
@@ -67,8 +67,10 @@ func envopts(env map[string]string) (*options, error) {
6767
opts.Host = v
6868
}
6969

70-
if v, ok := env[envReport]; ok {
71-
opts.Report = v
70+
if v, ok := env[envExport]; ok {
71+
opts.Export = v
72+
} else if v, ok := env[envReport]; ok {
73+
opts.Export = v
7274
}
7375

7476
if v, ok := env[envRecord]; ok {
@@ -123,8 +125,10 @@ func getopts(query string, env map[string]string) (*options, error) {
123125
opts.Host = v
124126
}
125127

126-
if v := value.Get(paramReport); len(v) != 0 {
127-
opts.Report = v
128+
if v := value.Get(paramExport); len(v) != 0 {
129+
opts.Export = v
130+
} else if v := value.Get(paramReport); len(v) != 0 {
131+
opts.Export = v
128132
}
129133

130134
if v := value.Get(paramRecord); len(v) != 0 {
@@ -211,6 +215,8 @@ const (
211215

212216
paramReport = "report"
213217
envReport = envPrefix + "REPORT"
218+
paramExport = "export"
219+
envExport = envPrefix + "EXPORT"
214220

215221
paramRecord = "record"
216222
envRecord = envPrefix + "RECORD"

dashboard/options_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Test_getopts_defaults(t *testing.T) {
2828
assert.Equal(t, defaultPort, opts.Port)
2929
assert.Equal(t, defaultPeriod, opts.Period)
3030
assert.Equal(t, defaultOpen, opts.Open)
31-
assert.Equal(t, defaultReport, opts.Report)
31+
assert.Equal(t, defaultExport, opts.Export)
3232
assert.Equal(t, defaultTags(), opts.Tags)
3333

3434
assert.Equal(
@@ -54,7 +54,7 @@ func Test_getopts_env(t *testing.T) {
5454
envHost: "example.com",
5555
envPeriod: "1h",
5656
envRecord: "results.data",
57-
envReport: "report.html",
57+
envExport: "report.html",
5858
envTags: "foo,bar",
5959
envOpen: "true",
6060
}
@@ -68,7 +68,7 @@ func Test_getopts_env(t *testing.T) {
6868
assert.Equal(t, 1, opts.Port)
6969
assert.Equal(t, time.Hour, opts.Period)
7070
assert.Equal(t, true, opts.Open)
71-
assert.Equal(t, "report.html", opts.Report)
71+
assert.Equal(t, "report.html", opts.Export)
7272
assert.Equal(t, []string{"foo", "bar"}, opts.Tags)
7373

7474
assert.Equal(t, "http://example.com:1", opts.url())
@@ -82,21 +82,21 @@ func Test_getopts(t *testing.T) {
8282
envHost: "example.net",
8383
envPeriod: "2h",
8484
envRecord: "results.data",
85-
envReport: "final.html",
85+
envExport: "final.html",
8686
envTags: "foo,bar",
8787
envOpen: "true",
8888
}
8989

9090
opts, err := getopts(
91-
"period=1s&port=1&host=localhost&open&report=report.html&tag=foo&tag=bar",
91+
"period=1s&port=1&host=localhost&open&export=report.html&tag=foo&tag=bar",
9292
env,
9393
)
9494

9595
assert.NoError(t, err)
9696
assert.Equal(t, time.Second, opts.Period)
9797
assert.Equal(t, 1, opts.Port)
9898
assert.True(t, opts.Open)
99-
assert.Equal(t, "report.html", opts.Report)
99+
assert.Equal(t, "report.html", opts.Export)
100100
assert.Equal(t, "localhost", opts.Host)
101101
assert.Equal(t, "http://localhost:1", opts.url())
102102
assert.Equal(t, "localhost:1", opts.addr())

dashboard/replay.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func replay(input string, opts *options, assets *assets, proc *process) error {
5858
}
5959

6060
func (rep *replayer) run() error {
61-
rptr := newReporter(rep.options.Report, rep.assets, rep.proc)
61+
rptr := newReporter(rep.options.Export, rep.assets, rep.proc)
6262

6363
rep.addEventListener(rptr)
6464

dashboard/replay_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Test_replay(t *testing.T) {
2828
Host: "127.0.0.1",
2929
Period: time.Second,
3030
Open: false,
31-
Report: "",
31+
Export: "",
3232
Tags: nil,
3333
TagsS: "",
3434
}
@@ -50,7 +50,7 @@ func Test_replay_gz(t *testing.T) {
5050
Host: "127.0.0.1",
5151
Period: time.Second,
5252
Open: false,
53-
Report: "",
53+
Export: "",
5454
Tags: nil,
5555
TagsS: "",
5656
}
@@ -70,7 +70,7 @@ func Test_replay_open(t *testing.T) { //nolint:paralleltest
7070
Host: "127.0.0.1",
7171
Period: time.Second,
7272
Open: true,
73-
Report: "",
73+
Export: "",
7474
Tags: nil,
7575
TagsS: "",
7676
}
@@ -90,7 +90,7 @@ func Test_replay_error_port_used(t *testing.T) { //nolint:paralleltest
9090
Host: "127.0.0.1",
9191
Period: time.Second,
9292
Open: false,
93-
Report: "",
93+
Export: "",
9494
Tags: nil,
9595
TagsS: "",
9696
}
@@ -101,17 +101,17 @@ func Test_replay_error_port_used(t *testing.T) { //nolint:paralleltest
101101
assert.Error(t, replay("testdata/result.ndjson.gz", opts, th.assets, th.proc))
102102
}
103103

104-
func Test_replay_report(t *testing.T) {
104+
func Test_replay_export(t *testing.T) {
105105
t.Parallel()
106106

107-
report := filepath.Join(t.TempDir(), "report.html")
107+
export := filepath.Join(t.TempDir(), "report.html")
108108

109109
opts := &options{
110110
Port: -1,
111111
Host: "",
112112
Period: time.Second,
113113
Open: false,
114-
Report: report,
114+
Export: export,
115115
Tags: nil,
116116
TagsS: "",
117117
}
@@ -120,7 +120,7 @@ func Test_replay_report(t *testing.T) {
120120

121121
assert.NoError(t, replay("testdata/result.ndjson.gz", opts, th.assets, th.proc))
122122

123-
st, err := th.proc.fs.Stat(report)
123+
st, err := th.proc.fs.Stat(export)
124124

125125
assert.NoError(t, err)
126126

magefiles/magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func out(script string) string {
8484
report := filepath.Join(workdir, slug(script)+"-report.html")
8585
record := filepath.Join(workdir, slug(script)+"-record.ndjson.gz")
8686

87-
return "dashboard=report=" + report + "&record=" + record
87+
return "dashboard=export=" + report + "&record=" + record
8888
}
8989

9090
func jsonout(script string) string {

0 commit comments

Comments
 (0)