forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: migrate grpc-gateway from v1.16.0 to v2.7.0
The PR is trying to migrate the api package from gogo to google.golang.org/protobuf because the grpc-gateway runtime has been upgraded to use protobuf-go v2 API. It's impossible to use gogo with new version grpc-gateway and we can't re-generate all the proto codes by protobuf-go because the raftpb uses gogoproto.nullable to use non-pointer for message fileds, which protobuf-go doesn't support [1]. Fortunately, both `api/etcdserverpb/rpc.proto` and `server/etcdserver/api/v3electionpb/v3election.proto` doesn't use the `gogoproto.nullable` features to message filed. For the migration, we can just re-generate code for the following the protos as the approach: * api/**/*.proto * server/lease/leasepb/*.proto * server/etcdserver/api/snap/snappb/*.proto * server/etcdserver/api/v3election/v3electionpb/*.proto * server/etcdserver/api/v3lock/v3lockpb/*.proto Highlight the change for proto: * Use `protoc-gen-go-vtproto` to generate Marshal/Unmarshal/Size code for `gogoproto.{marshaler,unmarshaler,size,}_all` interface, instead of using proto package; * There is no way to support `gogoproto.goproto_enum_prefix_all`. So in this patch, I add `*.pb.ext.go` to add the const alias without prefix manually. Maybe we can build a proto binary as generator in the future; * Both `api/etcdserverpb/etcdserver.proto` and `server/etcdserver/api/snap/snappb/snap.proto` use `gogoproto.nullable = true` for builtin type. In this patch, I upgrade the proto syntax from `2` to `3` with `optional` features. We can re-generate the optional fileds as pointer by `--experimental_allow_proto3_optional`. Since it's syntax upgrade, the marshal methods is also changed. For instance, in proto3 syntax, if the bool is empty, the marshaler won't encode it [2]. It's compatible. Highlight the change for grpc-gateway: * The grpc-gateway/third_party/googleapis has been removed. We need to download the https://github.com/googleapis/googleapis.git to get the target proto. * The protobuf-go won't generate json tag for `oneOf` filed [3]. We have to use `sed` in `scripts/genproto.sh` to append the `tag` before upstream accepts the change [4]. * Both `Hash` and `HashKV` shares the one URL `/v3/maintenance/hash`. New grpc-gateway openapi can detect the error. So in this patch, we should use `/v3/maintenance/hashkv` for `HashKV`. * New grpc-gateway always renders default value in json payload. In this patch, we use set the `EmitUnpopulated: false`. * The error message of grpc-gateway has been changed. In v1.16.0, the error message is rendered by [6]. In v2.7.0, the `error` string has been removed [7]. [1]: <golang/protobuf#1225> [2]: <https://github.com/protocolbuffers/protobuf-go/blob/fc47fdd3d3fca5283fa9428ac94cf730236e4ca3/internal/impl/codec_gen.go#L74> [3]: <https://github.com/protocolbuffers/protobuf-go/blob/fc47fdd3d3fca5283fa9428ac94cf730236e4ca3/cmd/protoc-gen-go/internal_gengo/main.go#L814> [4]: <golang/protobuf#140> [5]: <https://github.com/grpc-ecosystem/grpc-gateway/blob/40ee80cbcc0751e0c943d4abc99ca4bd196bec3b/docs/docs/development/grpc-gateway_v2_migration_guide.md?plain=1#L92> [6]: <https://github.com/grpc-ecosystem/grpc-gateway/blob/v1.16.0/internal/errors.proto#L9> [7]: <https://github.com/googleapis/go-genproto/blob/e85fd2cbaebc/googleapis/rpc/status/status.pb.go#L46> Signed-off-by: Wei Fu <[email protected]>
- Loading branch information
Showing
87 changed files
with
42,276 additions
and
35,526 deletions.
There are no files selected for viewing
187 changes: 103 additions & 84 deletions
187
Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package authpb | ||
|
||
const ( | ||
READ Permission_Type = Permission_READ | ||
WRITE Permission_Type = Permission_WRITE | ||
READWRITE Permission_Type = Permission_READWRITE | ||
) |
Oops, something went wrong.