Skip to content

Commit

Permalink
Merge pull request #51 from avast/HealtEndpointExclusion
Browse files Browse the repository at this point in the history
Don't crash when standard Health endpoint is used
  • Loading branch information
jendakol authored Mar 5, 2020
2 parents 900f9a0 + 59effa7 commit 61f6869
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 61f6869

Please sign in to comment.