Skip to content

Commit

Permalink
feat: Integrating the web dashboard feature
Browse files Browse the repository at this point in the history
As per our product DNA, we aim, by integrating the web dashboard (xk6-dashboard) directly into k6, to enhance and
streamline the user experience, making real-time and end-of-test visualizations immediately accessible as part of the k6
command-line experience.
  • Loading branch information
szkiba committed Dec 15, 2023
1 parent 340503b commit 31569f1
Show file tree
Hide file tree
Showing 93 changed files with 7,725 additions and 19 deletions.
20 changes: 13 additions & 7 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ func configFlagSet() *pflag.FlagSet {
flags.StringArrayP("out", "o", []string{}, "`uri` for an external metrics database")
flags.BoolP("linger", "l", false, "keep the API server alive past test end")
flags.Bool("no-usage-report", false, "don't send anonymous stats to the developers")
flags.Bool("no-web-dashboard", false, "disable web dashboard")
return flags
}

// Config ...
type Config struct {
lib.Options

Out []string `json:"out" envconfig:"K6_OUT"`
Linger null.Bool `json:"linger" envconfig:"K6_LINGER"`
NoUsageReport null.Bool `json:"noUsageReport" envconfig:"K6_NO_USAGE_REPORT"`
Out []string `json:"out" envconfig:"K6_OUT"`
Linger null.Bool `json:"linger" envconfig:"K6_LINGER"`
NoUsageReport null.Bool `json:"noUsageReport" envconfig:"K6_NO_USAGE_REPORT"`
NoWebDashboard null.Bool `json:"noWebDashboard" envconfig:"K6_NO_WEB_DASHBOARD"`

// TODO: deprecate
Collectors map[string]json.RawMessage `json:"collectors"`
Expand All @@ -67,6 +69,9 @@ func (c Config) Apply(cfg Config) Config {
if cfg.NoUsageReport.Valid {
c.NoUsageReport = cfg.NoUsageReport
}
if cfg.NoWebDashboard.Valid {
c.NoWebDashboard = cfg.NoWebDashboard
}
if len(cfg.Collectors) > 0 {
c.Collectors = cfg.Collectors
}
Expand Down Expand Up @@ -94,10 +99,11 @@ func getConfig(flags *pflag.FlagSet) (Config, error) {
return Config{}, err
}
return Config{
Options: opts,
Out: out,
Linger: getNullBool(flags, "linger"),
NoUsageReport: getNullBool(flags, "no-usage-report"),
Options: opts,
Out: out,
Linger: getNullBool(flags, "linger"),
NoUsageReport: getNullBool(flags, "no-usage-report"),
NoWebDashboard: getNullBool(flags, "no-web-dashboard"),
}, nil
}

Expand Down
14 changes: 12 additions & 2 deletions cmd/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
"go.k6.io/k6/output/json"
"go.k6.io/k6/output/statsd"

"github.com/grafana/xk6-dashboard/dashboard"
"github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite"
)

const webDashboardName = "web-dashboard"

