From 59effa70e56a47d254c53247939549952357526f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20August=C3=BDn?= Date: Thu, 5 Mar 2020 16:11:40 +0100 Subject: [PATCH] fix: don't crash when standard Health endpoint is used --- .../grpc/jsonbridge/scalapb/ScalaPBServiceHandlers.scala | 4 ++-- .../scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest.scala | 2 ++ .../scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest2.scala | 2 ++ .../avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest.scala | 2 ++ .../avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest2.scala | 2 ++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core-scalapb/src/main/scala/com/avast/grpc/jsonbridge/scalapb/ScalaPBServiceHandlers.scala b/core-scalapb/src/main/scala/com/avast/grpc/jsonbridge/scalapb/ScalaPBServiceHandlers.scala index e93000bc..6091d7b1 100644 --- a/core-scalapb/src/main/scala/com/avast/grpc/jsonbridge/scalapb/ScalaPBServiceHandlers.scala +++ b/core-scalapb/src/main/scala/com/avast/grpc/jsonbridge/scalapb/ScalaPBServiceHandlers.scala @@ -24,8 +24,8 @@ import scala.util.{Failure, Success} private[jsonbridge] object ScalaPBServiceHandlers extends ServiceHandlers with StrictLogging { def createServiceHandlers[F[_]](ec: ExecutionContext)(inProcessChannel: ManagedChannel)(ssd: ServerServiceDefinition)( implicit F: Async[F]): Map[GrpcMethodName, HandlerFunc[F]] = { - if (ssd.getServiceDescriptor.getName == "grpc.reflection.v1alpha.ServerReflection") { - logger.debug("Reflection endpoint service cannot be bridged because its implementation is not ScalaPB-based") + if (ssd.getServiceDescriptor.getName.startsWith("grpc.reflection.") || ssd.getServiceDescriptor.getName.startsWith("grpc.health.")) { + logger.debug("Reflection and health endpoint service cannot be bridged because its implementation is not ScalaPB-based") Map.empty } else { val futureStubCtor = createFutureStubCtor(ssd.getServiceDescriptor, inProcessChannel) diff --git a/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest.scala b/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest.scala index 51d921da..97781181 100644 --- a/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest.scala +++ b/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest.scala @@ -7,6 +7,7 @@ import com.avast.grpc.jsonbridge.scalapbtest.TestServices.TestServiceGrpc import com.avast.grpc.jsonbridge.{BridgeError, GrpcJsonBridge} import io.grpc.inprocess.InProcessServerBuilder import io.grpc.protobuf.services.ProtoReflectionService +import io.grpc.services.HealthStatusManager import org.scalatest.{fixture, Matchers, Outcome} import scala.concurrent.ExecutionContext.Implicits.global @@ -21,6 +22,7 @@ class ScalaPBReflectionGrpcJsonBridgeTest extends fixture.FlatSpec with Matchers .forName(channelName) .addService(TestServiceGrpc.bindService(new TestServiceImpl, global)) .addService(ProtoReflectionService.newInstance()) + .addService(new HealthStatusManager().getHealthService) .build val (bridge, close) = ScalaPBReflectionGrpcJsonBridge.createFromServer[IO](global)(server).allocated.unsafeRunSync() try { diff --git a/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest2.scala b/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest2.scala index 45386ff4..5fc0965f 100644 --- a/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest2.scala +++ b/core-scalapb/src/test/scala/com/avast/grpc/jsonbridge/scalapbtest/ScalaPBReflectionGrpcJsonBridgeTest2.scala @@ -7,6 +7,7 @@ import com.avast.grpc.jsonbridge.scalapbtest.TestServices2.TestService2Grpc import com.avast.grpc.jsonbridge.{BridgeError, GrpcJsonBridge} import io.grpc.inprocess.InProcessServerBuilder import io.grpc.protobuf.services.ProtoReflectionService +import io.grpc.services.HealthStatusManager import org.scalatest.{fixture, Matchers, Outcome} import scala.concurrent.ExecutionContext.Implicits.global @@ -21,6 +22,7 @@ class ScalaPBReflectionGrpcJsonBridgeTest2 extends fixture.FlatSpec with Matcher .forName(channelName) .addService(TestService2Grpc.bindService(new TestServiceImpl2, global)) .addService(ProtoReflectionService.newInstance()) + .addService(new HealthStatusManager().getHealthService) .build val (bridge, close) = ScalaPBReflectionGrpcJsonBridge.createFromServer[IO](global)(server).allocated.unsafeRunSync() try { diff --git a/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest.scala b/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest.scala index 139eb995..19b9e235 100644 --- a/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest.scala +++ b/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest.scala @@ -4,6 +4,7 @@ import cats.effect.IO import com.avast.grpc.jsonbridge.GrpcJsonBridge.GrpcMethodName import io.grpc.inprocess.InProcessServerBuilder import io.grpc.protobuf.services.ProtoReflectionService +import io.grpc.services.HealthStatusManager import org.scalatest.{fixture, Matchers, Outcome} import scala.concurrent.ExecutionContext.Implicits.global @@ -18,6 +19,7 @@ class ReflectionGrpcJsonBridgeTest extends fixture.FlatSpec with Matchers { .forName(channelName) .addService(new TestServiceImpl()) .addService(ProtoReflectionService.newInstance()) + .addService(new HealthStatusManager().getHealthService) .build val (bridge, close) = ReflectionGrpcJsonBridge.createFromServer[IO](global)(server).allocated.unsafeRunSync() try { diff --git a/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest2.scala b/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest2.scala index 642109fb..ddfe9b3d 100644 --- a/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest2.scala +++ b/core/src/test/scala/com/avast/grpc/jsonbridge/ReflectionGrpcJsonBridgeTest2.scala @@ -4,6 +4,7 @@ import cats.effect.IO import com.avast.grpc.jsonbridge.GrpcJsonBridge.GrpcMethodName import io.grpc.inprocess.InProcessServerBuilder import io.grpc.protobuf.services.ProtoReflectionService +import io.grpc.services.HealthStatusManager import org.scalatest._ import scala.concurrent.ExecutionContext.Implicits.global @@ -18,6 +19,7 @@ class ReflectionGrpcJsonBridgeTest2 extends fixture.FlatSpec with Matchers { .forName(channelName) .addService(new TestServiceImpl2()) .addService(ProtoReflectionService.newInstance()) + .addService(new HealthStatusManager().getHealthService) .build val (bridge, close) = ReflectionGrpcJsonBridge.createFromServer[IO](global)(server).allocated.unsafeRunSync() try {