2022-09-26 15:25:34 -05:00
|
|
|
|
package grpcserver
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"google.golang.org/grpc/health"
|
|
|
|
|
"google.golang.org/grpc/health/grpc_health_v1"
|
2023-01-30 02:21:27 -06:00
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2022-09-26 15:25:34 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// HealthService implements GRPC Health Checking Protocol:
|
|
|
|
|
// https://github.com/grpc/grpc/blob/master/doc/health-checking.md
|
|
|
|
|
// It also demonstrates how to override authentication for a service – in this
|
|
|
|
|
// case we are disabling any auth in AuthFuncOverride.
|
|
|
|
|
type HealthService struct {
|
|
|
|
|
cfg *setting.Cfg
|
|
|
|
|
healthServer *healthServer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type healthServer struct {
|
|
|
|
|
*health.Server
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AuthFuncOverride for no auth for health service.
|
|
|
|
|
func (s *healthServer) AuthFuncOverride(ctx context.Context, _ string) (context.Context, error) {
|
|
|
|
|
return ctx, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ProvideHealthService(cfg *setting.Cfg, grpcServerProvider Provider) (*HealthService, error) {
|
|
|
|
|
hs := &healthServer{health.NewServer()}
|
|
|
|
|
grpc_health_v1.RegisterHealthServer(grpcServerProvider.GetServer(), hs)
|
|
|
|
|
return &HealthService{
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
healthServer: hs,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|