-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Refactor prehog & teleterm protos to match project conventions #20810
Conversation
This makes them follow the pattern set out by api/proto and proto.
This also entailed changing the location of lib/teleterm protos and changing the value of their package specifier to match the conventions in other parts of the codebase. This is a breaking change but that is fine for Connect as the protos are used locally only and each build ships with matching protobufs.
We used to copy protobufs over to web/packages/teleterm/src/services/tshd since webapps used to be in a separate repo. This is no longer the case, so we can just make teleterm use protobufs from gen-proto-js.
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: github.com/gravitational/teleport/lib/prehog/gen |
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 had a short discussion with Edoardo about why we don't want to use managed mode here. Just copying what I said there:
Alan suggested that lib/prehog protos should use go_package to control the output location, that's why I disabled managed mode. Buf docs actually list some advantages for using managed mode.
In our case though not using managed mode and defining the location with go_package
instead means that we can use the same buf.gen.yaml
config for multiple Buf modules. That means that we have different buf.gen.yaml
for different sets of protoc plugins rather than a separate buf.gen.yaml
for each module.
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.
This is great, @ravicious. Thanks!
What do you think about unifying the paths even further? Ie, moving all non-api protos under proto/ and all generated code under gen/?
/ <-- teleport root
proto/
teleport/
lib/
prehog/ <- lib/prehog/proto goes here
teleterm/ <- lib/teleterm/api/proto goes here
gen/
proto/
go/ <- all Go generated files
js/ <- all Js generated files
This mirrors api/ and becomes a nice, unified place for all non-public protos (and corresponding generated code).
version: v1 | ||
plugins: | ||
- name: go | ||
path: lib/prehog/bin/protoc-gen-go |
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.
Not for this PR, but we should consolidate so we don't have tooling versions tracked by go.mod and tooling versions tracked via buildbox.
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 really like the idea of just needing go
to generate all the RPCs, but as that's no longer a possibility with grpc_node_plugin
anyway, I'm 👍
Could we backport the teleterm changes to v10 too? |
Oh yeah, that would work and we wouldn't need to have special handling of |
Do we ever rely on the horrible "add methods to a protobuf type" thing outside of |
Outside of api/types/ we don't; we even delete/recreate gen/ folders on codegen in order to "incentivize" not doing that. +1 for keeping generated code cleanly separate from manually-written code. |
@codingllama Take a look at the last two commits I pushed. Things accomplished in them:
Now, the biggest thing I need help with are package names. I didn't touch them at all. If I let the linter run on prehog and teleterm protos, I see these messages:
Does it mean that the proper packages for them would be I don't have much experience here so I'd follow whatever Buf recommends but I wonder if you have opinions on this. |
👍
I think only have 1 workspace, but 2 proto roots. Looks good to me.
👍
👍
That was my bad - packages names should match the directory structure, starting from the root of proto imports (which, in our case, is now This is what I suggest:
All prefixed with Generated paths follow the same paths as above:
I hope this helps! |
Yeah this helps a lot, thanks! I'll hack on it tomorrow, I'll also have to figure out how to selectively block linter rules (or maybe just fix them) but that seems easier than agreeing on package names. |
Are we supposed to change the package name for the prehog proto? It's not really a |
Do you mean whether the reporting team should take care of that or if we should consider renaming it at all? Also what do you consider to be the source of truth in this case? From what I see the proto files live here and gravitational/cloud only has the generated files. I'll take of renaming in this PR if we agree on the names. From what I gathered, changing the package name should be a backwards-compatible change unless prehog uses JSON encoding somewhere. |
Not sure why for the last merge commit GitHub is not showing only the changes that my PR did over what's on master, |
version: v1 | ||
plugins: | ||
- name: go | ||
path: lib/prehog/bin/protoc-gen-go |
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 really like the idea of just needing go
to generate all the RPCs, but as that's no longer a possibility with grpc_node_plugin
anyway, I'm 👍
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.
LGTM. Ship it!
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.
Teleterm changes look good too!
🙌 🙌 🙌 🙌 🙌 |
@ravicious See the table below for backport results.
|
* Adjust go_package of lib/prehog Go protobufs This makes them follow the pattern set out by api/proto and proto. * Adjust go_package of lib/teleterm Go protobufs * Use single buf.gen.yaml to generate JS protos This also entailed changing the location of lib/teleterm protos and changing the value of their package specifier to match the conventions in other parts of the codebase. This is a breaking change but that is fine for Connect as the protos are used locally only and each build ships with matching protobufs. * Make web/packages/teleterm use protobufs from gen-proto-js We used to copy protobufs over to web/packages/teleterm/src/services/tshd since webapps used to be in a separate repo. This is no longer the case, so we can just make teleterm use protobufs from gen-proto-js. * Move prehog & teleterm protos into proto/teleport/lib * Generate JS protos to gen/proto/js * Move lib/teleterm Go protobufs to gen/proto/go * Move lib/prehog Go protobufs to gen/proto/go * Rename lib/teleterm proto package * Re-enable linter rules for teleterm & prehog * Update prehogv1 path in usagereporter_test.go * Use except instead of ignore_only to allow Google API-style responses * Add UNARY_RPC to api/proto & proto * Ignore gen/ when running addlicense * buf-js.gen.yaml: Remove comment about lack of go_package for JS * Move prehog protos to proto/prehog/v1alpha * Adjust prehog's go_package to match proto package
… (#21298) * Moved prehog's and teleterm's proto files from their respective `lib/` dir to `proto/`. * Updated `go_package` of `lib/prehog` and `lib/teleterm` protobufs to match conventions used by `api/proto` and `proto`. * `lib/prehog` Go protobufs now live in a different location: * `lib/prehog/gen/prehog/v1alpha` before * `gen/proto/go/prehog/v1alpha` now * `lib/teleterm` Go protobufs now live in a different location: * `lib/teleterm/api/protogen/golang/v1` before * `gen/proto/go/teleport/lib/teleterm/v1/` now * proto package name has been updated to match the new location. * `lib/prehog` no longer uses managed mode to set `go_package_prefix`. * JS protobufs for both packages now live in `gen/proto/js` in the root folder. * Connect no longer needs to copy protobufs to its own directory. * Instead it uses protobufs from `gen/proto/js` so that any change done through `make grpc` is automatically picked up by Connect.
v11 and v10 backports should also include the followup fix for Teleport Operator. #21362 |
* Moved teleterm's proto files from their respective `lib/` dir to `proto/`. * Updated `go_package` of `lib/teleterm` protobufs to match conventions used by `api/proto` and `proto`. * `lib/teleterm/api/protogen/golang/v1` before * `gen/proto/go/teleport/lib/teleterm/v1/` now * proto package name has been updated to match the new location. * JS protobufs for now live in `gen/proto/js` in the root folder. * Connect no longer needs to copy protobufs to its own directory. * Instead it uses protobufs from `gen/proto/js` so that any change done through `make grpc` is automatically picked up by Connect.
* Moved teleterm's proto files from their respective `lib/` dir to `proto/`. * Updated `go_package` of `lib/teleterm` protobufs to match conventions used by `api/proto` and `proto`. * `lib/teleterm/api/protogen/golang/v1` before * `gen/proto/go/teleport/lib/teleterm/v1/` now * proto package name has been updated to match the new location. * JS protobufs for now live in `gen/proto/js` in the root folder. * Connect no longer needs to copy protobufs to its own directory. * Instead it uses protobufs from `gen/proto/js` so that any change done through `make grpc` is automatically picked up by Connect.
* Moved teleterm's proto files from their respective `lib/` dir to `proto/`. * Updated `go_package` of `lib/teleterm` protobufs to match conventions used by `api/proto` and `proto`. * `lib/teleterm/api/protogen/golang/v1` before * `gen/proto/go/teleport/lib/teleterm/v1/` now * proto package name has been updated to match the new location. * JS protobufs for now live in `gen/proto/js` in the root folder. * Connect no longer needs to copy protobufs to its own directory. * Instead it uses protobufs from `gen/proto/js` so that any change done through `make grpc` is automatically picked up by Connect.
Summary of changes:
lib/
dir toproto/
.go_package
oflib/prehog
andlib/teleterm
protobufs to match conventions used byapi/proto
andproto
.lib/prehog
Go protobufs now live in a different location:lib/prehog/gen/prehog/v1alpha
beforegen/proto/go/prehog/v1alpha
nowlib/teleterm
Go protobufs now live in a different location:lib/teleterm/api/protogen/golang/v1
beforegen/proto/go/teleport/lib/teleterm/v1/
nowlib/prehog
no longer uses managed mode to setgo_package_prefix
.gen/proto/js
in the root folder.gen/proto/js
so that any change done throughmake grpc
is automatically picked up by Connect.This is a followup to #19774 where I promised to further refactor JS protos at a later date.
I requested review from multiple people so that each person can look at the PR from a slightly different angle:
lib/prehog
changeslib/teleterm
changes