Skip to content
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

Use grpc.reflection.v1.ServerReflection #407

Merged
merged 1 commit into from Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -14,7 +14,7 @@ This program accepts messages using JSON encoding, which is much more friendly f
humans and scripts.

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
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
Expand Down Expand Up @@ -192,7 +192,7 @@ are needed to use them.

### 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).

Expand Down
3 changes: 1 addition & 2 deletions cmd/grpcurl/grpcurl.go
Expand Up @@ -21,7 +21,6 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/descriptorpb"

Expand Down Expand Up @@ -508,7 +507,7 @@ func main() {
md := grpcurl.MetadataFromHeaders(append(addlHeaders, reflHeaders...))
refCtx := metadata.NewOutgoingContext(ctx, md)
cc = dial()
refClient = grpcreflect.NewClientV1Alpha(refCtx, reflectpb.NewServerReflectionClient(cc))
refClient = grpcreflect.NewClientAuto(refCtx, cc)
reflSource := grpcurl.DescriptorSourceFromServer(ctx, refClient)
if fileSource != nil {
descSource = compositeSource{reflSource, fileSource}
Expand Down
9 changes: 4 additions & 5 deletions grpcurl_test.go
Expand Up @@ -21,7 +21,6 @@ import (
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection"
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/grpc/status"

. "github.com/fullstorydev/grpcurl"
Expand Down Expand Up @@ -82,7 +81,7 @@ func TestMain(m *testing.M) {
panic(err)
}
defer ccReflect.Close()
refClient := grpcreflect.NewClientV1Alpha(context.Background(), reflectpb.NewServerReflectionClient(ccReflect))
refClient := grpcreflect.NewClientAuto(context.Background(), ccReflect)
defer refClient.Reset()

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

func TestServerDoesNotSupportReflection(t *testing.T) {
refClient := grpcreflect.NewClientV1Alpha(context.Background(), reflectpb.NewServerReflectionClient(ccNoReflect))
refClient := grpcreflect.NewClientAuto(context.Background(), ccNoReflect)
defer refClient.Reset()

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

if includeReflection {
// 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 {
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 {
// without reflection, we see all services defined in the same test.proto file, which is the
// TestService as well as UnimplementedService
Expand Down