-
Notifications
You must be signed in to change notification settings - Fork 232
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
plugin: Serve via tf5server/tf6server rather than go-plugin directly #857
Conversation
Will rebase now due to [email protected] merging in. |
af4b73a
to
67c6c2e
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.
I can't pretend to understand fully this, but I'm giving it a go.
So, here you are making the call to Serve
use tf5server
and tf6server
, instead of creating a new grcp.Server
. I have to assume this was a "transitional state", where a GRPC Server was added to TF5 and TF6 but not used yet?
Anyway, I left some comments on the logging, thinking that it might useful if the "unrecoverable errors" that you are logging can be .Fatal
or .Panic
.
Given this is not just a style thing like the PR from yesterday, I think I need to hold the Approval for now: I'm not confident enough in my understanding :)
@@ -69,6 +84,11 @@ type ServeOpts struct { | |||
// Serve serves a plugin. This function never returns and should be the final | |||
// function called in the main function of the plugin. | |||
func Serve(opts *ServeOpts) { | |||
if opts.Debug && opts.TestConfig != nil { | |||
log.Printf("[ERROR] Error starting provider: cannot set both Debug and TestConfig") |
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.
Question: I assume that changing the interface of the plugin
to return an error via Serve
would be madness (right?). But I do see that you are checking for a mutually exclusive "either Debug
or TestConfig
".
Would it make sense for the log.
call to be log.Fatal
or log.Panic
? I'd vote for Fatal
as it also calls exit(1)
, and that is what I'd presume we want (the provider process exiting with a POSIX error).
Am I making any sense?
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.
Given Serve
is exported and effectively in use by every provider developed on top of this SDK (or any wrapping logic developed externally), we need to be very careful about breaking changes, both in Go terms and potential usage.
Since there are no returns now, any calling code wouldn't necessarily be checking for the error return upon upgrading. Calling codebases would need to be using something like the errcheck
linter to catch the issue, which we cannot assume, and introducing the new errcheck
issue (for those using it) is probably "breaking" enough. Any external Go types that alias the function would also receive the breaking change.
We also cannot assume how callers were interacting with this function. For example, there's no requirement it is only called by main
function in provider binaries where it would generally be appropriate to exit(1). There are potential use cases where providers are served as part of other logic and the unilateral decision to exit the Go runtime would be very inappropriate for us to introduce.
Whether we should separately introduce a "Serve" function that has an error return to be more correct in this situation is likely debatable -- no one has asked for it yet and errors (if they didn't already panic or exit themselves as part of the called logic) were previously swallowed. I agree in principle that its probably something that should exist, but I'd love to hear the demand and use cases before extending the package surface area, especially since going forward we are encouraging folks to use the new framework, rather than this one.
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.
There are potential use cases where providers are served as part of other logic and the unilateral decision to exit the Go runtime would be very inappropriate for us to introduce.
Absolutely!
Logger: opts.Logger, | ||
Test: opts.TestConfig, | ||
if err != nil { | ||
log.Printf("[ERROR] Error starting provider: %s", err) |
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.
Same comment about the .Fatal
here. If this fails, definitely the provider isn't working (and will exit(0)
).
It indeed is a transitional state, but maybe not in the way you're alluding. 😄 The brief historical context here:
However, the server handling hasn't been migrated yet and here we are! This will standardize |
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.
Thanks for the clarification.
It makes perfect sense: the amount of ways that a change like that can go wrong is just too much.
LGTM
Since there's #650, I'm going to add an enhancement changelog entry for this to match the upstream one: https://github.com/hashicorp/terraform-plugin-go/pull/139/files |
We should hold off merging or releasing this until hashicorp/terraform-plugin-go#153 is reviewed, merged, released, and the dependency updated. Refer to hashicorp/terraform-plugin-go#152 for additional context. |
Providers will automatically receive upstream enhancements to provider servers, including protocol logging. Lower level dependencies in this SDK, such as gRPC and go-plugin versions, can instead be managed upstream, which will ensure consistency across the SDKs.
3b5650f
to
3fb4027
Compare
#884 was merged with the necessary |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #650
Providers will automatically receive upstream enhancements to provider servers, including protocol logging and the increased gRPC message limit. Lower level dependencies in this SDK, such as gRPC and go-plugin versions, can instead be managed upstream, which will ensure consistency across the SDKs.