diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index b9dfe86d..8e5f9300 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -40,8 +40,8 @@ jobs: flags: unit - name: Publish Unit Test Results - uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1.6 + uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v2 if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository with: github_token: ${{ secrets.GITHUB_TOKEN }} - files: ./**/build/test-results/**/*.xml \ No newline at end of file + junit_files: ./**/build/test-results/**/*.xml \ No newline at end of file diff --git a/.snyk b/.snyk index 691c39d2..f67d1c46 100644 --- a/.snyk +++ b/.snyk @@ -5,6 +5,6 @@ ignore: SNYK-JAVA-IONETTY-1042268: - '*': reason: No replacement available - expires: 2022-07-31T00:00:00.000Z + expires: 2022-10-31T00:00:00.000Z patch: {} diff --git a/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistry.java b/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistry.java index 708d9b91..c29c03c0 100644 --- a/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistry.java +++ b/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistry.java @@ -1,20 +1,14 @@ package org.hypertrace.core.graphql.utils.grpc; import io.grpc.ManagedChannel; -import javax.inject.Inject; -import javax.inject.Singleton; -import org.hypertrace.core.graphql.spi.lifecycle.GraphQlServiceLifecycle; import org.hypertrace.core.grpcutils.client.GrpcChannelConfig; -@Singleton class DefaultGrpcChannelRegistry implements GrpcChannelRegistry { - private final org.hypertrace.core.grpcutils.client.GrpcChannelRegistry delegate = - new org.hypertrace.core.grpcutils.client.GrpcChannelRegistry(); + private final org.hypertrace.core.grpcutils.client.GrpcChannelRegistry delegate; - @Inject - DefaultGrpcChannelRegistry(GraphQlServiceLifecycle serviceLifecycle) { - serviceLifecycle.shutdownCompletion().thenRun(this.delegate::shutdown); + DefaultGrpcChannelRegistry(org.hypertrace.core.grpcutils.client.GrpcChannelRegistry delegate) { + this.delegate = delegate; } @Override diff --git a/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/GraphQlGrpcModule.java b/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/GraphQlGrpcModule.java index 1e32e347..f501a04c 100644 --- a/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/GraphQlGrpcModule.java +++ b/hypertrace-core-graphql-grpc-utils/src/main/java/org/hypertrace/core/graphql/utils/grpc/GraphQlGrpcModule.java @@ -7,11 +7,19 @@ public class GraphQlGrpcModule extends AbstractModule { + private final org.hypertrace.core.grpcutils.client.GrpcChannelRegistry channelRegistry; + + public GraphQlGrpcModule( + org.hypertrace.core.grpcutils.client.GrpcChannelRegistry channelRegistry) { + this.channelRegistry = channelRegistry; + } + @Override protected void configure() { bind(CallCredentials.class).toInstance(getClientCallCredsProvider().get()); bind(GraphQlGrpcContextBuilder.class).to(DefaultGraphQlGrpcContextBuilder.class); - bind(GrpcChannelRegistry.class).to(DefaultGrpcChannelRegistry.class); + bind(GrpcChannelRegistry.class) + .toInstance(new DefaultGrpcChannelRegistry(this.channelRegistry)); bind(GrpcContextBuilder.class).to(PlatformGrpcContextBuilder.class); } } diff --git a/hypertrace-core-graphql-grpc-utils/src/test/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistryTest.java b/hypertrace-core-graphql-grpc-utils/src/test/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistryTest.java index 270afa51..762f085c 100644 --- a/hypertrace-core-graphql-grpc-utils/src/test/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistryTest.java +++ b/hypertrace-core-graphql-grpc-utils/src/test/java/org/hypertrace/core/graphql/utils/grpc/DefaultGrpcChannelRegistryTest.java @@ -1,36 +1,23 @@ package org.hypertrace.core.graphql.utils.grpc; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.when; import io.grpc.Channel; -import io.grpc.ManagedChannel; -import java.util.concurrent.CompletableFuture; -import org.hypertrace.core.graphql.spi.lifecycle.GraphQlServiceLifecycle; +import org.hypertrace.core.grpcutils.client.GrpcChannelRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class DefaultGrpcChannelRegistryTest { - - @Mock GraphQlServiceLifecycle mockLifecycle; - CompletableFuture shutdown; - DefaultGrpcChannelRegistry channelRegistry; @BeforeEach void beforeEach() { - this.shutdown = new CompletableFuture<>(); - when(this.mockLifecycle.shutdownCompletion()).thenReturn(this.shutdown); - this.channelRegistry = new DefaultGrpcChannelRegistry(this.mockLifecycle); + this.channelRegistry = new DefaultGrpcChannelRegistry(new GrpcChannelRegistry()); } @Test @@ -45,21 +32,4 @@ void reusesChannelsForDuplicateRequests() { assertNotSame(firstChannel, this.channelRegistry.forAddress("foo", 1001)); assertNotSame(firstChannel, this.channelRegistry.forAddress("bar", 1000)); } - - @Test - void shutdownAllChannelsOnLifecycleShutdown() { - ManagedChannel firstChannel = this.channelRegistry.forAddress("foo", 1000); - ManagedChannel secondChannel = this.channelRegistry.forAddress("foo", 1002); - assertFalse(firstChannel.isShutdown()); - assertFalse(secondChannel.isShutdown()); - this.shutdown.complete(null); - assertTrue(firstChannel.isShutdown()); - assertTrue(secondChannel.isShutdown()); - } - - @Test - void throwsIfNewChannelRequestedAfterLifecycleShutdown() { - this.shutdown.complete(null); - assertThrows(AssertionError.class, () -> this.channelRegistry.forAddress("foo", 1000)); - } } diff --git a/hypertrace-core-graphql-impl/build.gradle.kts b/hypertrace-core-graphql-impl/build.gradle.kts index 0db51f7d..c8545af6 100644 --- a/hypertrace-core-graphql-impl/build.gradle.kts +++ b/hypertrace-core-graphql-impl/build.gradle.kts @@ -7,6 +7,7 @@ plugins { dependencies { api(project(":hypertrace-core-graphql-spi")) api("com.graphql-java-kickstart:graphql-java-servlet") + api("org.hypertrace.core.grpcutils:grpc-client-utils") implementation(project(":hypertrace-core-graphql-schema-registry")) implementation(project(":hypertrace-core-graphql-context")) diff --git a/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlFactory.java b/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlFactory.java index 4b3c9a07..21dc88da 100644 --- a/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlFactory.java +++ b/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlFactory.java @@ -7,11 +7,15 @@ import org.hypertrace.core.graphql.context.GraphQlRequestContextBuilder; import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; import org.hypertrace.core.graphql.spi.lifecycle.GraphQlServiceLifecycle; +import org.hypertrace.core.grpcutils.client.GrpcChannelRegistry; public class GraphQlFactory { public static GraphQLConfiguration build( - GraphQlServiceConfig config, GraphQlServiceLifecycle lifecycle) { - final Injector injector = Guice.createInjector(new GraphQlModule(config, lifecycle)); + GraphQlServiceConfig config, + GraphQlServiceLifecycle lifecycle, + GrpcChannelRegistry grpcChannelRegistry) { + final Injector injector = + Guice.createInjector(new GraphQlModule(config, lifecycle, grpcChannelRegistry)); return GraphQLConfiguration.with(injector.getInstance(GraphQLSchema.class)) .with(injector.getInstance(GraphQlRequestContextBuilder.class)) diff --git a/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlModule.java b/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlModule.java index 68f973ba..f106f6df 100644 --- a/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlModule.java +++ b/hypertrace-core-graphql-impl/src/main/java/org/hypertrace/core/graphql/impl/GraphQlModule.java @@ -19,15 +19,21 @@ import org.hypertrace.core.graphql.utils.gateway.GatewayUtilsModule; import org.hypertrace.core.graphql.utils.grpc.GraphQlGrpcModule; import org.hypertrace.core.graphql.utils.schema.SchemaUtilsModule; +import org.hypertrace.core.grpcutils.client.GrpcChannelRegistry; class GraphQlModule extends AbstractModule { private final GraphQlServiceConfig config; private final GraphQlServiceLifecycle lifecycle; + private final org.hypertrace.core.grpcutils.client.GrpcChannelRegistry grpcChannelRegistry; - public GraphQlModule(final GraphQlServiceConfig config, final GraphQlServiceLifecycle lifecycle) { + public GraphQlModule( + final GraphQlServiceConfig config, + final GraphQlServiceLifecycle lifecycle, + final GrpcChannelRegistry grpcChannelRegistry) { this.config = config; this.lifecycle = lifecycle; + this.grpcChannelRegistry = grpcChannelRegistry; } @Override @@ -35,7 +41,7 @@ protected void configure() { bind(GraphQlServiceConfig.class).toInstance(this.config); bind(GraphQlServiceLifecycle.class).toInstance(this.lifecycle); install(new GraphQlRequestContextModule()); - install(new GraphQlGrpcModule()); + install(new GraphQlGrpcModule(this.grpcChannelRegistry)); install(new GraphQlSchemaRegistryModule()); install(new GraphQlDeserializationRegistryModule()); install(new CommonSchemaModule()); diff --git a/hypertrace-core-graphql-impl/src/test/java/org/hypertrace/core/graphql/impl/GraphQlModuleTest.java b/hypertrace-core-graphql-impl/src/test/java/org/hypertrace/core/graphql/impl/GraphQlModuleTest.java index ecfc3a55..1e1d0122 100644 --- a/hypertrace-core-graphql-impl/src/test/java/org/hypertrace/core/graphql/impl/GraphQlModuleTest.java +++ b/hypertrace-core-graphql-impl/src/test/java/org/hypertrace/core/graphql/impl/GraphQlModuleTest.java @@ -6,6 +6,7 @@ import com.google.inject.Guice; import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; import org.hypertrace.core.graphql.spi.lifecycle.GraphQlServiceLifecycle; +import org.hypertrace.core.grpcutils.client.GrpcChannelRegistry; import org.junit.jupiter.api.Test; public class GraphQlModuleTest { @@ -16,7 +17,9 @@ public void testResolveBindings() { () -> Guice.createInjector( new GraphQlModule( - mock(GraphQlServiceConfig.class), mock(GraphQlServiceLifecycle.class))) + mock(GraphQlServiceConfig.class), + mock(GraphQlServiceLifecycle.class), + mock(GrpcChannelRegistry.class))) .getAllBindings()); } } diff --git a/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/GraphQlService.java b/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/GraphQlService.java index 671989bf..b46d5383 100644 --- a/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/GraphQlService.java +++ b/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/GraphQlService.java @@ -34,7 +34,10 @@ List buildHandlerDefinition(HttpContainerEnvironment envi .port(config.getServicePort()) .contextPath(config.getGraphQlUrlPath()) .corsConfig(buildCorsConfig(config)) - .servlet(new GraphQlServiceHttpServlet(GraphQlFactory.build(config, serviceLifecycle))) + .servlet( + new GraphQlServiceHttpServlet( + GraphQlFactory.build( + config, serviceLifecycle, environment.getChannelRegistry()))) .build()); }