armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Add `ServiceOptions` and `@ServiceOption`

Open seonWKim opened this issue 10 months ago โ€ข 8 comments

Motivation:

Allow users to set default options for a specific service

Modifications:

  • Add ServiceOptions and @ServiceOption annotation to allow users specify default options

Result:

Users are able to set service specific options like below

final HttpService httpService = new HttpService() {
    ...

    @Override
    public ServiceOptions options() {
        return defaultServiceOptions;
    }
};

or use annotation

  final class MyService {

      @ServiceOption(requestTimeoutMillis = 11111, maxRequestLength = 1111,
              requestAutoAbortDelayMillis = 111)
      @Get("/test1")
      public HttpResponse test() {
          return HttpResponse.of("OK");
      }
   ...
}

seonWKim avatar Apr 07 '24 12:04 seonWKim

I think we need to decide what settings the ServiceOptions should support. For now, it only supports three settings which are:

  • requestTimeoutMillis
  • maxRequestLength
  • requestAutoAbortDelayMillis

seonWKim avatar Apr 07 '24 12:04 seonWKim

Should we use the name ServiceOptions which is used to configure HttpService? Because HttpService extends Service<HttpRequest, HttpResponse> it might be better to use HttpServiceOptions for HttpService rather than ServiceOptions. ๐Ÿค”

seonWKim avatar Apr 07 '24 12:04 seonWKim

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

Job name Status Build Scanยฎ
build-windows-latest-jdk-21 โœ… https://ge.armeria.dev/s/wzdflrljxzo7w
build-self-hosted-unsafe-jdk-8 โœ… https://ge.armeria.dev/s/vdey42wtrnmju
build-self-hosted-unsafe-jdk-21-snapshot-blockhound โŒ (failure) https://ge.armeria.dev/s/w6mq24abzhqyc
build-self-hosted-unsafe-jdk-17-min-java-17-coverage โœ… https://ge.armeria.dev/s/uitxumx7exrrc
build-self-hosted-unsafe-jdk-17-min-java-11 โœ… https://ge.armeria.dev/s/rnoyyigfv65pg
build-self-hosted-unsafe-jdk-17-leak โœ… https://ge.armeria.dev/s/kob7j6vllkaqm
build-self-hosted-unsafe-jdk-11 โœ… https://ge.armeria.dev/s/6mrjy4sdpo2gg
build-macos-12-jdk-21 โœ… https://ge.armeria.dev/s/4uwdpxjotdpcs

github-actions[bot] avatar Apr 07 '24 12:04 github-actions[bot]

A service can be wrapped with a decorator. If the decorator does not override ServiceOptions, it should delegate options().

public abstract class SimpleDecoratingHttpService ... {
    @Override
    public ServiceOptions options() {
        return ((HttpService) unwrap()).options();
    }
}

ikhoon avatar Apr 11 '24 08:04 ikhoon

it might be better to use HttpServiceOptions for HttpService rather than ServiceOptions

It may be better. Let use HttpServiceOptions for now. Other folks may have different opinions though.

ikhoon avatar Apr 11 '24 08:04 ikhoon

It may be better. Let use HttpServiceOptions for now. Other folks may have different opinions though.

I've renamed the class into HttpServiceOptions.

seonWKim avatar Apr 13 '24 09:04 seonWKim

Codecov Report

Attention: Patch coverage is 79.01235% with 17 lines in your changes missing coverage. Please review.

Project coverage is 74.11%. Comparing base (14c5566) to head (a15ef81). Report is 42 commits behind head on main.

:exclamation: Current head a15ef81 differs from pull request most recent head 0eb3cc9

Please upload reports for the commit 0eb3cc9 to get more accurate results.

Files Patch % Lines
...om/linecorp/armeria/server/HttpServiceOptions.java 47.82% 12 Missing :warning:
...corp/armeria/server/HttpServiceOptionsBuilder.java 78.57% 0 Missing and 3 partials :warning:
...nal/server/annotation/DefaultAnnotatedService.java 86.66% 0 Missing and 2 partials :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5574      +/-   ##
============================================
+ Coverage     74.05%   74.11%   +0.05%     
- Complexity    21253    21328      +75     
============================================
  Files          1850     1855       +5     
  Lines         78600    78816     +216     
  Branches      10032    10069      +37     
============================================
+ Hits          58209    58413     +204     
- Misses        15686    15691       +5     
- Partials       4705     4712       +7     

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

codecov[bot] avatar Apr 13 '24 13:04 codecov[bot]

There were some conflicts with my origin and upstream, so I'd reset the commits and did a force push ๐Ÿ˜“

seonWKim avatar Apr 14 '24 05:04 seonWKim

I think we also need to update RouteDecoratingService.

I guess we don't need to do this yet since 1) we only check HttpService#options when the server is being built 2) and HttpService#options doesn't do anything for decorators.

Actually, I'm not sure if it is even possible since the selected decorators may differ depending on the request path.

jrhee17 avatar May 29 '24 09:05 jrhee17

I think we also need to update RouteDecoratingService. I guess we don't need to do this yet since

Oops no, we don't need that. Have checked that the InitialDispatcherService in RouteDecoratingService already extends the SimpleDecoratingHttpService and SimpleDecoratingHttpService delegates to the next service already. https://github.com/line/armeria/pull/5574/files#diff-6c2400d047aec27ce1d011623100deb31c37334399da51aa0d3ed9821591b720R45

minwoox avatar May 29 '24 10:05 minwoox

I reschedule the release version to 1.30.0. Applying HttpServiceOptions to a WebSocketService having HttpService is tricky. I need more time to review.

ikhoon avatar Jun 04 '24 01:06 ikhoon

Discussed with other maintainers and decided to include this PR in 1.29.0. I will do more reviews today.

ikhoon avatar Jun 04 '24 05:06 ikhoon

ServiceOption(s) is just fine?

ServiceOption is simpler and the naming is connected to ServiceConfig. Let me rename it.

ikhoon avatar Jun 05 '24 02:06 ikhoon

Still have lot's of things to learn ๐Ÿ˜„. Thank you for all the support.

seonWKim avatar Jun 05 '24 11:06 seonWKim