Use `grpc.reflection.v1.ServerReflection`

The proper `v1` gRPC reflection has been around for a bit.
The "client auto" mechanism still supports falling back to `v1alpha`.
Not many support the `v1`, but we should default to it when possible.
This commit is contained in:
Valters Jansons 2023-08-26 00:13:12 +03:00
parent 9a59bed1d2
commit 918921431d
No known key found for this signature in database
GPG Key ID: 4F021EB3A83CE748
3 changed files with 7 additions and 9 deletions

View File

@ -14,7 +14,7 @@ This program accepts messages using JSON encoding, which is much more friendly f
humans and scripts. humans and scripts.
With this tool you can also browse the schema for gRPC services, either by querying With this tool you can also browse the schema for gRPC services, either by querying
a server that supports [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto), a server that supports [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto),
by reading proto source files, or by loading in compiled "protoset" files (files that contain by reading proto source files, or by loading in compiled "protoset" files (files that contain
encoded file [descriptor protos](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto)). encoded file [descriptor protos](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto)).
In fact, the way the tool transforms JSON request data into a binary encoded protobuf In fact, the way the tool transforms JSON request data into a binary encoded protobuf
@ -192,7 +192,7 @@ are needed to use them.
### Server Reflection ### Server Reflection
Without any additional command-line flags, `grpcurl` will try to use [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto). Without any additional command-line flags, `grpcurl` will try to use [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto).
Examples for how to set up server reflection can be found [here](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md#known-implementations). Examples for how to set up server reflection can be found [here](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md#known-implementations).

View File

@ -21,7 +21,6 @@ import (
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive" "google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/descriptorpb" "google.golang.org/protobuf/types/descriptorpb"
@ -508,7 +507,7 @@ func main() {
md := grpcurl.MetadataFromHeaders(append(addlHeaders, reflHeaders...)) md := grpcurl.MetadataFromHeaders(append(addlHeaders, reflHeaders...))
refCtx := metadata.NewOutgoingContext(ctx, md) refCtx := metadata.NewOutgoingContext(ctx, md)
cc = dial() cc = dial()
refClient = grpcreflect.NewClientV1Alpha(refCtx, reflectpb.NewServerReflectionClient(cc)) refClient = grpcreflect.NewClientAuto(refCtx, cc)
reflSource := grpcurl.DescriptorSourceFromServer(ctx, refClient) reflSource := grpcurl.DescriptorSourceFromServer(ctx, refClient)
if fileSource != nil { if fileSource != nil {
descSource = compositeSource{reflSource, fileSource} descSource = compositeSource{reflSource, fileSource}

View File

@ -21,7 +21,6 @@ import (
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
. "github.com/fullstorydev/grpcurl" . "github.com/fullstorydev/grpcurl"
@ -82,7 +81,7 @@ func TestMain(m *testing.M) {
panic(err) panic(err)
} }
defer ccReflect.Close() defer ccReflect.Close()
refClient := grpcreflect.NewClientV1Alpha(context.Background(), reflectpb.NewServerReflectionClient(ccReflect)) refClient := grpcreflect.NewClientAuto(context.Background(), ccReflect)
defer refClient.Reset() defer refClient.Reset()
sourceReflect = DescriptorSourceFromServer(context.Background(), refClient) sourceReflect = DescriptorSourceFromServer(context.Background(), refClient)
@ -118,7 +117,7 @@ func TestMain(m *testing.M) {
} }
func TestServerDoesNotSupportReflection(t *testing.T) { func TestServerDoesNotSupportReflection(t *testing.T) {
refClient := grpcreflect.NewClientV1Alpha(context.Background(), reflectpb.NewServerReflectionClient(ccNoReflect)) refClient := grpcreflect.NewClientAuto(context.Background(), ccNoReflect)
defer refClient.Reset() defer refClient.Reset()
refSource := DescriptorSourceFromServer(context.Background(), refClient) refSource := DescriptorSourceFromServer(context.Background(), refClient)
@ -216,11 +215,11 @@ func doTestListMethods(t *testing.T, source DescriptorSource, includeReflection
if includeReflection { if includeReflection {
// when using server reflection, we see the TestService as well as the ServerReflection service // when using server reflection, we see the TestService as well as the ServerReflection service
names, err = ListMethods(source, "grpc.reflection.v1alpha.ServerReflection") names, err = ListMethods(source, "grpc.reflection.v1.ServerReflection")
if err != nil { if err != nil {
t.Fatalf("failed to list methods for ServerReflection: %v", err) t.Fatalf("failed to list methods for ServerReflection: %v", err)
} }
expected = []string{"grpc.reflection.v1alpha.ServerReflection.ServerReflectionInfo"} expected = []string{"grpc.reflection.v1.ServerReflection.ServerReflectionInfo"}
} else { } else {
// without reflection, we see all services defined in the same test.proto file, which is the // without reflection, we see all services defined in the same test.proto file, which is the
// TestService as well as UnimplementedService // TestService as well as UnimplementedService