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

Add support for exec/env/tags executor options #1428

Merged
merged 25 commits into from
May 18, 2020

Conversation

imiric
Copy link
Contributor

@imiric imiric commented Apr 30, 2020

This enables configuration of environment variables, metric tags and non-default function execution for each executor. See the example in #1300.

Closes #1300

@imiric imiric requested review from mstoykov and na-- April 30, 2020 14:00
core/local/local.go Outdated Show resolved Hide resolved
core/local/local.go Outdated Show resolved Hide resolved
}
}
export function nonDefault() {}`,
"error while initializing executor per_vu_iters: function 'nonDefaultErr' not found in exports"},
Copy link
Contributor Author

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?

lib/runner.go Outdated Show resolved Hide resolved
core/local/local.go Outdated Show resolved Hide resolved
lib/executor/constant_arrival_rate.go Outdated Show resolved Hide resolved
lib/executor/vu_handle.go Outdated Show resolved Hide resolved
core/local/local.go Outdated Show resolved Hide resolved
Ivan Mirić added 2 commits May 4, 2020 12:42
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)
Ivan Mirić added 2 commits May 6, 2020 18:00
Not sure if this is an improvement honestly, but I didn't find a way to
set a default value for null.String.
@imiric imiric force-pushed the feat/1007-1300-env-tags-exec-options branch from 4d47445 to 1eafd11 Compare May 6, 2020 16:00
imiric pushed a commit that referenced this pull request May 7, 2020
This now also grabs all exported functions, including setup/teardown.

Partially resolves:
- #1428 (comment)
- #1428 (comment)
@codecov-io
Copy link

codecov-io commented May 7, 2020

Codecov Report

Merging #1428 into new-schedulers will increase coverage by 0.36%.
The diff coverage is 87.95%.

Impacted file tree graph

@@                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     
Impacted Files Coverage Δ
cmd/archive.go 26.19% <0.00%> (ø)
cmd/cloud.go 9.02% <0.00%> (ø)
cmd/run.go 9.28% <0.00%> (ø)
lib/executors.go 94.11% <ø> (+3.92%) ⬆️
lib/testutils/minirunner/minirunner.go 77.77% <33.33%> (-3.00%) ⬇️
js/runner.go 82.68% <75.00%> (-0.65%) ⬇️
lib/executor/externally_controlled.go 62.32% <85.71%> (+3.09%) ⬆️
js/bundle.go 89.33% <86.36%> (+0.68%) ⬆️
cmd/config.go 83.58% <100.00%> (+10.56%) ⬆️
js/modules/k6/k6.go 100.00% <100.00%> (+8.51%) ⬆️
... and 23 more

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 7dcbfe1...b2b8648. Read the comment docs.

This now also grabs all exported functions, including setup/teardown.

Partially resolves:
- #1428 (comment)
- #1428 (comment)
@imiric imiric force-pushed the feat/1007-1300-env-tags-exec-options branch from 9c1d408 to d90078d Compare May 7, 2020 12:57
@imiric imiric requested a review from na-- May 7, 2020 13:12
cmd/config.go Outdated Show resolved Hide resolved
core/local/local.go Outdated Show resolved Hide resolved
lib/executor/shared_iterations.go Show resolved Hide resolved
js/runner.go Outdated Show resolved Hide resolved
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.

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.

Ivan Mirić added 6 commits May 11, 2020 14:54
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)
Comment on lines 94 to 97
tags := state.Options.RunTags.CloneTags()
for k, v := range state.Tags {
tags[k] = v
}
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@imiric imiric May 12, 2020

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. :-/

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 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 :(

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @na--

Copy link
Contributor

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

Copy link
Contributor Author

@imiric imiric May 12, 2020

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.

@imiric imiric force-pushed the feat/1007-1300-env-tags-exec-options branch from b23b02a to a90e8f2 Compare May 11, 2020 15:59
}
}
case <-done:
require.Equal(t, 8, gotSampleTags, "received wrong amount of samples with expected tags")
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 a couple of issues with this test:

  1. 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?
  2. This assertion is far too brittle (i.e. easily susceptible to changes), and the counter approach is not very reliable. Any better ideas? :)

Copy link
Contributor

@mstoykov mstoykov left a 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)

  1. 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.
  2. 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.
  3. Not really happy with us polluting even more lib and core/local with dependencies to js
  4. something that I forgot while I was writing the above 🤦

Comment on lines 494 to 498
opts := runner.GetOptions()
opts.Hosts = map[string]net.IP{
"httpbin.local": net.ParseIP("127.0.0.1"),
}
require.NoError(t, runner.SetOptions(opts))
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed 🤦 Fixed in 8c5d8df.

Comment on lines 342 to 345
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,
Copy link
Contributor

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 ...

Copy link
Contributor Author

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.

lib/executor/vu_handle.go Outdated Show resolved Hide resolved
imiric pushed a commit that referenced this pull request May 12, 2020
This avoids having to read state.Options in some cases, as that should
be done only once in runFn.

Resolves #1428 (comment)
Ivan Mirić added 7 commits May 12, 2020 16:39
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
@imiric imiric force-pushed the feat/1007-1300-env-tags-exec-options branch from d15bfe9 to 60b2ffe Compare May 12, 2020 14:49
@imiric imiric requested review from mstoykov and na-- May 12, 2020 15:05
@imiric
Copy link
Contributor Author

imiric commented May 12, 2020

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?

Copy link
Contributor

@mstoykov mstoykov left a 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.

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 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.

@imiric imiric merged commit 270fd91 into new-schedulers May 18, 2020
@imiric imiric deleted the feat/1007-1300-env-tags-exec-options branch May 18, 2020 11:03
@mstoykov mstoykov added this to the v0.27.0 milestone Jul 13, 2020
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