armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Implement @Attribute Injection.

Open chickenchickenlove opened this issue 10 months ago โ€ข 10 comments

Motivation:

  • In the past, users could get a value from ServiceRequestContext by using ServiceRequestContext.attr(key). however, if it were possible to inject values which in ServiceRequestContext into method parameters using any annotation, users would be able to use it more conveniently.

Modifications:

  • New annotation. @Attribute is added.
  • Make new field rawType in AnnotatedValueResolver to validate type cast.
  • New methods ofAttribute() and attributeResolver() are added to AnnotatedValueResolver to get values from ServiceRequestContext and inject them method parameters.
  • findName() in AnnotatedElementNameUtil method have been merged into a single method. (refactoring for internal use)
  • Add test codes.
  • Add document explaining how to use the @Attribute annotation.

Result:

  • Closes https://github.com/line/armeria/issues/5514
  • Users can inject values from the ServiceRequestContext into method parameters using the @Attribute annotation without ServiceRequestContext.attr(key).

chickenchickenlove avatar Mar 29 '24 08:03 chickenchickenlove

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 29 '24 08:03 CLAassistant

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

Job name Status Build Scanยฎ
build-windows-latest-jdk-19 โœ… https://ge.armeria.dev/s/lu7vfihw5qooe
build-self-hosted-unsafe-jdk-8 โœ… https://ge.armeria.dev/s/bockuhidf4g3s
build-self-hosted-unsafe-jdk-19-snapshot-blockhound โœ… https://ge.armeria.dev/s/4qbeilnrztoqq
build-self-hosted-unsafe-jdk-17-min-java-17-coverage โœ… https://ge.armeria.dev/s/jv2vv4gi2bf34
build-self-hosted-unsafe-jdk-17-min-java-11 โŒ (failure) https://ge.armeria.dev/s/bdumqrgjh34h4
build-self-hosted-unsafe-jdk-17-leak โœ… https://ge.armeria.dev/s/fo7wwfesfgic6
build-self-hosted-unsafe-jdk-11 โœ… https://ge.armeria.dev/s/3enumq5mr3v7i
build-macos-12-jdk-19 โœ… https://ge.armeria.dev/s/m5xpss23od44i

github-actions[bot] avatar Mar 29 '24 08:03 github-actions[bot]

Codecov Report

Attention: Patch coverage is 90.62500% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 74.11%. Comparing base (b8eb810) to head (1d0b6c7). Report is 190 commits behind head on main.

:exclamation: Current head 1d0b6c7 differs from pull request most recent head 70d76cb. Consider uploading reports for the commit 70d76cb to get more accurate results

Files Patch % Lines
...rnal/server/annotation/AnnotatedValueResolver.java 90.00% 1 Missing and 2 partials :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5547      +/-   ##
============================================
+ Coverage     73.95%   74.11%   +0.16%     
- Complexity    20115    21019     +904     
============================================
  Files          1730     1819      +89     
  Lines         74161    77418    +3257     
  Branches       9465     9891     +426     
============================================
+ Hits          54847    57380    +2533     
- Misses        14837    15385     +548     
- Partials       4477     4653     +176     

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

codecov[bot] avatar Mar 29 '24 09:03 codecov[bot]

@trustin nim, There are two failed build list.

  • build-self-hosted-unsafe-jdk-19-snapshot-blockhound: ./gradlew: No such file or directory error occurs.
  • build-windows-latest-jdk-19 : because failed to upload Artifact. (403 Return) I think it seems not related with this PR. What do you think? Please let me know your opinion. ๐Ÿ™‡โ€โ™‚๏ธ

chickenchickenlove avatar Apr 05 '24 09:04 chickenchickenlove

Thank you for taking the time to see me even on a holiday. I've learned a lot thanks to you. ๐Ÿ™‡โ€โ™‚๏ธ

chickenchickenlove avatar Apr 10 '24 08:04 chickenchickenlove

Left a couple more super nit comments, still looks good for merging ๐Ÿ‘

@jrhee17 nim, thanks for your review. When you have free time, please review again ๐Ÿ™‡โ€โ™‚๏ธ

chickenchickenlove avatar Apr 18 '24 13:04 chickenchickenlove

Re-requesting review sounds like a bug. https://github.com/line/armeria/actions/runs/8796330970/job/24138993146?pr=5547#step:2:10 It seems that component-owners plugin takes the case into account though. https://github.com/dyladan/component-owners/blob/cdaadffde64c918909ee081e3fe044b8910f56c2/src/main.ts#L64-L65

ikhoon avatar Apr 23 '24 07:04 ikhoon

Re-requesting review sounds like a bug. https://github.com/line/armeria/actions/runs/8796330970/job/24138993146?pr=5547#step:2:10 It seems that component-owners plugin takes the case into account though. https://github.com/dyladan/component-owners/blob/cdaadffde64c918909ee081e3fe044b8910f56c2/src/main.ts#L64-L65

@ikhoon nim, Thanks for your comment. By the way, i lost your approve again ๐Ÿ˜ข... after commit suggestion from @minwoox nim.

@ikhoon nim, @minwoox nim, sorry to bother you. I lost you guys approve ๐Ÿ˜ข when you have free time, please take a look again ๐Ÿ™‡โ€โ™‚๏ธ...

chickenchickenlove avatar Apr 23 '24 07:04 chickenchickenlove

Oops! Sorry but would you mind resolving the merge conflict, @chickenchickenlove ?

trustin avatar May 07 '24 13:05 trustin

@trustin nim, thanks for you to notify me ๐Ÿ™‡โ€โ™‚๏ธ I made new commit to resolve conflict. I guess this PR cause the conflict. ๐Ÿค” I updated the PR description as well.

chickenchickenlove avatar May 07 '24 14:05 chickenchickenlove

Thanks a lot for updating the PR description and resolving the merge conflict, @chickenchickenlove! :bow::bow::bow:

@jrhee17 @minwoox PTAL

trustin avatar May 08 '24 05:05 trustin