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

js/grpc: modules.Module migration #2365

Merged
merged 2 commits into from
Feb 3, 2022
Merged

js/grpc: modules.Module migration #2365

merged 2 commits into from
Feb 3, 2022

Conversation

codebien
Copy link
Collaborator

@codebien codebien commented Feb 1, 2022

Migrated k6/grpc to the modules.Module (aka modules.ModuleV2) interface.

mstoykov
mstoykov previously approved these changes Feb 1, 2022
Copy link
Collaborator

@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 🎉 . I did leave some non essential nit picks

Copy link
Collaborator

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

Thanks! The PR looks good, I left a few suggestions that can improve the readability.

js/modules/k6/grpc/client.go Outdated Show resolved Hide resolved
func (c *Client) Connect(ctxPtr *context.Context, addr string, params map[string]interface{}) (bool, error) {
state := lib.GetState(*ctxPtr)
func (c *Client) Connect(addr string, params map[string]interface{}) (bool, error) {
state := c.vu.State()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed that there are several places (here and other parts of there code) where we use this check:

state := c.vu.State()
if state == nil {
	return false, errConnectInInitContext
}

How about adding a simple method like modules.IsInitialContext(vu VU) bool I believe that improves the readability of the code, and what is also essential make code more maintainable since we consolidate the logic that identifies that the particular place is dependent during what phase it is executing?

Copy link
Collaborator Author

@codebien codebien Feb 2, 2022

Choose a reason for hiding this comment

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

I like the idea in terms of readability, but in this way, we can't reuse the state variable so for most of the methods we are doing 2x on the call for resolving the State that comes from the slow context.

k6/js/initcontext.go

Lines 169 to 171 in 0dda328

func (m *moduleVUImpl) State() *lib.State {
return lib.GetState(*m.ctxPtr) // TODO thread it correctly instead
}

so I'm feeling a bit conflicted here without having some profiling data

Copy link
Collaborator

Choose a reason for hiding this comment

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

@olegbespalov please make a separate issue about this.
@codebien in #2228 I in practice stop getting the state from a context, which is a thing that needs to happen for everything at some point either way.

But I do think this should be made ina separate PR and probably across the codebase, so please open an issue @olegbespalov so we can discuss the API for example and whether we want to do this for more stuff

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to keep the connection, opened an issue #2368

js/modules/k6/grpc/client.go Outdated Show resolved Hide resolved
js/modules/k6/grpc/client.go Outdated Show resolved Hide resolved
@codebien
Copy link
Collaborator Author

codebien commented Feb 2, 2022

I did some refactor inspired by your suggestions. WDYT?

olegbespalov
olegbespalov previously approved these changes Feb 3, 2022
Copy link
Collaborator

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

PR looks good to me, great work! 👍

Copy link
Collaborator

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

Hm I think we can't remove the goroutine because of #1623 (comment) also ... I really prefer to not change the code all that much in the same PR that already changes a lot of stuff.

If there are some refactoring ideas, please move them to a separate PR, so we can have smaller and easier to review PRs instead of just doing a lot of those in one 🙏

@codebien
Copy link
Collaborator Author

codebien commented Feb 3, 2022

Hm I think we can't remove the goroutine because of #1623 (comment) also

@mstoykov We should be able to remove it as documented in the commit's description c93b8b0

From my understanding, we did it in that way just for getting the TLS error that is covered by grpc.WithReturnConnectionError, I added a test for it in the same commit that fails without using the option. So, I would like to maintain it.

I can move in another PR the stats handler refactor and the reorder. WDYT?

@mstoykov
Copy link
Collaborator

mstoykov commented Feb 3, 2022

This was added in grpc/grpc-go#3430 which was released before the PR that added grpc to k6(and before the comment I linked to). I have no idea if this was just missed or is buggy and just doens't cover all cases 🤷 .

I guess if @rogchap might have some idea, as well as @na--. I have found only one issue grpc/grpc-go#4822, which seems not relevant, but there are others where it seems like TLS errors still seem to not work in some cases. Unfortunately I don't really understand enough to know if those matter or not for our case :(. Your test for example seems to handle what the issue is talking about so 🤷 .

If we can go back to the previous code and have this in a separate PR I think it will be better. We also (AFAIK) don't have that many gRPC users so an introduced bug here will likely stay there for while before we can fix it.

So if it isn't that much work I prefer if this gets split , sorry :(

p.s. thansk for the commit message, and sorry for skip reading it, but unfortunately I am not particularly certain this catches all the cases the previous one did :(

@codebien codebien force-pushed the grpc-modulev2 branch 4 times, most recently from ba43716 to 61886b9 Compare February 3, 2022 13:55
@codebien
Copy link
Collaborator Author

codebien commented Feb 3, 2022

@mstoykov @olegbespalov I restored the codebase without the Connect/dial split. I let only the change for the dedicated method for the parameters' parse.

Implemented the latest API for JS modules.
olegbespalov
olegbespalov previously approved these changes Feb 3, 2022
mstoykov
mstoykov previously approved these changes Feb 3, 2022
@mstoykov
Copy link
Collaborator

mstoykov commented Feb 3, 2022

2022/02/03 14:35:21 http: TLS handshake error from 127.0.0.1:50993: EOF
--- FAIL: TestClient (0.00s)
    --- FAIL: TestClient/BadTLS (0.11s)
        client_test.go:675: 
            	Error Trace:	client_test.go:675
            	            				client_test.go:717
            	Error:      	"GoError: context deadline exceeded at reflect.methodValueCall (native)" does not contain "certificate signed by unknown authority"
            	Test:       	TestClient/BadTLS
FAIL
FAIL	go.k6.io/k6/js/modules/k6/grpc	0.397s

seems to be because of the test

@codebien codebien dismissed stale reviews from mstoykov and olegbespalov via f4dbdec February 3, 2022 14:50
@codebien codebien merged commit 344e68f into master Feb 3, 2022
@codebien codebien deleted the grpc-modulev2 branch February 3, 2022 15:14
@codebien codebien linked an issue Feb 3, 2022 that may be closed by this pull request
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.

Migrate js/grpc to ModuleV2
3 participants