Skip to content

Commit 2a29c1e

Browse files
authored
Use grpc.reflection.v1.ServerReflection (#407)
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.
1 parent 9a59bed commit 2a29c1e

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This program accepts messages using JSON encoding, which is much more friendly f
1414
humans and scripts.
1515

1616
With this tool you can also browse the schema for gRPC services, either by querying
17-
a server that supports [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto),
17+
a server that supports [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto),
1818
by reading proto source files, or by loading in compiled "protoset" files (files that contain
1919
encoded file [descriptor protos](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto)).
2020
In fact, the way the tool transforms JSON request data into a binary encoded protobuf
@@ -192,7 +192,7 @@ are needed to use them.
192192

193193
### Server Reflection
194194

195-
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).
195+
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).
196196

197197
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).
198198

cmd/grpcurl/grpcurl.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"google.golang.org/grpc/credentials"
2222
"google.golang.org/grpc/keepalive"
2323
"google.golang.org/grpc/metadata"
24-
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
2524
"google.golang.org/grpc/status"
2625
"google.golang.org/protobuf/types/descriptorpb"
2726

@@ -508,7 +507,7 @@ func main() {
508507
md := grpcurl.MetadataFromHeaders(append(addlHeaders, reflHeaders...))
509508
refCtx := metadata.NewOutgoingContext(ctx, md)
510509
cc = dial()
511-
refClient = grpcreflect.NewClientV1Alpha(refCtx, reflectpb.NewServerReflectionClient(cc))
510+
refClient = grpcreflect.NewClientAuto(refCtx, cc)
512511
reflSource := grpcurl.DescriptorSourceFromServer(ctx, refClient)
513512
if fileSource != nil {
514513
descSource = compositeSource{reflSource, fileSource}

grpcurl_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"google.golang.org/grpc/credentials/insecure"
2222
"google.golang.org/grpc/metadata"
2323
"google.golang.org/grpc/reflection"
24-
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
2524
"google.golang.org/grpc/status"
2625

2726
. "github.com/fullstorydev/grpcurl"
@@ -82,7 +81,7 @@ func TestMain(m *testing.M) {
8281
panic(err)
8382
}
8483
defer ccReflect.Close()
85-
refClient := grpcreflect.NewClientV1Alpha(context.Background(), reflectpb.NewServerReflectionClient(ccReflect))
84+
refClient := grpcreflect.NewClientAuto(context.Background(), ccReflect)
8685
defer refClient.Reset()
8786

8887
sourceReflect = DescriptorSourceFromServer(context.Background(), refClient)
@@ -118,7 +117,7 @@ func TestMain(m *testing.M) {
118117
}
119118

120119
func TestServerDoesNotSupportReflection(t *testing.T) {
121-
refClient := grpcreflect.NewClientV1Alpha(context.Background(), reflectpb.NewServerReflectionClient(ccNoReflect))
120+
refClient := grpcreflect.NewClientAuto(context.Background(), ccNoReflect)
122121
defer refClient.Reset()
123122

124123
refSource := DescriptorSourceFromServer(context.Background(), refClient)
@@ -216,11 +215,11 @@ func doTestListMethods(t *testing.T, source DescriptorSource, includeReflection
216215

217216
if includeReflection {
218217
// when using server reflection, we see the TestService as well as the ServerReflection service
219-
names, err = ListMethods(source, "grpc.reflection.v1alpha.ServerReflection")
218+
names, err = ListMethods(source, "grpc.reflection.v1.ServerReflection")
220219
if err != nil {
221220
t.Fatalf("failed to list methods for ServerReflection: %v", err)
222221
}
223-
expected = []string{"grpc.reflection.v1alpha.ServerReflection.ServerReflectionInfo"}
222+
expected = []string{"grpc.reflection.v1.ServerReflection.ServerReflectionInfo"}
224223
} else {
225224
// without reflection, we see all services defined in the same test.proto file, which is the
226225
// TestService as well as UnimplementedService

0 commit comments

Comments
 (0)