Skip to content
Permalink
Browse files

Support `router-api` annotations for gRPC services (#912)

Motivation:

gRPC should support annotations that help to configure the execution
strategy per service or per route. Also, gRPC should compute the
effective execution strategy based on the main execution strategy
from the builder configuration and from the route configuration.

Modifications:

- Parse annotations from `route-api` module;
- Compute the difference between execution strategy on the builder
and on the route;
- Add tests to verify that offloading works correctly for different
execution strategy configurations;
- Add tests to verify that misconfiguration of `route-api` annotations
will be explained to the user;
- Adjust gRPC codegen for new features;
- Change `difference` functions to compare with `noOffloadsStrategy`
by configuration, not by reference;
- Make `NoOffloadsHttpExecutionStrategy` no op;
- Fix tests;

Result:

gRPC routes correctly compute per-route execution strategy
configuration.
  • Loading branch information
idelpivnitskiy committed Jan 17, 2020
1 parent 464554a commit 6bb2722b1643016c6c808bf8d0ae972bf7f222de
Showing with 1,859 additions and 282 deletions.
  1. +2 −1 servicetalk-bom/build.gradle
  2. +2 −0 servicetalk-grpc-api/build.gradle
  3. +8 −9 servicetalk-grpc-api/src/main/java/io/servicetalk/grpc/api/GrpcRouter.java
  4. +107 −31 servicetalk-grpc-api/src/main/java/io/servicetalk/grpc/api/GrpcRoutes.java
  5. +2 −1 servicetalk-grpc-netty/build.gradle
  6. +7 −0 servicetalk-grpc-netty/gradle/spotbugs/test-exclusions.xml
  7. +6 −4 servicetalk-grpc-netty/src/main/java/io/servicetalk/grpc/netty/DefaultGrpcServerBuilder.java
  8. +195 −0 ...rpc-netty/src/test/java/io/servicetalk/grpc/netty/ExecutionStrategyConfigurationFailuresTest.java
  9. +573 −0 servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/ExecutionStrategyTest.java
  10. +270 −0 servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/ExecutionStrategyTestServices.java
  11. +47 −35 servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/ProtocolCompatibilityTest.java
  12. +40 −0 servicetalk-grpc-netty/src/test/proto/test_es.proto
  13. +27 −3 servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Generator.java
  14. +9 −1 servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Types.java
  15. +1 −0 servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Words.java
  16. +1 −0 servicetalk-http-api/build.gradle
  17. +1 −7 servicetalk-http-api/src/main/java/io/servicetalk/http/api/BlockingStreamingToStreamingService.java
  18. +30 −24 servicetalk-http-api/src/main/java/io/servicetalk/http/api/DefaultHttpExecutionStrategy.java
  19. +8 −3 servicetalk-http-api/src/main/java/io/servicetalk/http/api/HttpExecutionStrategies.java
  20. +7 −6 servicetalk-http-api/src/main/java/io/servicetalk/http/api/HttpServiceContext.java
  21. +12 −19 servicetalk-http-api/src/main/java/io/servicetalk/http/api/NoOffloadsHttpExecutionStrategy.java
  22. +53 −3 servicetalk-http-api/src/test/java/io/servicetalk/http/api/DefaultHttpExecutionStrategyTest.java
  23. +22 −1 servicetalk-http-api/src/testFixtures/java/io/servicetalk/http/api/TestHttpServiceContext.java
  24. +2 −0 servicetalk-http-router-jersey/build.gradle
  25. +9 −8 ...uter-jersey/src/main/java/io/servicetalk/http/router/jersey/DefaultJerseyStreamingHttpRouter.java
  26. +13 −9 ...router-jersey/src/main/java/io/servicetalk/http/router/jersey/EndpointEnhancingRequestFilter.java
  27. +10 −8 ...k-http-router-jersey/src/main/java/io/servicetalk/http/router/jersey/HttpJerseyRouterBuilder.java
  28. +24 −66 ...lk/http/router/jersey/{RouteExecutionStrategyUtils.java → JerseyRouteExecutionStrategyUtils.java}
  29. +1 −1 ...ava/io/servicetalk/http/router/jersey/AbstractNonParameterizedJerseyStreamingHttpServiceTest.java
  30. +13 −14 ...-router-jersey/src/testFixtures/java/io/servicetalk/http/router/jersey/ExecutionStrategyTest.java
  31. +1 −0 servicetalk-http-router-predicate/build.gradle
  32. +2 −7 ...etalk-http-router-predicate/src/main/java/io/servicetalk/http/router/predicate/InOrderRouter.java
  33. +21 −20 ...dicate/src/test/java/io/servicetalk/http/router/predicate/BaseHttpPredicateRouterBuilderTest.java
  34. +36 −0 servicetalk-router-api/src/main/java/io/servicetalk/router/api/RouteExecutionStrategyFactory.java
  35. +26 −0 servicetalk-router-utils-internal/build.gradle
  36. +65 −0 ...rnal/src/main/java/io/servicetalk/router/utils/internal/DefaultRouteExecutionStrategyFactory.java
  37. +165 −0 ...tils-internal/src/main/java/io/servicetalk/router/utils/internal/RouteExecutionStrategyUtils.java
  38. +19 −0 ...cetalk-router-utils-internal/src/main/java/io/servicetalk/router/utils/internal/package-info.java
  39. +21 −1 servicetalk-utils-internal/src/main/java/io/servicetalk/utils/internal/ReflectionUtils.java
  40. +1 −0 settings.gradle
@@ -21,7 +21,8 @@ rootProject.subprojects.findAll { !it.name.contains("bom") && !it.name.contains(
dependencies.constraints.add("api", it)
}

// Keep publishing and signing configuration in sync with servicetalk-gradle-plugin-internal/src/main/groovy/io/servicetalk/gradle/plugin/internal/ServiceTalkLibraryPlugin.groovy
// Keep publishing and signing configuration in sync with ServiceTalkLibraryPlugin.groovy from
// servicetalk-gradle-plugin-internal
publishing {
publications {
mavenJava(MavenPublication) {
@@ -19,13 +19,15 @@ apply plugin: "io.servicetalk.servicetalk-gradle-plugin-internal-library"
dependencies {
api project(":servicetalk-concurrent-api")
api project(":servicetalk-http-api")
api project(":servicetalk-router-api")
api ("com.google.api.grpc:proto-google-common-protos:$protoGoogleCommonProtosVersion") {
exclude group: "com.google.protobuf"
}

implementation project(":servicetalk-annotations")
implementation project(":servicetalk-concurrent-api-internal")
implementation project(":servicetalk-concurrent-internal")
implementation project(":servicetalk-router-utils-internal")
implementation project(":servicetalk-utils-internal")
implementation "org.slf4j:slf4j-api:$slf4jVersion"
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
@@ -72,7 +72,7 @@
import static io.servicetalk.grpc.api.GrpcUtils.readGrpcMessageEncoding;
import static io.servicetalk.grpc.api.GrpcUtils.setStatus;
import static io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService;
import static io.servicetalk.http.api.HttpExecutionStrategies.noOffloadsStrategy;
import static io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy;
import static io.servicetalk.http.api.HttpRequestMethod.POST;
import static java.util.Collections.unmodifiableMap;
import static java.util.Objects.requireNonNull;
@@ -107,7 +107,7 @@ private GrpcRouter(final Map<String, RouteProvider> routes,
}

Single<ServerContext> bind(final ServerBinder binder, final ExecutionContext executionContext) {
CompositeCloseable closeable = AsyncCloseables.newCompositeCloseable();
final CompositeCloseable closeable = AsyncCloseables.newCompositeCloseable();
final Map<String, StreamingHttpService> allRoutes = new HashMap<>();
populateRoutes(executionContext, allRoutes, routes, closeable);
populateRoutes(executionContext, allRoutes, streamingRoutes, closeable);
@@ -255,7 +255,7 @@ public Completable closeAsyncGracefully() {
final StreamingRoute<Req, Resp> route, final Class<Req> requestClass,
final Class<Resp> responseClass, final GrpcSerializationProvider serializationProvider) {
streamingRoutes.put(path, new RouteProvider(executionContext -> {
StreamingHttpService service = new StreamingHttpService() {
final StreamingHttpService service = new StreamingHttpService() {
@Override
public Single<StreamingHttpResponse> handle(final HttpServiceContext ctx,
final StreamingHttpRequest request,
@@ -295,7 +295,7 @@ public StreamingHttpService adaptor() {

@Override
public HttpExecutionStrategy serviceInvocationStrategy() {
return executionStrategy == null ? noOffloadsStrategy() : executionStrategy;
return executionStrategy == null ? defaultStrategy() : executionStrategy;
}
};
}, () -> route, () -> toRequestStreamingRoute(route), () -> toResponseStreamingRoute(route),
@@ -323,8 +323,7 @@ public Completable closeAsync() {
public Completable closeAsyncGracefully() {
return route.closeAsyncGracefully();
}
}, requestClass, responseClass,
serializationProvider);
}, requestClass, responseClass, serializationProvider);
}

/**
@@ -463,9 +462,9 @@ public void close() throws Exception {
public void closeGracefully() throws Exception {
route.closeGracefully();
}
}, strategy -> executionStrategy == null ? strategy : executionStrategy), () -> toStreaming(route),
() -> toRequestStreamingRoute(route), () -> toResponseStreamingRoute(route),
() -> toRoute(route), route));
}, strategy -> executionStrategy == null ? strategy : executionStrategy),
() -> toStreaming(route), () -> toRequestStreamingRoute(route),
() -> toResponseStreamingRoute(route), () -> toRoute(route), route));
return this;
}

0 comments on commit 6bb2722

Please sign in to comment.
You can’t perform that action at this time.