akka / akka-grpc

Akka gRPC
https://doc.akka.io/docs/akka-grpc/
Other
431 stars 123 forks source link

Example or convenience utility to provide a 'health' endpoint #700

Open raboof opened 5 years ago

raboof commented 5 years ago

Not sure yet what this should look like in practice, perhaps having it as an example/documentation is sufficient. Something like:

import scala.concurrent.Future

import io.grpc.Status

import io.grpc.health.v1._

import akka.NotUsed
import akka.grpc.GrpcServiceException
import akka.stream.scaladsl.Source

class HealthServiceImpl(services: Seq[String]) extends Health {
  override def check(in: HealthCheckRequest): Future[HealthCheckResponse] =
    if (services.contains(in.service))
      Future.successful(HealthCheckResponse(HealthCheckResponse.ServingStatus.UNKNOWN))
    else
      Future.failed(new GrpcServiceException(Status.NOT_FOUND))

  override def watch(in: HealthCheckRequest): Source[HealthCheckResponse, NotUsed] =
    Source.failed(new GrpcServiceException(Status.UNIMPLEMENTED))
}
Marcus-Rosti commented 5 years ago

Hey, we solved this by just adding

syntax = "proto3";

package grpc.health.v1;

message HealthCheckRequest {
    string service = 1;
}

message HealthCheckResponse {
    enum ServingStatus {
        UNKNOWN = 0;
        SERVING = 1;
        NOT_SERVING = 2;
    }
    ServingStatus status = 1;
}

service Health {
    rpc Check(HealthCheckRequest) returns (HealthCheckResponse);

    rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);
}

The standard health proto to the protobuf folder and just implementing it in our service. Is this request to just bake that into the offerings for akka-grpc?

Marcus-Rosti commented 5 years ago

The other idea is that you could maybe have this work with https://doc.akka.io/docs/akka-management/current/