grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.48k stars 816 forks source link

"reflection API" not working #566

Open einsitang opened 3 years ago

einsitang commented 3 years ago

The context

What do you wish to achieve?

use reflection API debug grpc-server

The bug

I checked grpc.server.reflection-service-enabledconfig istrue also ​@Bean @GrpcService protoReflectionService from net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration did worked.

but net.devh.boot.grpc.server.service.AnnotationGrpcServiceDiscoverer#findGrpcServices() line:55

Collection<String> beanNames =
                Arrays.asList(this.applicationContext.getBeanNamesForAnnotation(GrpcService.class));

is not get the bean protoReflectionService,look like applicationContext.getBeanNamesForAnnotation method can't get annotation on method @Bean ,only on class .

Steps to reproduce the behavior: just use grpcurl command:

grpcurl --plaintext localhost:26680 list
Failed to list services: server does not support the reflection API

The application's environment

Which versions do you use?

the feature reflection API is look like contributed by @ST-DDT ?

ST-DDT commented 3 years ago

You tested that GrpcReflectionServiceAutoConfiguration gets called first, but then it doesn't show up in AnnotationGrpcServiceDiscoverer?

Thats weird.

Could you run this test with your version setup?

einsitang commented 3 years ago

seem test fine .

is that because my project use spring boot 2.1.18 ?

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

18:30:56.460 [background-preinit] INFO  o.h.validator.internal.util.Version - HV000001: Hibernate Validator 6.1.7.Final
18:30:56.476 [Test worker] INFO  n.d.b.g.s.a.GrpcReflectionServiceDefaultAutoConfigurationTest - Starting GrpcReflectionServiceDefaultAutoConfigurationTest using Java 1.8.0_282 on EinsiTangdeMacBook-ProM1.local with PID 70356 (started by einsitang in /Users/einsitang/workspace/github/grpc-spring-boot-starter/grpc-server-spring-boot-autoconfigure)
18:30:56.476 [Test worker] DEBUG n.d.b.g.s.a.GrpcReflectionServiceDefaultAutoConfigurationTest - Running with Spring Boot v2.4.5, Spring v5.3.6
18:30:56.476 [Test worker] INFO  n.d.b.g.s.a.GrpcReflectionServiceDefaultAutoConfigurationTest - No active profile set, falling back to default profiles: default
18:30:56.796 [Test worker] INFO  n.d.b.g.s.a.GrpcServerFactoryAutoConfiguration - Detected grpc-netty-shaded: Creating ShadedNettyGrpcServerFactory
18:30:56.824 [Test worker] DEBUG n.d.b.g.s.i.AnnotationGlobalServerInterceptorConfigurer - Registering GlobalServerInterceptor: grpcRequestScope (net.devh.boot.grpc.server.scope.GrpcRequestScope@6b85a909)
18:30:56.828 [Test worker] DEBUG n.d.b.g.s.s.AnnotationGrpcServiceDiscoverer - Found gRPC service: grpc.reflection.v1alpha.ServerReflection, bean: protoReflectionService, class: io.grpc.protobuf.services.ProtoReflectionService
18:30:56.892 [Test worker] INFO  n.d.b.g.s.s.AbstractGrpcServerFactory - Registered gRPC service: grpc.reflection.v1alpha.ServerReflection, bean: protoReflectionService, class: io.grpc.protobuf.services.ProtoReflectionService
18:30:56.964 [Test worker] INFO  n.d.b.g.s.s.GrpcServerLifecycle - gRPC Server started, listening on address: *, port: 9090
18:30:56.968 [Test worker] INFO  n.d.b.g.s.a.GrpcReflectionServiceDefaultAutoConfigurationTest - Started GrpcReflectionServiceDefaultAutoConfigurationTest in 0.714 seconds (JVM running for 1.754)
18:30:57.313 [Test worker] DEBUG n.d.b.g.s.s.GrpcServerLifecycle - Initiating gRPC server shutdown
18:30:57.316 [Test worker] INFO  n.d.b.g.s.s.GrpcServerLifecycle - Completed gRPC server shutdown
Disconnected from the target VM, address: 'localhost:50630', transport: 'socket'
GrpcReflectionServiceDefaultAutoConfigurationTest > testReflectionService() PASSED
BUILD SUCCESSFUL in 13s
8 actionable tasks: 2 executed, 6 up-to-date
18:30:57: Task execution finished ':grpc-server-spring-boot-autoconfigure:test --tests "net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceDefaultAutoConfigurationTest.testReflectionService"'.
ST-DDT commented 3 years ago

is that because my project use spring boot 2.1.18 ?

I dont know. Thats why I asked you to run that test with your version setup. I'm on vacation and thus cannot verify it myself.

einsitang commented 3 years ago

Thanks, I will test later and tell you result

einsitang commented 3 years ago

@ST-DDT I can't build grpc-server-spring-boot-starter on latest(2.12.0.RELEASE) with my springboot version(2.1.18).

but I change grpc-server-spring-boot-starter version 2.9.0.RELEASE is work fine (gradle springBootVersion = '2.3.1.RELEASE')

that mean grpc-server-spring-boot-starter 2.12.0.RELEASE not support spring boot 2.1.18

maybe you should rewrite readme file to explain version support

ST-DDT commented 3 years ago

Thanks for bringing this to our attention. We will edit the Readme soon.