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

Extend k6 inspect command with additional flag #2279

Merged
merged 2 commits into from
Jan 11, 2022
Merged

Conversation

yorugac
Copy link
Contributor

@yorugac yorugac commented Dec 1, 2021

This PR adds additional output to k6 inspect with --execution-requirements CLI option. When switched on, it triggers calculation of execution requirements, substitutes config with the derived one and adds maxVUs and totalDuration fields to the output.

Signature of getConsolidatedConfig was modified: now it doesn't depend on lib.Runner but only on lib.Options.

Some minor refactoring in cmd/ was added on the way, but not too much as that'd require additional work and likely a separate PR.

This is part of the work for implementing grafana/k6-operator#9

@github-actions github-actions bot requested review from codebien and mstoykov December 1, 2021 08:34
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

I added some comments, if there is an open issue/PR from the operator where this should be used can you link it, please? It would be helpful to see the global picture 🙏

inspectOutput := interface{}(b.Options)

if addExecReqs {
inspectOutput, err = addExecRequirements(b, builtinMetrics, registry, logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something but could we reuse the newRunner function from cmd/run.go and inject the runner here?

k6/cmd/run.go

Line 390 in 5c14dae

func newRunner(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I started with that approach but newRunner creates a runner from loader.SourceData so it duplicates what was already done in inspect cmd, i.e. js.New / lib.ReadArchive calls. So primarily I didn't use newRunner to avoid duplication. Additionally, it just makes sense to me for NewFromBundle to be public too, even if it isn't used anywhere else right now.

@yorugac
Copy link
Contributor Author

yorugac commented Dec 1, 2021

Thanks @codebien! I've added relevant link to the description

@yorugac yorugac added this to the v0.36.0 milestone Dec 1, 2021
@yorugac yorugac added documentation-needed A PR which will need a separate PR for documentation ux labels Dec 1, 2021
cmd/inspect.go Outdated
Comment on lines 114 to 124
runner, err := js.NewFromBundle(logger, b, builtinMetrics, registry)
if err != nil {
return nil, err
}

conf, err := getConsolidatedConfig(afero.NewOsFs(), Config{}, runner)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Bundle is actually a type that I and @na-- have mostly wanted to remove in the past, so exposing it more seems like a bad idea. Refactoring everything needed is probably going to be way too much work, but I would argue you that given that you already got the Bundle, and that it actually has the options and that getConsolidatedConfig just gets the Options from the runner, which gets it from the Bundle inside .... You can just rewrite getConsolidatedConfig to be taking the Options and get the Options directly from the runner, skipping making NewFromBundle public.

Even more importantly the one thing that `get

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think your comment got cut in two and only the first part is left 😛

Needless to say, it's the first time I'm learning of these plans... 👀 Why do you want to remove Bundle? And yes, my logic was ~ since Bundle is public, NewFromBundle can be public too.

Regardless, that's an interesting point. The main reason runner appeared here was not the getConsolidatedConfig but ExecutionScheduler. In theory it should be possible to derive the execution plan from just options without runner 🤔 I'll need to double-check if current interfaces fully allow that but at first glance that might work.

Copy link
Contributor Author

@yorugac yorugac Dec 2, 2021

Choose a reason for hiding this comment

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

Did you mean this: #1048 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that issue (as most very old issues) is now very outdated, but in parts - yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mstoykov I've looked into this: trying to refactor in "minimal fashion" (without touching js/ stuff) gets stuck on the point of Runner.IsExecutable → which needs Bundle.exports so again, the same problem with private field of Bundle. Trying to refactor this at the level of Bundle is definitely too out-of-scope for this PR: I think it should be done separately.
For now, I'll add some notes on that to the #1048 issue: it can be continued in a separate PR or be left alone until next prioritization.

I added a small refactoring around getConsolidatedConfig: it can truly be used with only options, without Runner: I think it's relatively small to be present in this PR and might simplify next stages of refactorings too.

Copy link
Contributor

Choose a reason for hiding this comment

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

:(

Hm looking at this again, maybe just instead of using NewBundle and then NewFromBundle, you can just go with creating the runner the same run will do. The additional work NewFromBundle does is ... minimal and should not have any side effects. But will make the cmd<->js dependency smaller.

WDYT ?

Copy link
Contributor Author

@yorugac yorugac Dec 16, 2021

Choose a reason for hiding this comment

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

I wouldn't say dependency would be "smaller".. meaning, even prior to this PR inspect was the only one in cmd using Bundle directly which makes sense in its case. From this follows that probably any major refactoring in js will impact inspect first.

Of course, it can be re-written as you describe but TBH, I think all options here are equally bad 😂 -- because that major refactoring is needed. I slightly prefer the current version because I don't see any harm from public NewFromBundle at this point while this version more explicitly shows the use cases that future refactoring should take into account. So it's kind of a way to document too. It may depend on how soon that refactoring will happen though.

mstoykov
mstoykov previously approved these changes Jan 5, 2022
codebien
codebien previously approved these changes Jan 5, 2022
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@yorugac yorugac dismissed stale reviews from codebien and mstoykov via dc8bd69 January 11, 2022 09:28
@yorugac yorugac force-pushed the feat/extend-k6-inspect branch from 6e68f3d to dc8bd69 Compare January 11, 2022 09:28
@yorugac yorugac force-pushed the feat/extend-k6-inspect branch from dc8bd69 to 500793f Compare January 11, 2022 10:01
@yorugac yorugac requested review from codebien and mstoykov January 11, 2022 10:17
@yorugac yorugac merged commit e280766 into master Jan 11, 2022
@yorugac yorugac deleted the feat/extend-k6-inspect branch January 11, 2022 10:21
@yorugac yorugac removed the documentation-needed A PR which will need a separate PR for documentation label Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants