armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Support adding gRPC interceptors using annotation '@GrpcInterceptor'

Open Dogacel opened this issue 1 year ago โ€ข 5 comments

Motivation:

#5359

Adding annotations to add interceptors to gRPC services and methods.

Modifications:

  • Create the GrpcInterceptor annotation.
  • Update GrpcServerBuilder to find interceptors defined by annotations on gRPC servers and methods.

Result:

  • Closes #5359

The way services are added to the HandlerRegistry has changed slightly, now we are not adding the whole Service objects as an entry but rather we find all MethodDescriptors under those services and add those methods one by one as Entry objects. The reason is that we can't create a single interceptor under a single Service object that would intercept individual methods, those methods need to be added as separate entries.

It can be checked if there is any method interception annotations and if there isn't any, it can fallback to the legacy logic (add the whole Service object as an Entry).

Question Do you think adding each method as a separate Entry would create performance issues?

Also, let me know if the interceptor order looks right based on the test.

Dogacel avatar Jan 21 '24 03:01 Dogacel

๐Ÿ” Build Scanยฎ (commit: fdccead176b725c007689e1143fdb8a6392ce789)

Job name Status Build Scanยฎ
build-windows-latest-jdk-21 โœ… https://ge.armeria.dev/s/4xyrseb4wymye
build-self-hosted-unsafe-jdk-8 โœ… https://ge.armeria.dev/s/sjttku4b75fwy
build-self-hosted-unsafe-jdk-21-snapshot-blockhound โŒ (failure) https://ge.armeria.dev/s/ibruz3okmyimq
build-self-hosted-unsafe-jdk-17-min-java-17-coverage โœ… https://ge.armeria.dev/s/sdoymsocgvpmc
build-self-hosted-unsafe-jdk-17-min-java-11 โœ… https://ge.armeria.dev/s/maoz6xuu4bxee
build-self-hosted-unsafe-jdk-17-leak โœ… https://ge.armeria.dev/s/pr7lq5tfweezm
build-self-hosted-unsafe-jdk-11 โœ… https://ge.armeria.dev/s/w22tspw5kbe6e
build-macos-12-jdk-21 โŒ (failure) https://ge.armeria.dev/s/yvy75by4g4qic

github-actions[bot] avatar Jan 21 '24 03:01 github-actions[bot]

Codecov Report

Attention: Patch coverage is 88.31169% with 9 lines in your changes missing coverage. Please review.

Project coverage is 74.01%. Comparing base (14c5566) to head (78e9d53). Report is 72 commits behind head on main.

:exclamation: Current head 78e9d53 differs from pull request most recent head 89f1b76

Please upload reports for the commit 89f1b76 to get more accurate results.

Files Patch % Lines
.../linecorp/armeria/server/grpc/HandlerRegistry.java 89.18% 3 Missing and 5 partials :warning:
...necorp/armeria/server/grpc/GrpcServiceBuilder.java 66.66% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5397      +/-   ##
============================================
- Coverage     74.05%   74.01%   -0.04%     
+ Complexity    21253    20745     -508     
============================================
  Files          1850     1800      -50     
  Lines         78600    76488    -2112     
  Branches      10032     9737     -295     
============================================
- Hits          58209    56615    -1594     
+ Misses        15686    15263     -423     
+ Partials       4705     4610      -95     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 04 '24 17:02 codecov[bot]

I think this PR looks good. Is there anything left for discussion or feedback, @Dogacel ?

I don't think anything left for discussion, @minwoox 's comment should be resolved now ๐Ÿ™‚ I merged latest master to double check the state of the tests.

Dogacel avatar Apr 10 '24 14:04 Dogacel

Bump ^ ๐Ÿ™‚ Seems like this was forgotten

Dogacel avatar Jul 29 '24 14:07 Dogacel