GithubHelp home page GithubHelp logo

connectrpc / grpcreflect-go Goto Github PK

View Code? Open in Web Editor NEW
71.0 71.0 7.0 191 KB

gRPC-compatible server reflection for any net/http server.

Home Page: https://connectrpc.com

License: Apache License 2.0

Makefile 4.85% Go 95.15%
connectrpc go grpc protobuf rpc

grpcreflect-go's People

Contributors

akshayjshah avatar bufdev avatar buildbreaker avatar chrispine avatar dependabot[bot] avatar drice-buf avatar emcfarlane avatar jhump avatar nyaplus avatar pkwarren avatar rubensf avatar smallsamantha avatar tiscs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpcreflect-go's Issues

Namespace conflict when using grpcreflect-go with connect-go

Hi guys, thanks for the awesome tool.
However, i'm facing this problem when using grpcreflect with connect-go.

WARNING: proto: file "connectext/grpc/status/v1/status.proto" is already registered
	previously from: "connectrpc.com/connect/internal/gen/connectext/grpc/status/v1"
	currently from:  "github.com/bufbuild/connect-go/internal/gen/connectext/grpc/status/v1"

The problem can be resolved if i add -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" to go run and go build command.
Is there any better way to resolve this problem ?
My version from go.mod
connectrpc.com/grpcreflect v1.2.0
github.com/bufbuild/connect-go v1.10.0

Expose Connect client for the gRPC reflection protocol

Trying to create a client that uses connect-go to communicate with a server that supports gRPC reflection is rather a hassle. Each such usage must use custom code generation (like this repo does) to avoid adding a dependency on google.golang.org/grpc/reflection (which would transitively bring in all of gRPC 😭). Given the name of this repo, it seems within bounds for this repo to provide that.

I know the API would want to avoid exposing the generated base types, for aesthetic reasons, but I don't think that's a very big lift. The only real question IMO is whether to drop it in the main grpcreflect package or to add a grpcreflectclient sub-package.

WDYT?

reflection works with grpcurl but not grpcui

grpcurl list and grpcurl describe both work, but the grpcui throws error

grpcui -plaintext localhost:8080
Failed to compute set of methods to expose: server does not support the reflection API

The grpcurl works

grpcurl -plaintext localhost:8080 list
api.v1.APIService
grpcurl -plaintext localhost:8080 describe
api.v1.APIService is a service:
service APIService {
  ....omitted....
}

version info

$ grpcui --version
grpcui 1.4.1

$ grpcurl --version
grpcurl dev build <no version set>

reflection error comes up with postman as well.

image

ErrorDetail issue with grpcurl

ErrorDetail issue with connect-grpcreflect-go v1.0.0 and grpcurl

May I submit a pull request?

Problem

When using connect-grpcreflect-go v1.0.0, ErrorDetail is not displayed when an error occurs in response to a request from the client.
This problem does not occur when using google.golang.org/grpc v1.51.0.

Difference in behavior

With 'google.golang.org/grpc v1.51.0'

https://github.com/2yanpath/grpc-error-detail-test

% grpcurl -plaintext -d '{"name": ""}' localhost:8081 greet.v1.GreetService.Greet
ERROR:
  Code: InvalidArgument
  Message: name is required
  Details:
  1)	{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"username","description":"should not empty"}]}

Expected respone

With 'connect-go v1.7.0' and 'connect-grpcreflect-go v1.0.0'

https://github.com/2yanpath/connect-error-detail-test
branch: main

% grpcurl -plaintext -d '{"name": ""}' localhost:8082 greet.v1.GreetService.Greet
ERROR:
  Code: InvalidArgument
  Message: name is required
  Details:
  1)	{"@error":"google.rpc.BadRequest is not recognized; see @value for raw binary message data","@type":"type.googleapis.com/google.rpc.BadRequest","@value":"ChwKCHVzZXJuYW1lEhBzaG91bGQgbm90IGVtcHR5"}

problem: ErrorDetail cannot be displayed.

[After fix] With 'connect-go v1.7.0' and 'connect-grpcreflect-go v1.0.0 based fix branch'

https://github.com/2yanpath/connect-error-detail-test
branch: fix/error-detail

% grpcurl -plaintext -d '{"name": ""}' localhost:8082 greet.v1.GreetService.Greet
ERROR:
  Code: InvalidArgument
  Message: name is required
  Details:
  1)	{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"username","description":"should not empty"}]}

Code difference

google.golang.org/grpc v1.51.0

serverreflection.go

// allExtensionNumbersForTypeName returns all extension numbers for the given type.
func (s *serverReflectionServer) allExtensionNumbersForTypeName(name string) ([]int32, error) {
	var numbers []int32
	s.extResolver.RangeExtensionsByMessage(protoreflect.FullName(name), func(xt protoreflect.ExtensionType) bool {
		numbers = append(numbers, int32(xt.TypeDescriptor().Number()))
		return true
	})
	sort.Slice(numbers, func(i, j int) bool {
		return numbers[i] < numbers[j]
	})
	if len(numbers) == 0 {
                 //-- NOTICE no error is thrown, so ([]int32{}, nil) is returned
		// maybe return an error if given type name is not known
		if _, err := s.descResolver.FindDescriptorByName(protoreflect.FullName(name)); err != nil {
			return nil, err
		}
	}
	return numbers, nil
}

connect-grpcreflect-go v1.0.0

grpcreflect.go

func (r *Reflector) getAllExtensionNumbersOfType(fqn string) ([]int32, error) {
	nums := []int32{}
	name := protoreflect.FullName(fqn)
	r.extensionResolver.RangeExtensionsByMessage(name, func(ext protoreflect.ExtensionType) bool {
		num := int32(ext.TypeDescriptor().Number())
		nums = append(nums, num)
		return true
	})
	if len(nums) == 0 {
                 //-- NOTICE an error occurs and (nil, [the error below]) is returned
		return nil, fmt.Errorf("no extensions for type %q", fqn)
	}
	sort.Slice(nums, func(i, j int) bool {
		return nums[i] < nums[j]
	})
	return nums, nil
}

[After fix] grpcreflect.go

func (r *Reflector) getAllExtensionNumbersOfType(fqn string) ([]int32, error) {
	nums := []int32{}
	name := protoreflect.FullName(fqn)
	r.extensionResolver.RangeExtensionsByMessage(name, func(ext protoreflect.ExtensionType) bool {
		num := int32(ext.TypeDescriptor().Number())
		nums = append(nums, num)
		return true
	})
	if len(nums) == 0 {
		if _, err := r.descriptorResolver.FindDescriptorByName(name); err != nil {
			return nil, err
		}
	}
	sort.Slice(nums, func(i, j int) bool {
		return nums[i] < nums[j]
	})
	return nums, nil
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.