armeria
armeria copied to clipboard
Add `ServiceOptions` and `@ServiceOption`
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");
}
...
}
- Closes https://github.com/line/armeria/issues/5071. (If this resolves the issue.)
I think we need to decide what settings the ServiceOptions
should support. For now, it only supports three settings which are:
- requestTimeoutMillis
- maxRequestLength
- requestAutoAbortDelayMillis
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
. ๐ค
๐ 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 |
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();
}
}
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.
It may be better. Let use HttpServiceOptions for now. Other folks may have different opinions though.
I've renamed the class into HttpServiceOptions
.
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.
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.
There were some conflicts with my origin and upstream, so I'd reset the commits and did a force push ๐
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.
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
I reschedule the release version to 1.30.0. Applying HttpServiceOptions
to a WebSocketService having HttpService
is tricky. I need more time to review.
Discussed with other maintainers and decided to include this PR in 1.29.0. I will do more reviews today.
ServiceOption(s) is just fine?
ServiceOption
is simpler and the naming is connected to ServiceConfig
. Let me rename it.
Still have lot's of things to learn ๐. Thank you for all the support.