-
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
Add support for exec/env/tags executor options #1428
Conversation
core/local/local_test.go
Outdated
} | ||
} | ||
export function nonDefault() {}`, | ||
"error while initializing executor per_vu_iters: function 'nonDefaultErr' not found in exports"}, |
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.
Should we add more test cases here? Test other executors as well?
This leaves executor init before VU init, but moves the config validation to a more suitable place before the engine/ExecutionScheduler is initialized. It now also properly reports errors from more than one executor. Resolves #1428 (comment)
Not sure if this is an improvement honestly, but I didn't find a way to set a default value for null.String.
4d47445
to
1eafd11
Compare
This now also grabs all exported functions, including setup/teardown. Partially resolves: - #1428 (comment) - #1428 (comment)
Codecov Report
@@ Coverage Diff @@
## new-schedulers #1428 +/- ##
==================================================
+ Coverage 76.34% 76.71% +0.36%
==================================================
Files 162 163 +1
Lines 12936 12977 +41
==================================================
+ Hits 9876 9955 +79
+ Misses 2545 2511 -34
+ Partials 515 511 -4
Continue to review full report at Codecov.
|
This now also grabs all exported functions, including setup/teardown. Partially resolves: - #1428 (comment) - #1428 (comment)
9c1d408
to
d90078d
Compare
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.
see #1428 (comment) - the rest are minor nitpicks, but tags and environment variables should not cross over between executors.
Basically, VUs in each executor have to get {the global --tag
/--env
values + whatever was configured for that specific executor}, no crossover.
This was done in e693715 to ensure exec validation would fail before VUs are initialized, but now that this validation is done much earlier, this is no longer needed. Resolves #1428 (comment)
The minor optimization wasn't worth the messiness. Resolves #1428 (comment)
js/modules/k6/k6.go
Outdated
tags := state.Options.RunTags.CloneTags() | ||
for k, v := range state.Tags { | ||
tags[k] = v | ||
} |
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.
Hm ... shouldn't it just be state.Tags.CloneTags()
? And have the state.Options.RunTags
be cloned to state.Tags
along all the others ?
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.
Not sure I'm following, sorry. Can you elaborate on that?
Options.RunTags
are the globally defined tags, whereas state.Tags
was added here to pass on the custom executor tags. There's an overriding hierarchy here, which we might want to document.
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 am just of the opinion you can put the overridden final tags inside state.Tags
and use them everywhere where state.Options.RunTags
are being used currently instead of merging them everywhere
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.
Aha, I see. I'll look into that, thanks.
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.
@mstoykov See d15bfe9 for this change.
I'm a bit apprehensive about it, since it could break some previous overriding, and it couldn't be done in httpext.MakeRequest
, otherwise TestRequestAndBatch/Params/tags/tags-precedence
would fail. Also now WS metrics will be tagged with optional system tags (iter
, vu
, etc.), whereas previously they weren't. Arguably an improvement, but a bit worrying that something else didn't inadvertently change and we're not testing for it.
I'd leave this in anyway, but there's now a race condition in CI I thought was fixed by e33400e, which passed locally, but apparently not, or I broke it again. :-/
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 know ... I think this is once again too big of change ... and at this point, I think it was a mistake to try and implement both exec, tags, and env at the same time. Especially tags seem to be problematic, mostly because they were problematic even before that. I don't know what is the correct change, but am fine with you reverting the changes ... or not - I am of the opinion that this probably fixes some tiems when vu
/iter
weren't present in metrics they should've been in.
The race conditions on the other hand are problematic and will 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.
cc @na--
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 race condition seems to be between https://github.com/loadimpact/k6/blob/d15bfe93177fabfd80527045a270930b2f609eed/lib/executor/variable_looping_vus.go#L579 and https://github.com/loadimpact/k6/blob/d15bfe93177fabfd80527045a270930b2f609eed/lib/executor/variable_looping_vus.go#L587, where apparently by https://golang.org/src/sync/waitgroup.go?s=3500:3527#L124 you need to synchronize the Add and Wait ... which I agree with and it is something that my WIP change does for variable arrival rate ... I think ...
So maybe this isn't a problem with this PR :D
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.
Yeah, while it doesn't seem related to this PR, the raciness was exhibited with the new tests, which is good I suppose, since I didn't find anything wrong with the tests themselves.
So I applied the same defer
reordering fix we did in a previous PR for the arrival-rate execs to the VLV one, and it seemed to fix the issue locally at least (although that could be flaky...). See 60b2ffe. Let's wait for CI... \o/ Seems to have fixed it.
b23b02a
to
a90e8f2
Compare
} | ||
} | ||
case <-done: | ||
require.Equal(t, 8, gotSampleTags, "received wrong amount of samples with expected tags") |
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.
So a couple of issues with this test:
- It's too large, and possibly testing too much functionality. I'd be up for splitting it, but I think we'd end up with more LOCs overall. Any ideas on simplifying, or splitting criteria and/or where to move it?
- This assertion is far too brittle (i.e. easily susceptible to changes), and the counter approach is not very reliable. Any better ideas? :)
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 have a few more nitpicks and in general things that I do not like, but all of those can be fixed at a later time, and this seems to be in a working state? Although we should definitely do more manual testing.
List of things I don't like (in no particular order): (while I am okay debating them, implementing them in this PR is in no way required)
- the whole exports field in the js package, haven't tried it but IMO we don't need it, we just need the VU to have its function as a field, and even that is probably not a requirement. As I mentioned previously my primary problem is that in the past we had stupid bugs because of a goja.Value/goja.Object was used in another VM that isn't the one it was created in. Looking at this - this will predominantly be problematic in the tests.
- the more I look at the more it seems to me the whole merging of tags/env should just happen in one place ... maybe even not in the runner (although that is okay as well) and just to get propagated through the state for everywhere else in the VU to use.
- Not really happy with us polluting even more
lib
andcore/local
with dependencies tojs
- something that I forgot while I was writing the above 🤦
core/local/local_test.go
Outdated
opts := runner.GetOptions() | ||
opts.Hosts = map[string]net.IP{ | ||
"httpbin.local": net.ParseIP("127.0.0.1"), | ||
} | ||
require.NoError(t, runner.SetOptions(opts)) |
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.
nit: Does this not work if it's just in the text options above ?
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.
Indeed 🤦 Fixed in 8c5d8df.
func newManualVUHandle( | ||
parentCtx context.Context, state *lib.ExecutionState, | ||
localActiveVUsCount *int64, initVU lib.InitializedVU, logger *logrus.Entry, | ||
localActiveVUsCount *int64, initVU lib.InitializedVU, | ||
config *BaseConfig, logger *logrus.Entry, |
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.
nit: maybe have this be a method on *externallyControlledRunState as there are now 5 parameters that are its fields ...
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.
Good idea, should be resolved by 438b422.
This avoids having to read state.Options in some cases, as that should be done only once in runFn. Resolves #1428 (comment)
This reverts commit 25a26ab. Concurrent calls to getVUActivationParams would cause race conditions when reading from BaseConfig and several tests would fail, so this needs to be done only once per executor, and we need this RunContext overriding after all.
This avoids having to read state.Options in some cases, as that should be done only once in runFn. Resolves #1428 (comment)
This applies the same fixes as eb13303 and d01e2c1 for the VLV executor, to ensure activeVUsWG.Wait() is called last, after the context has been cancelled. It resolves some race conditions exhibited by the TestExecutionSchedulerRun* tests (e.g. [1]). [1]: https://circleci.com/gh/loadimpact/k6/10139
d15bfe9
to
60b2ffe
Compare
This should be ready now, hopefully free from race conditions... Let me know if I should clean the commits up a bit, some of them could be squashed. Also: I haven't tested tagging of thresholds. Besides that, is there anything else taggable that might be affected by this? |
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.
What I said in my previous comment - LGTM!
We need to test and document this a lot now ... as this is probably the single biggest change to the executing of VUs we've done in a long time.
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.
LGTM in general, though I found a few minor issues that I fixed in #1453 - if you don't see any issues with the changes, feel free to 👍 and merge that PR here, and this in new-schedulers
afterwards.
This would previously fail without the fixes in #1453.
This enables configuration of environment variables, metric tags and non-default function execution for each executor. See the example in #1300.
Closes #1300