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

allow specifying multiple collectors #624

Merged
merged 3 commits into from
May 16, 2018

Conversation

jmccann
Copy link
Contributor

@jmccann jmccann commented May 14, 2018

Taking a stab at #620

Example:

~ # k6 run --vus 10 --duration 5s --out json=test2.json --out json=test.json github.com/loadimpact/k6/samples/http_get.js

          /\      |‾‾|  /‾‾/  /‾/   
     /\  /  \     |  |_/  /  / /   
    /  \/    \    |      |  /  ‾‾\  
   /          \   |  |\  \ | (_) | 
  / __________ \  |__|  \__\ \___/ .io

  execution: local
     output: json=test2.json; json=test.json
     script: github.com/loadimpact/k6/samples/http_get.js
...

~ # ls
k6          test.json   test2.json
~ # diff test.json test2.json 
~ # head -n5 test.json && tail -n5 test.json 
{"type":"Metric","data":{"name":"http_reqs","type":"counter","contains":"default","tainted":null,"thresholds":[],"submetrics":null,"sub":{"name":"","parent":"","suffix":"","tags":null}},"metric":"http_reqs"}
{"type":"Point","data":{"time":"2018-05-14T18:18:54.431179649Z","value":1,"tags":{"group":"","method":"GET","name":"http://test.loadimpact.com","proto":"HTTP/1.1","status":"200","url":"http://test.loadimpact.com"}},"metric":"http_reqs"}
{"type":"Metric","data":{"name":"http_req_duration","type":"trend","contains":"time","tainted":null,"thresholds":[],"submetrics":null,"sub":{"name":"","parent":"","suffix":"","tags":null}},"metric":"http_req_duration"}
{"type":"Point","data":{"time":"2018-05-14T18:18:54.431179649Z","value":132.390419,"tags":{"group":"","method":"GET","name":"http://test.loadimpact.com","proto":"HTTP/1.1","status":"200","url":"http://test.loadimpact.com"}},"metric":"http_req_duration"}
{"type":"Metric","data":{"name":"http_req_blocked","type":"trend","contains":"time","tainted":null,"thresholds":[],"submetrics":null,"sub":{"name":"","parent":"","suffix":"","tags":null}},"metric":"http_req_blocked"}
{"type":"Point","data":{"time":"2018-05-14T18:18:59.060387819Z","value":1,"tags":null},"metric":"iterations"}
{"type":"Point","data":{"time":"2018-05-14T18:18:59.117344636Z","value":10,"tags":null},"metric":"vus"}
{"type":"Point","data":{"time":"2018-05-14T18:18:59.117344636Z","value":10,"tags":null},"metric":"vus_max"}
{"type":"Point","data":{"time":"2018-05-14T18:18:59.244079246Z","value":10,"tags":null},"metric":"vus"}
{"type":"Point","data":{"time":"2018-05-14T18:18:59.244079246Z","value":10,"tags":null},"metric":"vus_max"}

@codecov-io
Copy link

codecov-io commented May 14, 2018

Codecov Report

Merging #624 into master will increase coverage by 0.52%.
The diff coverage is 51.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #624      +/-   ##
==========================================
+ Coverage   64.51%   65.04%   +0.52%     
==========================================
  Files          98       98              
  Lines        7829     7838       +9     
==========================================
+ Hits         5051     5098      +47     
+ Misses       2488     2436      -52     
- Partials      290      304      +14
Impacted Files Coverage Δ
cmd/run.go 6.76% <0%> (-0.11%) ⬇️
core/engine.go 89.23% <100%> (+1.14%) ⬆️
cmd/config.go 50.74% <66.66%> (+13.24%) ⬆️
cmd/common.go 40% <0%> (+25.71%) ⬆️
cmd/options.go 63.44% <0%> (+25.8%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee5a9c3...f1dc9cf. Read the comment docs.

cmd/common.go Outdated
@@ -100,6 +100,25 @@ func getNullString(flags *pflag.FlagSet, key string) null.String {
return null.NewString(v, flags.Changed(key))
}

func getNullStrings(flags *pflag.FlagSet, key string) []null.String {
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned in the kafka PR, I don't think it's necessary it to have null.String slices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I'll get this updated

cmd/config.go Outdated
Linger null.Bool `json:"linger" envconfig:"linger"`
NoUsageReport null.Bool `json:"noUsageReport" envconfig:"no_usage_report"`
NoThresholds null.Bool `json:"noThresholds" envconfig:"no_thresholds"`
Out []null.String `json:"out" envconfig:"out"`
Copy link
Member

Choose a reason for hiding this comment

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

See comment above about []null.String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

cmd/config.go Outdated
c.Out = cfg.Out
for _, o := range cfg.Out {
if o.Valid {
c.Out = append(c.Out, o)
Copy link
Member

Choose a reason for hiding this comment

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

This would make it so there's no way to actually override a configured collector from a lower level. If we (after fixing #587) specify a collector in the exported script options, there wouldn't be a way to actually override it from the CLI options, like we could do with all the other options.

cmd/run.go Outdated
@@ -125,19 +125,21 @@ a commandline interface for interacting with it.`,
// defaults in there, override with Runner-provided ones, then merge the CLI opts in
// on top to give them priority.
fmt.Fprintf(stdout, "%s options\r", initBar.String())
cliConf, err := getConfig(cmd.Flags())

defaultConf := Config{Options: r.GetOptions()}
Copy link
Member

Choose a reason for hiding this comment

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

Ah, unfortunately this would break some stuff 😒... We have to use the cliConf as the base from which to build the config (and also Apply() it last) because it both contains the default values for different options AND is the highest user-supplied config set in the configuration hierarchy...
For example if you try running the code as it is without specifying VUs anywhere, it won't run because the number of VUs would be 0.
I'm sorry you have to deal with this, we'll hopefully fix the configuration mess soon. I'm still collecting pain points, issues and unexpected behaviours, but I'll soon create a github issue that comprehensively describes the current problems with option and configuration handling. For the moment, to avoid breakage, please don't touch the sacred 💩 that is cliConf.Apply(fileConf).Apply(Config{Options: r.GetOptions()}).Apply(envConf).Apply(cliConf) 😒

if len(e.Collectors) > 0 {
for _, collector := range e.Collectors {
collectorwg.Add(1)
go func(collector lib.Collector) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we need goroutines here, see my comment about Collect() in the kafka PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I didn't add it, I'm just using what was already there ... did you want me to work on removing it? Should that be in scope for this PR?

But I can play with it ... maybe it would help address the issue of why I switched from Run() to Collect() for sending the samples to Kafka that I was talking about in the Kafka PR.

Copy link
Member

Choose a reason for hiding this comment

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

Argh, my bad, I misread the diff and the collector method called, ignore my comment entirely. It's exactly how it's supposed to be and your changes are perfectly fine.

@jmccann jmccann force-pushed the multi-output-pt2 branch from c536645 to f1dc9cf Compare May 15, 2018 16:27
@jmccann
Copy link
Contributor Author

jmccann commented May 15, 2018

I think I got everything addressed. Thanks!

Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

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

LGTM! @luizbafilho, please take a look at this as well

@na-- na-- requested a review from luizbafilho May 16, 2018 11:02
Copy link
Contributor

@luizbafilho luizbafilho left a comment

Choose a reason for hiding this comment

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

LGTM

@luizbafilho luizbafilho merged commit c0c680d into grafana:master May 16, 2018
@jmccann jmccann deleted the multi-output-pt2 branch May 16, 2018 17:49
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.

4 participants