GoFr provides built-in health checks for gRPC services to enable observability, monitoring, and inter-service health verification.
Client-side
When using a GoFr-generated gRPC client, the client interface includes a health interface. This allows you to perform health checks on the remote service using Check and Watch methods.
Server-side
GoFr's gRPC server implementation includes a healthServer that supports standard gRPC health check methods. You can manage the service status using SetServingStatus, and control the health check lifecycle with Shutdown and Resume.
// Client Interface snippet
type <SERVICE_NAME>GoFrClient interface {
SayHello(*gofr.Context, *HelloRequest, ...grpc.CallOption) (*HelloResponse, error)
health
}
type health interface {
Check(ctx *gofr.Context, in *grpc_health_v1.HealthCheckRequest, opts ...grpc.CallOption) (*grpc_health_v1.HealthCheckResponse, error)
Watch(ctx *gofr.Context, in *grpc_health_v1.HealthCheckRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[grpc_health_v1.HealthCheckResponse], error)
}
// Server Implementation snippet
type <SERVICE_NAME>GoFrServer struct {
health *healthServer
}
// Supported Server Methods
func (h *healthServer) Check(ctx *gofr.Context, req *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error)
func (h *healthServer) Watch(ctx *gofr.Context, in *grpc_health_v1.HealthCheckRequest, stream grpc_health_v1.Health_WatchServer) error
func (h *healthServer) SetServingStatus(ctx *gofr.Context, service string, status grpc_health_v1.HealthCheckResponse_ServingStatus)
func (h *healthServer) Shutdown(ctx *gofr.Context)
func (h *healthServer) Resume(ctx *gofr.Context)