plugin-barman-cloud/internal/cnpgi/common/health.go
Armando Ruocco 5fd9449b27
feat: add liveness and readiness probe support (#69)
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
Co-authored-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Co-authored-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
2024-12-02 14:51:32 +01:00

29 lines
869 B
Go

package common
import (
"context"
"github.com/cloudnative-pg/machinery/pkg/log"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
)
// AddHealthCheck adds a health check service to the gRPC server with the tag 'plugin-barman-cloud'
func AddHealthCheck(server *grpc.Server) {
grpc_health_v1.RegisterHealthServer(server, &healthServer{}) // replaces default registration
}
type healthServer struct {
grpc_health_v1.UnimplementedHealthServer
}
// Check is the response handle for the healthcheck request
func (h healthServer) Check(
ctx context.Context,
_ *grpc_health_v1.HealthCheckRequest,
) (*grpc_health_v1.HealthCheckResponse, error) {
contextLogger := log.FromContext(ctx)
contextLogger.Trace("serving health check response")
return &grpc_health_v1.HealthCheckResponse{Status: grpc_health_v1.HealthCheckResponse_SERVING}, nil
}