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 a Connection Broker for GRPC plugins #52

Merged
merged 9 commits into from
Jan 18, 2018
Merged

Conversation

briankassouf
Copy link
Member

@briankassouf briankassouf commented Jan 11, 2018

This adds a broker object that can serve and dial connections via connection ids. It uses a streaming gRPC service to communicate the connection details between a client and a plugin. Each AcceptAndServe call opens a new listener socket and sends the connection info down the stream to the dialer. Since a new connection is opened every call, these calls should be used sparingly. Multiple gRPC server implementations can be registered to a single AcceptAndServe call.

Plugins written in another language will, optionally, have to implement the gRPC server/client for the broker, but we provide the proto file for this definition.

Unfortunately there is a slight API breaking change with the GRPCPlugin interface. The GRPCServer and GRPCClient now accept a GRPCBroker as the first parameter. Open to ideas on how to make this BC.

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Wow, great work and clever implementation. Also happens to align well with the net/rpc style which is a huge plus.

I may be missing something, but where is newGRPCBroker and such functions? Curious what their lifecycle is like and I can't seem to find them.

@briankassouf
Copy link
Member Author

@mitchellh The newGRPCBroker function is here: https://github.com/hashicorp/go-plugin/pull/52/files#diff-d87e36aaf5ae95071a965d9f6d6d40bdR273

In that file is the implementation of the GRPCBroker as well as the server/client used for the gRPC stream.

@calvn calvn self-requested a review January 17, 2018 17:38
Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Whew, took a bit to work through this but this looks good.

It'd be great to see docs on how this works put into the docs/ folder. That is a recent addition (with initial grpc) so its less in depth but I'd like to start making sure we update that so that the whole system is easier to understand going forward.

Get(key string) (int64, error)
}

// This is the implementation of plugin.Plugin so we can serve/consume this.
Copy link
Member

@calvn calvn Jan 17, 2018

Choose a reason for hiding this comment

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

Should be plugin.GRPCPlugin instead of plugin.Plugin.

Nevermind, this embeds plugin.NetRPCUnsupportedPlugin which is the plugin.Plugin implementation.

grpc_broker.go Outdated
return
case <-s.quit:
return
case s := <-s.send:
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit, but perhaps rename s into something else, since s initially refers to *gRPCBrokerServer, but after the assignment it's a *sendErr. Even though there's not conflict in overriding s in this case, it makes it somewhat harder to read. Same for StartStream on the client side.

@briankassouf briankassouf merged commit 4b3b291 into master Jan 18, 2018
@briankassouf briankassouf deleted the grpc-broker branch January 18, 2018 02:43
briankassouf pushed a commit that referenced this pull request Mar 14, 2018
This commit fixes the plugin-go-grpc example to use the updated
GRPCPlugin interface introduced in #52 and #55.

Prior to this change attempts to initialise the plugin would fail
with an `is not a GRPC-compatible plugin` error.

Signed-off-by: John McCabe <john@johnmccabe.net>
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.

None yet

3 participants