-
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
Move most capabilities out of the core.Engine
in preparation for removal
#2813
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2813 +/- ##
==========================================
+ Coverage 76.78% 76.84% +0.06%
==========================================
Files 226 225 -1
Lines 16848 16807 -41
==========================================
- Hits 12936 12915 -21
+ Misses 3084 3066 -18
+ Partials 828 826 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
f6386b7
to
195c2ab
Compare
8e8f1aa
to
947ecb1
Compare
@na-- For staring the code review could you please resolve conflicts, thanks! |
947ecb1
to
3b44fa2
Compare
195c2ab
to
818cee6
Compare
3b44fa2
to
e5b8879
Compare
818cee6
to
d24bcc2
Compare
a42bdc7
to
9f050f7
Compare
96162e1
to
30908a1
Compare
30908a1
to
cb17842
Compare
// TODO: reduce the control surface as much as possible? For example, if | ||
// we refactor the Runner API, we won't need to send the Samples channel. |
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.
Out of curiosity, do we have an issue with it? I didn't find much searching by Runner
.
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.
Hmm I don't think we have a dedicated issue for that 🤔 We have a few code TODOs like this one, and some tangentially related issues like #1048 and #2869, but nothing dedicated 🤔
The problem is that we (or at least I) don't have a clear vision for how it should refactored yet... For example, I know that we need to change the name, since Runner
is super confusing when it is essentially a "factory" for VUs... 😅 But since I don't have a clear idea how we can refactor it, I also don't know into what to rename it 😞
So yeah, this is why we have the TODO
here and in the Runner
:
Lines 41 to 85 in 1d99b0b
// A Runner is a factory for VUs. It should precompute as much as possible upon | |
// creation (parse ASTs, load files into memory, etc.), so that spawning VUs | |
// becomes as fast as possible. The Runner doesn't actually *do* anything in | |
// itself, the ExecutionScheduler is responsible for wrapping and scheduling | |
// these VUs for execution. | |
// | |
// TODO: Rename this to something more obvious? This name made sense a very long | |
// time ago. | |
type Runner interface { | |
// Creates an Archive of the runner. There should be a corresponding NewFromArchive() function | |
// that will restore the runner from the archive. | |
MakeArchive() *Archive | |
// Spawns a new VU. It's fine to make this function rather heavy, if it means a performance | |
// improvement at runtime. Remember, this is called once per VU and normally only at the start | |
// of a test - RunOnce() may be called hundreds of thousands of times, and must be fast. | |
NewVU(ctx context.Context, idLocal, idGlobal uint64, out chan<- metrics.SampleContainer) (InitializedVU, error) | |
// Runs pre-test setup, if applicable. | |
Setup(ctx context.Context, out chan<- metrics.SampleContainer) error | |
// Returns json representation of the setup data if setup() is specified and run, nil otherwise | |
GetSetupData() []byte | |
// Saves the externally supplied setup data as json in the runner | |
SetSetupData([]byte) | |
// Runs post-test teardown, if applicable. | |
Teardown(ctx context.Context, out chan<- metrics.SampleContainer) error | |
// Returns the default (root) Group. | |
GetDefaultGroup() *Group | |
// Get and set options. The initial value will be whatever the script specifies (for JS, | |
// `export let options = {}`); cmd/run.go will mix this in with CLI-, config- and env-provided | |
// values and write it back to the runner. | |
GetOptions() Options | |
SetOptions(opts Options) error | |
// Returns whether the given name is an exported and executable | |
// function in the script. | |
IsExecutable(string) bool | |
HandleSummary(context.Context, *Summary) (map[string]io.Reader, error) | |
} |
I also have some very vague ideas on how to refactor setup/teardown/handleSummary handling so they don't require their own dedicated methods, and also how to refactor the archive handling to be somewhat separate, but everything is super vague at the moment and probably full of problems 😞 Someone needs to start doing it, so we can hit the real issues.
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.
Decided to create a new issue after all: #2873
Even though we don't have the whole picture, it doesn't hurt to have a place to collect problems that need to be fixed
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 have major comments, nicely done 👍 And sorry it took so long to review it 😓
cb17842
to
c234955
Compare
After this commit, the only place the Engine is used in the api/ package tests, and only in a few places that will be easy to refactor after we remove it completely.
c234955
to
d0eb9d3
Compare
This is the first commit from #2815, plus an extra test that checks the exit code when aborting a `k6 run --paused` test with Ctrl+C. Unfortunately, it turned out that 19dd505 from #2813 introduced a regression. Interrupting the k6 process with a signal should result in a `105` exit code (`ExternalAbort`), but with that commit k6 exited with `103` if k6 was `--paused`. The good news is that the fix was already done in the first commit of #2815, which was entirely self-sufficient and can be moved to this separate PR. As a bonus, this makes reviewing everything even easier... So, some details about the commit itself... In short, there is no need to have 2 separate `Run()` and `Init()` methods in the `execution.Scheduler`. Instead, Run() can start the VU initialization itself. As a bonus, this immediately makes the error handling around init errors much more in line with other error handling, allowing us to resolve the bug, but also to respect `--linger` and to try and execute `handleSummary()` if there were problems. Except the first init that is used to get the exported options, of course, that one is still special.
This built on top of #2812 and is the penultimate PR before #1889 🎉 🤞
It splits off as much of the capabilities of the
Engine
as it's possible to do and keep most of its tests (mostly) intact 😅 Commits should be atomic and it might be easier to review the PR commit by commit. I can even split this into smaller PRs, if needs be, though I think grouping these commits together in one PR and completely removing theEngine
in another PR makes the most sense.