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

Fix gRPC and bidirectional examples' code generation instructions #250

Closed
wants to merge 5 commits into from

Conversation

2rs2ts
Copy link

@2rs2ts 2rs2ts commented Apr 11, 2023

Hello! My teammates and I were trying to get the grpc example to work, and were eventually able to figure out the things that needed to change to make its instructions, which seem to be around six years old, work with modern versions of protoc and the related Golang tooling for it. We decided that not only should we update the .proto file and generated code, we should also make sure that the two separate generated files (since there are two now, rather than one) get committed. In addition to that, we recorded some details in the README about how to find the versions of the software used to generate the code, for newbies to the codebase (like ourselves!) who didn't really know what was assumed about the development environment.

The updates to the client required us to also regenerate the Python plugin code, so we updated that and made sure we spelled out the dependencies that were used for that language. We found that we did have to manually re-insert the copyright notices to the python code, but not the Golang code; if there's an option in the generation command that fixes that, then we'd love to know about it.

We felt that recording the versions of various software dependencies used would not only help orient new users, but it would also make it easier in the future, if protoc or related tools introduce more breaking changes, to figure out what needs to change to make the instructions keep working. This is our first time using both this plugin repo and gRPC in general, and we're not experts with Golang either, so it may read as unnecessarily redundant information to an experienced developer, so we apologize for that. Also, we may not have written idiomatic code, but we're happy to take feedback and make sure it is idiomatic.

While we were at it, we also made the net/rpc example that lived in the grpc example's folder work. Before, it would fail with an error from rpc_server.go saying that it couldn't find the (hardcoded) kv_grpc plugin, which makes sense since the net/rpc plugin doesn't define that for obvious reasons.

And we also updated the bidirectional example since it's similar to the grpc example, plus we tested the other examples to ensure they still work, particularly the negotiated example which re-uses the grpc example's code. They all work on our machine, so hopefully they all work for you too.

Now, probably the most important change here is not to the example, but rather the top-level go.mod dependencies. The thing is, we were struggling to get things to work unless we upgraded the gRPC and protobuf dependencies to match modern guides (such as this one on grpc.io) unless we updated those dependencies. We were really hesitant to proceed until we noticed that the terraform-plugin-go repo uses the same grpc version and even a much more recent protobuf version, and if that repo is supposed to serve as a template or guide for people writing terraform plugins, and it's pretty married to gRPC, then upgrading would probably be fine. Also, our new generation instructions are based not only on those modern guides, but also how that repo generates its code too, so we felt pretty justified in our decisions after that. With that said, we understand that this repo is a dependency for many Hashicorp projects, so we're not sure whether we actually can upgrade those dependencies. Please let us know if we need to find a set of dependencies that will work for all consumers of this project.

At any rate, this fixes #249.

2rs2ts and others added 3 commits April 10, 2023 22:43
This was done using the latest release of protoc as of this authoring,
3.15.8. Whatever very old version of protoc was used before was not
stated, so in order to ensure that the example instructions still
worked, we wanted to use the latest available now. Updating the grpc and
protobuf dependencies was required, as well as adding the `go_package`
option to the .proto file.

This fixes hashicorp#249.

Co-authored-by: crashdummy101 <129228667+crashdummy101@users.noreply.github.com>
Co-authored-by: czavieh <czavieh@users.noreply.github.com>
We manually re-inserted the copyright notices, since the generated code
did not include them for some reason (even though it did for the golang
code.)

Co-authored-by: crashdummy101 <129228667+crashdummy101@users.noreply.github.com>
Co-authored-by: czavieh <czavieh@users.noreply.github.com>
We weren't sure why there is a net/rpc example in the grpc folder, but
it seemed like a waste for it to stay broken the way it was, so, this
code allows it to be used in the way documented by the README.

Co-authored-by: crashdummy101 <129228667+crashdummy101@users.noreply.github.com>
@hashicorp-cla
Copy link

hashicorp-cla commented Apr 11, 2023

CLA assistant check
All committers have signed the CLA.

@2rs2ts
Copy link
Author

2rs2ts commented Apr 11, 2023

Please accept my apologies about the delay in signing the CLA. I did not realize I had not already signed the CLA a long time ago, and I'm checking with my employer's legal department to make sure it's ok for me to sign it.

@2rs2ts
Copy link
Author

2rs2ts commented Apr 13, 2023

I got approval to sign from my employer. I am surprised that the bot does not require the commit co-authors to also sign, but I'll ask them to do it too.

Edit: we have all signed the CLA, so we should be good to go.

2rs2ts and others added 2 commits April 13, 2023 23:00
Co-authored-by: crashdummy101 <129228667+crashdummy101@users.noreply.github.com>
It's very similar to the gRPC example, and uses the same generation
process, so it needed to be updated in the same way. This wasn't on our
radar because we weren't referencing it, but after noticing that the
"negotiated" example was using the grpc example's code, we decided to
ensure all four examples were working as documented.

Of course, we also updated the README, and made sure to include a
.gitignore since this example was missing one.

Co-authored-by: crashdummy101 <129228667+crashdummy101@users.noreply.github.com>
@2rs2ts 2rs2ts changed the title Fix gRPC example's code generation instructions Fix gRPC and bidirectional examples' code generation instructions Apr 13, 2023
@heaxo
Copy link

heaxo commented May 9, 2023

Unknown flag: --go-grpc_opt

@2rs2ts
Copy link
Author

2rs2ts commented May 9, 2023

@heaxo you might have an out of date version of protoc or the golang/grpc plugins for it. While I used slightly newer versions of the libraries from this guide than are printed here (as you can tell from the generated code), I do believe the versions from here will also work: https://grpc.io/docs/languages/go/quickstart/

@2rs2ts
Copy link
Author

2rs2ts commented Jan 10, 2024

@tomhjp is my PR obsoleted by #286? I haven't had time to look deeply into it, but I'd be happy to close my PR if you can confirm

@tomhjp
Copy link
Contributor

tomhjp commented May 16, 2024

Hey @2rs2ts - I think you're right that most of this is obsoleted by #286, sorry about that and the delay responding. Comparing against main, it does look like your fix for the net/rpc example within grpc could still be landed, as it still looks broken to me on main. If you did want to land it, you could rebase the PR down to that change, but unfortunately I won't be help land that as I'll be losing write access to this repo later today. Thank you for the PR though! ❤️

@2rs2ts
Copy link
Author

2rs2ts commented Jun 3, 2024

It's been too long, and I don't remember a whole lot, but it seems that the new generation process would necessitate me starting from scratch, and I'd have to rewrite the PR summary. At that point, why even bother saving this branch? Hopefully this PR will be of some use to someone who does want to re-update the example for net/rpc. (We were not using it, we just made sure that if we were going to change one thing, we'd keep it all consistent...)

@2rs2ts 2rs2ts closed this Jun 3, 2024
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 example's proto regeneration command doesn't work
4 participants