-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aggregated metrics in JSON format #274
Conversation
run.go
Outdated
@@ -69,8 +70,13 @@ const ( | |||
CollectorJSON = "json" | |||
CollectorInfluxDB = "influxdb" | |||
CollectorCloud = "cloud" | |||
|
|||
SummaryFormatText = SummaryFormat(iota) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency: else where we use the form SummaryFormatText SummaryFormat = iota
.
run.go
Outdated
@@ -588,60 +627,131 @@ loop: | |||
} | |||
fmt.Fprintf(color.Output, "\n") | |||
|
|||
// Print summary | |||
summaryError := printSummary(fs, summaryFile, summaryFormat, engine, atTime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just call this err
; I think this can be shortened to if err := printSummary(...); err != nil
without the line length getting ridiculous too?
run.go
Outdated
return nil | ||
} | ||
|
||
func printSummary(fs afero.Fs, filename string, summaryFormat SummaryFormat, engine *core.Engine, atTime time.Duration) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that this does two things.
The cyclomatic complexity of actionRun is ridiculous, but it's something I'm going to do something about as soon as I can (we need proper packages!). Just have it call a writeSummary()
function that writes to the file if one is given instead.
run.go
Outdated
@@ -150,6 +156,17 @@ var commandRun = cli.Command{ | |||
Usage: "output metrics to an external data store (format: type=uri)", | |||
EnvVar: "K6_OUT", | |||
}, | |||
cli.StringFlag{ | |||
Name: "summary-file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the name summary
or report
better here; also give it a shorthand flag!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions on what letter to use for the shorthand flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-s
or -r
works; this is so useful that it deserves a flag imo.
run.go
Outdated
@@ -150,6 +156,17 @@ var commandRun = cli.Command{ | |||
Usage: "output metrics to an external data store (format: type=uri)", | |||
EnvVar: "K6_OUT", | |||
}, | |||
cli.StringFlag{ | |||
Name: "summary-file", | |||
Usage: "file where the summary is written (default: standard output)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it default to -
instead of writing it here.
run.go
Outdated
Name: "summary-format", | ||
Usage: "file format for summary, one of: text, json", | ||
EnvVar: "K6_SUMMARY_FILE", | ||
Value: "text", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's default to JSON if a summary file is given instead of making it mutually exclusive with the text summary like this. Or YAML, if you prefer that.
stats/stats.go
Outdated
func (m *Metric) Summary() *Summary { | ||
return &Summary{ | ||
Metric: m, | ||
Samples: m.Sink.Format(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field name is misleading imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions on the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary
maybe?
Also: for consistency, all field names should have camelCase names when serialized to/from JSON.
Those are some linter errors from CircleCI too. |
Thanks for the review. I'll address your points in full when I get the chance. There's one thing I didn't ask about earlier. These changes assume that you always want to output the summary in either text or JSON format to either stdout or a file. Is this style OK, or would the preferred style be to always print the text summary to stdout, and optionally write the summary as JSON to a file? |
Always print the summary to stdout, optionally write to a file. |
38130ba
to
34a03f1
Compare
I think the latest build failure is unrelated. I couldn't reproduce it locally. Is it possible to retrigger the build? |
34a03f1
to
04159b6
Compare
Could you try merging from master? |
22c357e
to
555d6da
Compare
@@ -24,6 +24,7 @@ import ( | |||
"archive/tar" | |||
"bytes" | |||
"context" | |||
jsonenc "encoding/json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't rename this import, adapt your variable names instead. It's too ubiquitous and it'd be inconsistent with what we're doing in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's renamed is because there's already an import to something else named json
: github.com/loadimpact/k6/stats/json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, my bad.
Really sorry for being so slow on this, I somehow missed that you pushed those commits until I went back through some old issues. Please merge with master again, right now your branch only seems to be failing to build due to not having 72fa552. |
- Mutexes don't have any sensible JSON serialization - Attempting to serialize a parent node will lead to infinite recursion.
Instead of choosing to print out the summary in either a human readable format or in JSON, always print out to stdout, and optionally write the JSON summary to a file.
555d6da
to
d98ba72
Compare
Heads up: this was broken in the CLI rewrite (#110) and will be skipping v0.18.0, but I'll do my best to get it back into the next version. |
Changes summary
Added a new command line parameter
report
: the file where the aggregated metrics are written to in JSON format.Related issues
Resolves #271