Skip to content
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

Merged
merged 6 commits into from
Oct 4, 2017

Conversation

jpallari
Copy link
Contributor

@jpallari jpallari commented Jul 4, 2017

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

run.go Outdated
@@ -69,8 +70,13 @@ const (
CollectorJSON = "json"
CollectorInfluxDB = "influxdb"
CollectorCloud = "cloud"

SummaryFormatText = SummaryFormat(iota)
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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",
Copy link
Contributor

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!

Copy link
Contributor Author

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?

Copy link
Contributor

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)",
Copy link
Contributor

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",
Copy link
Contributor

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(),
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@liclac
Copy link
Contributor

liclac commented Jul 4, 2017

Those are some linter errors from CircleCI too.

@jpallari
Copy link
Contributor Author

jpallari commented Jul 4, 2017

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?

@liclac
Copy link
Contributor

liclac commented Jul 4, 2017

Always print the summary to stdout, optionally write to a file.

@jpallari
Copy link
Contributor Author

jpallari commented Jul 8, 2017

I think the latest build failure is unrelated. I couldn't reproduce it locally. Is it possible to retrigger the build?

@liclac
Copy link
Contributor

liclac commented Jul 31, 2017

Could you try merging from master?

@jpallari jpallari force-pushed the feature/json-summary branch 2 times, most recently from 22c357e to 555d6da Compare August 1, 2017 07:24
@@ -24,6 +24,7 @@ import (
"archive/tar"
"bytes"
"context"
jsonenc "encoding/json"
Copy link
Contributor

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.

Copy link
Contributor Author

@jpallari jpallari Oct 4, 2017

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad.

@liclac
Copy link
Contributor

liclac commented Oct 3, 2017

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.

Jaakko Pallari and others added 6 commits October 4, 2017 19:01
- 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.
@liclac liclac merged commit 87423b7 into grafana:master Oct 4, 2017
@jpallari jpallari deleted the feature/json-summary branch October 5, 2017 07:35
@liclac
Copy link
Contributor

liclac commented Nov 21, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants