Skip to content

Commit 11bfac0

Browse files
authored
Support grpc.reflection.v1.ServerReflection (#314)
Currently, `grpc.reflection.v1.ServerReflection` is shown in the list of `Service Name`. This PR removes it as well as `grpc.reflection.v1alpha.ServerReflection`. Also, change to use `v1` protocol if we can use it.
1 parent 0d16d85 commit 11bfac0

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GUI. This lets you interactively construct requests to send to a gRPC server.
1212

1313
With this tool you can also browse the schema for gRPC services, which is presented as a
1414
list of available endpoints. This is enabled either by querying a server that supports
15-
[server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto),
15+
[server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto),
1616
by reading proto source files, or by loading in compiled "protoset" files (files that contain
1717
encoded file [descriptor protos](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto)).
1818
In fact, the way the tool transforms JSON request data into a binary encoded protobuf
@@ -82,7 +82,7 @@ run `make install`.
8282
If you encounter compile errors, you could have out-dated versions of `grpcui`'s
8383
dependencies. You can update the dependencies by running `make updatedeps`.
8484

85-
### Running without install
85+
### Running without install
8686

8787
```
8888
go run ./cmd/grpcui/grpcui.go -plaintext localhost:9019
@@ -230,7 +230,7 @@ into text. The sections below document the supported sources and what command-li
230230
are needed to use them.
231231

232232
### Server Reflection
233-
Without any additional command-line flags, `grpcui` will try to use [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1alpha/reflection.proto).
233+
Without any additional command-line flags, `grpcui` will try to use [server reflection](https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto).
234234

235235
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).
236236

cmd/grpcui/grpcui.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"google.golang.org/grpc/grpclog"
3636
"google.golang.org/grpc/keepalive"
3737
"google.golang.org/grpc/metadata"
38-
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
3938

4039
// Register gzip compressor so compressed responses will work
4140
_ "google.golang.org/grpc/encoding/gzip"
@@ -564,7 +563,7 @@ func main() {
564563
if reflection.val {
565564
md := grpcurl.MetadataFromHeaders(append(addlHeaders, reflHeaders...))
566565
refCtx := metadata.NewOutgoingContext(ctx, md)
567-
refClient = grpcreflect.NewClientV1Alpha(refCtx, reflectpb.NewServerReflectionClient(cc))
566+
refClient = grpcreflect.NewClientAuto(refCtx, cc)
568567
refClient.AllowMissingFileDescriptors()
569568
reflSource := grpcurl.DescriptorSourceFromServer(ctx, refClient)
570569
if fileSource != nil {
@@ -859,7 +858,7 @@ func getMethods(source grpcurl.DescriptorSource, configs map[string]*svcConfig)
859858

860859
var descs []*desc.MethodDescriptor
861860
for _, svc := range allServices {
862-
if svc == "grpc.reflection.v1alpha.ServerReflection" {
861+
if svc == "grpc.reflection.v1alpha.ServerReflection" || svc == "grpc.reflection.v1.ServerReflection" {
863862
continue
864863
}
865864
d, err := source.FindSymbol(svc)

files.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/jhump/protoreflect/grpcreflect"
66
"golang.org/x/net/context"
77
"google.golang.org/grpc"
8-
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
98
"google.golang.org/protobuf/reflect/protoreflect"
109
"google.golang.org/protobuf/reflect/protoregistry"
1110

@@ -18,8 +17,7 @@ import (
1817
// reflection. (See "google.golang.org/grpc/reflection" for more on service
1918
// reflection.)
2019
func AllFilesViaReflection(ctx context.Context, cc grpc.ClientConnInterface) ([]*desc.FileDescriptor, error) {
21-
stub := rpb.NewServerReflectionClient(cc)
22-
cli := grpcreflect.NewClientV1Alpha(ctx, stub)
20+
cli := grpcreflect.NewClientAuto(ctx, cc)
2321
source := grpcurl.DescriptorSourceFromServer(ctx, cli)
2422
return grpcurl.GetAllFiles(source)
2523
}

methods.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"golang.org/x/net/context"
77
"google.golang.org/grpc"
88
"google.golang.org/grpc/reflection"
9-
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
109
)
1110

1211
// AllMethodsForServices returns a slice that contains the method descriptors
@@ -47,8 +46,7 @@ func AllMethodsForServer(svr *grpc.Server) ([]*desc.MethodDescriptor, error) {
4746
// This automatically skips the reflection service, since it is assumed this is not
4847
// a desired inclusion.
4948
func AllMethodsViaReflection(ctx context.Context, cc grpc.ClientConnInterface) ([]*desc.MethodDescriptor, error) {
50-
stub := rpb.NewServerReflectionClient(cc)
51-
cli := grpcreflect.NewClientV1Alpha(ctx, stub)
49+
cli := grpcreflect.NewClientAuto(ctx, cc)
5250
svcNames, err := cli.ListServices()
5351
if err != nil {
5452
return nil, err
@@ -59,7 +57,8 @@ func AllMethodsViaReflection(ctx context.Context, cc grpc.ClientConnInterface) (
5957
if err != nil {
6058
return nil, err
6159
}
62-
if sd.GetFullyQualifiedName() == "grpc.reflection.v1alpha.ServerReflection" {
60+
fullyQualifiedName := sd.GetFullyQualifiedName()
61+
if fullyQualifiedName == "grpc.reflection.v1alpha.ServerReflection" || fullyQualifiedName == "grpc.reflection.v1.ServerReflection" {
6362
continue // skip reflection service
6463
}
6564
descs = append(descs, sd)
@@ -78,7 +77,8 @@ func AllMethodsViaInProcess(svr reflection.GRPCServer) ([]*desc.MethodDescriptor
7877
}
7978
var descs []*desc.ServiceDescriptor
8079
for _, sd := range sds {
81-
if sd.GetFullyQualifiedName() == "grpc.reflection.v1alpha.ServerReflection" {
80+
fullyQualifiedName := sd.GetFullyQualifiedName()
81+
if fullyQualifiedName == "grpc.reflection.v1alpha.ServerReflection" || fullyQualifiedName == "grpc.reflection.v1.ServerReflection" {
8282
continue // skip reflection service
8383
}
8484
descs = append(descs, sd)

testing/cmd/testsvr/testsvr.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"google.golang.org/grpc/codes"
1818
"google.golang.org/grpc/metadata"
1919
"google.golang.org/grpc/reflection"
20-
reflectionpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
20+
reflectionpb "google.golang.org/grpc/reflection/grpc_reflection_v1"
2121
"google.golang.org/grpc/status"
2222
"google.golang.org/protobuf/proto"
2323
"google.golang.org/protobuf/types/known/anypb"
@@ -49,7 +49,7 @@ func main() {
4949

5050
svr := grpc.NewServer()
5151
RegisterKitchenSinkServer(svr, &testSvr{})
52-
refSvc := reflection.NewServer(reflection.ServerOptions{
52+
refSvc := reflection.NewServerV1(reflection.ServerOptions{
5353
Services: svr,
5454
DescriptorResolver: sourceinfo.GlobalFiles,
5555
ExtensionResolver: sourceinfo.GlobalFiles,

0 commit comments

Comments
 (0)