// TODO: move this to an output sub-module after we get rid of the old collectors?
func getAllOutputConstructors() (map[string]output.Constructor, error) {
// Start with the built-in outputs
Expand All @@ -45,6 +48,7 @@ func getAllOutputConstructors() (map[string]output.Constructor, error) {
"experimental-prometheus-rw": func(params output.Params) (output.Output, error) {
return remotewrite.New(params)
},
webDashboardName: dashboard.New,
}

exts := ext.Get(ext.OutputExtension)
Expand Down Expand Up @@ -92,9 +96,15 @@ func createOutputs(
RuntimeOptions: test.preInitState.RuntimeOptions,
ExecutionPlan: executionPlan,
}
result := make([]output.Output, 0, len(test.derivedConfig.Out))

for _, outputFullArg := range test.derivedConfig.Out {
outputs := test.derivedConfig.Out
if !test.derivedConfig.NoWebDashboard.Bool {
outputs = append(test.derivedConfig.Out, webDashboardName)

Check failure on line 102 in cmd/outputs.go

View workflow job for this annotation

GitHub Actions / lint

appendAssign: append result not assigned to the same slice (gocritic)
}

result := make([]output.Output, 0, len(outputs))

for _, outputFullArg := range outputs {
outputType, outputArg := parseOutputArgument(outputFullArg)
outputConstructor, ok := outputConstructors[outputType]
if !ok {
Expand Down
35 changes: 25 additions & 10 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func printExecutionDescription(
valueColor := getColor(noColor, color.FgCyan)

buf := &strings.Builder{}
fmt.Fprintf(buf, " execution: %s\n", valueColor.Sprint(execution))
fmt.Fprintf(buf, " script: %s\n", valueColor.Sprint(filename))
fmt.Fprintf(buf, " execution: %s\n", valueColor.Sprint(execution))
fmt.Fprintf(buf, " script: %s\n", valueColor.Sprint(filename))

var outputDescriptions []string
switch {
Expand All @@ -114,18 +114,23 @@ func printExecutionDescription(
for _, out := range outputs {
desc := out.Description()
if desc == engine.IngesterDescription {
if len(outputs) != 1 {
continue
}
desc = "-"
continue
}
if ok, v := checkWebDashboardDescription(desc); ok {
fmt.Fprintf(buf, "web dashboard: %s\n", valueColor.Sprint(v))

continue
}
outputDescriptions = append(outputDescriptions, desc)
}
if len(outputDescriptions) == 0 {
outputDescriptions = append(outputDescriptions, "-")
}
}

fmt.Fprintf(buf, " output: %s\n", valueColor.Sprint(strings.Join(outputDescriptions, ", ")))
fmt.Fprintf(buf, " output: %s\n", valueColor.Sprint(strings.Join(outputDescriptions, ", ")))
if gs.Flags.ProfilingEnabled && gs.Flags.Address != "" {
fmt.Fprintf(buf, " profiling: %s\n", valueColor.Sprintf("http://%s/debug/pprof/", gs.Flags.Address))
fmt.Fprintf(buf, " profiling: %s\n", valueColor.Sprintf("http://%s/debug/pprof/", gs.Flags.Address))
}

fmt.Fprintf(buf, "\n")
Expand All @@ -138,13 +143,13 @@ func printExecutionDescription(
scenarioDesc = fmt.Sprintf("%d scenarios", len(executorConfigs))
}

fmt.Fprintf(buf, " scenarios: %s\n", valueColor.Sprintf(
fmt.Fprintf(buf, " scenarios: %s\n", valueColor.Sprintf(
"(%.2f%%) %s, %d max VUs, %s max duration (incl. graceful stop):",
conf.ExecutionSegment.FloatLength()*100, scenarioDesc,
lib.GetMaxPossibleVUs(execPlan), maxDuration.Round(100*time.Millisecond)),
)
for _, ec := range executorConfigs {
fmt.Fprintf(buf, " * %s: %s\n",
fmt.Fprintf(buf, " * %s: %s\n",
ec.GetName(), ec.GetDescription(et))
}
fmt.Fprintf(buf, "\n")
Expand Down Expand Up @@ -380,3 +385,13 @@ func yamlPrint(w io.Writer, v interface{}) error {
}
return nil
}

// checkWebDashboardDescription returns true if desc contains web dashboard description.
// The returned string contains info string (URL).
func checkWebDashboardDescription(desc string) (bool, string) {
const webDashboardDescPrefix = webDashboardName + " "
if strings.HasPrefix(desc, webDashboardDescPrefix) {
return true, strings.TrimPrefix(desc, webDashboardDescPrefix)
}
return false, ""
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/gorilla/websocket v1.5.1
github.com/grafana/xk6-browser v1.2.1
github.com/grafana/xk6-dashboard v0.6.1
github.com/grafana/xk6-output-prometheus-remote v0.3.1
github.com/grafana/xk6-redis v0.2.0
github.com/grafana/xk6-timers v0.1.2
Expand Down Expand Up @@ -74,15 +75,18 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/r3labs/sse/v2 v2.10.0 // indirect
github.com/redis/go-redis/v9 v9.0.5 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
Expand All @@ -93,4 +97,5 @@ require (
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 h1:ZgoomqkdjGbQ3+qQXC
github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grafana/xk6-browser v1.2.1 h1:O2fuHHvmmhXvWTPXzD+jsnt1XkVgVjx0+Lj1hsGIWMM=
github.com/grafana/xk6-browser v1.2.1/go.mod h1:D3k9/MQHnNKfyzU3fh32pHlrh3GY2LAlkY4wYt/Vn4Y=
github.com/grafana/xk6-dashboard v0.6.1 h1:qUHFId+7/K72VoDqTh5g5I/1SKYtHkav/B++lbpYl/c=
github.com/grafana/xk6-dashboard v0.6.1/go.mod h1:9NoiyT5qcEhJWbIxY6LIkHtUUCbQcjl2cM7evUQ0Apc=
github.com/grafana/xk6-output-prometheus-remote v0.3.1 h1:X23rQzlJD8dXWB31DkxR4uPnuRFo8L0Y0H22fSG9xl0=
github.com/grafana/xk6-output-prometheus-remote v0.3.1/go.mod h1:0JLAm4ONsNUlNoxJXAwOCfA6GtDwTPs557OplAvE+3o=
github.com/grafana/xk6-redis v0.2.0 h1:iXmAKVlAxafZ/h8ptuXTFhGu63IFsyDI8QjUgWm66BU=
Expand Down Expand Up @@ -154,6 +158,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.20.2 h1:8uQq0zMgLEfa0vRrrBgaJF2gyW9Da9BmfGV+OyUzfkY=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -166,6 +172,8 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0=
github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand Down Expand Up @@ -244,6 +252,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand All @@ -270,6 +279,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -331,6 +341,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
27 changes: 27 additions & 0 deletions vendor/github.com/gorilla/schema/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions vendor/github.com/gorilla/schema/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 31569f1

Please sign in to comment.