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

Rename gRPC module to k6/net/grpc and track and bundle loaded protobuf files #1706

Merged
merged 3 commits into from
Nov 4, 2020

Conversation

na--
Copy link
Member

@na-- na-- commented Nov 3, 2020

This should fix #1696 (it's WIP since I want to write a few more tests).

I think I've managed to get away with very little refactoring for v0.29.0, so hopefully not introducing any bugs... 🤞

I'm also hopeful that the new InitEnvironment concept is a viable way to refactor the InitContext and BaseInitContext and get rid of some of the complexity and code smells (ctxPtr 🤮) there in future k6 releases. In principle, we should be able to extend the InitEnvironment struct so that there is nothing special about the built-in k6 functions like open() and even require(), i.e. refactor them so they use GetInitEnv() as well.

@rogchap, can you please also review this PR and test it, to see if it works for your complex use case as well. I imagine that removing protoparse.ResolveFilenames() and always disabling InferImportPaths might break some complicated imports, even after automatically adding the CWD as the default import path, though I couldn't do it on my machine with my simple .proto files... In any case, protoparse.ResolveFilenames() is not viable since it directly uses the os package to look for files, so if it's absolutely needed, we'd have to re-implement it with afero (or a generic file system interface) in a future k6 version.

Edit: for testing it properly, if k6 run script.js works, then k6 archive script.js && k6 run archive.tar should also work.

@na--
Copy link
Member Author

na-- commented Nov 3, 2020

Ugh, yeah, Windows file paths... 😭 I'll try to fix the tests tomorrow, as well as hopefully write a few new ones.

Comment on lines 100 to 101
FileSystems: map[string]afero.Fs{
"file": afero.NewOsFs(),
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

LGTM apart from the failing windows tests.

I haven't tested it ... and likely won't try as I don't have any gRPC code or tests to begin with, so it will be just the most basic testing that is likely not worth the trouble.

I do like the idea of initEnv and am glad that this didn't require some complete refactor across the code base, and this does look like it won't break anything 🤞

js/modules/k6/grpc/client.go Outdated Show resolved Hide resolved
@@ -527,6 +527,7 @@ func TestVURunContext(t *testing.T) {
fnCalled = true

assert.Equal(t, vu.Runtime, common.GetRuntime(*vu.Context), "incorrect runtime in context")
assert.Nil(t, common.GetInitEnv(*vu.Context)) // shouldn't get this in the vu context
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be nice for there to be a test it is there in the initcontext though, in the js packages, for example, bundle_test.go

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's one test I want to add - I couldn't do it here since getSimpleRunner() can't be used for it

@codecov-io
Copy link

codecov-io commented Nov 4, 2020

Codecov Report

Merging #1706 into master will increase coverage by 0.02%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1706      +/-   ##
==========================================
+ Coverage   71.40%   71.42%   +0.02%     
==========================================
  Files         177      177              
  Lines       13696    13702       +6     
==========================================
+ Hits         9779     9787       +8     
+ Misses       3305     3303       -2     
  Partials      612      612              
Flag Coverage Δ
ubuntu 71.38% <80.00%> (-0.01%) ⬇️
windows 69.98% <86.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
js/initcontext.go 92.13% <ø> (ø)
js/common/initenv.go 66.66% <66.66%> (ø)
js/modules/k6/grpc/client.go 78.43% <84.61%> (+0.57%) ⬆️
js/bundle.go 90.54% <100.00%> (+0.33%) ⬆️
js/common/context.go 100.00% <100.00%> (ø)
js/modules/k6/metrics/metrics.go 92.30% <0.00%> (-0.29%) ⬇️
js/modules/k6/encoding/encoding.go 92.85% <0.00%> (-0.25%) ⬇️
js/modules/k6/html/html.go 81.86% <0.00%> (-0.09%) ⬇️
js/modules/k6/ws/ws.go 81.49% <0.00%> (-0.08%) ⬇️
js/modules/k6/crypto/crypto.go 97.16% <0.00%> (-0.03%) ⬇️
... and 8 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 df5087c...6faf7f2. Read the comment docs.

mstoykov
mstoykov previously approved these changes Nov 4, 2020
@mstoykov
Copy link
Contributor

mstoykov commented Nov 4, 2020

I am fine with this as it is ... more testing with complexer scenarios 😉 😉

@na--
Copy link
Member Author

na-- commented Nov 4, 2020

Almost forgot, we reconsidered the decision to use k6/protocols as the new "namespace" for modules, and decided to somewhat emulate the Go stdlib, so the gRPC module name will be k6/net/grpc, the new HTTP and WebSocket module names will be k6/net/http and k6/net/ws, SQL databases will be k6/db/sql, etc.

mstoykov
mstoykov previously approved these changes Nov 4, 2020
@na-- na-- changed the title [WIP] Track and bundle protobuf files loaded by the gRPC module Track and bundle protobuf files loaded by the gRPC module Nov 4, 2020
imiric
imiric previously approved these changes Nov 4, 2020
Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

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

LGTM! I like the InitEnvironment abstraction and how it elegantly solves this gRPC issue. 👍

js/common/initenv.go Show resolved Hide resolved
js/modules/k6/grpc/client.go Outdated Show resolved Hide resolved
Accessor: protoparse.FileAccessor(func(filename string) (io.ReadCloser, error) {
absFilePath := initEnv.GetAbsFilePath(filename)
// initEnv.Logger.Infof("gRPC trying to load %s from %s...", filename, absFilePath)
return initEnv.FileSystems["file"].Open(absFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe for a follow up PR, but could we use constants / an enum for the FileSystems keys? It wasn't clear to me initially that this is the URL scheme.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we probably should refactor this together with the other TODOs I left...

@na-- na-- dismissed stale reviews from imiric and mstoykov via b7db89c November 4, 2020 16:39
@na-- na-- force-pushed the grpc-file-fixes branch 2 times, most recently from b7db89c to 9a762b5 Compare November 4, 2020 16:43
@na--
Copy link
Member Author

na-- commented Nov 4, 2020

I plan to merge this in master now, so we can get a complete test build for what is going to be v0.29.0, and add the missing unit tests in a separate PR...

mstoykov
mstoykov previously approved these changes Nov 4, 2020
@na-- na-- changed the title Track and bundle protobuf files loaded by the gRPC module Rename gRPC module to k6/net/grpc and track and bundle loaded protobuf files Nov 4, 2020
imiric
imiric previously approved these changes Nov 4, 2020
@na-- na-- dismissed stale reviews from imiric and mstoykov via a15c0b3 November 4, 2020 17:01
@na-- na-- merged commit 1fca463 into master Nov 4, 2020
@na-- na-- deleted the grpc-file-fixes branch November 4, 2020 17:19
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.

gRPC protobuf definitions aren't included in archive bundles
4 participants