github.com/thanos-io/thanos@v0.32.5/pkg/prober/grpc.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package prober 5 6 import ( 7 "google.golang.org/grpc/health" 8 grpc_health "google.golang.org/grpc/health/grpc_health_v1" 9 ) 10 11 // GRPCProbe represents health and readiness status of given component, and provides GRPC integration. 12 type GRPCProbe struct { 13 h *health.Server 14 } 15 16 // NewGRPC creates a Probe that wrapped around grpc/healt.Server which reflects status of server. 17 func NewGRPC() *GRPCProbe { 18 h := health.NewServer() 19 h.SetServingStatus("", grpc_health.HealthCheckResponse_NOT_SERVING) 20 21 return &GRPCProbe{h: h} 22 } 23 24 // HealthServer returns a gRPC health server which responds readiness and liveness checks. 25 func (p *GRPCProbe) HealthServer() *health.Server { 26 return p.h 27 } 28 29 // Ready sets components status to ready. 30 func (p *GRPCProbe) Ready() { 31 p.h.SetServingStatus("", grpc_health.HealthCheckResponse_SERVING) 32 } 33 34 // NotReady sets components status to not ready with given error as a cause. 35 func (p *GRPCProbe) NotReady(err error) { 36 p.h.SetServingStatus("", grpc_health.HealthCheckResponse_NOT_SERVING) 37 } 38 39 // Healthy sets components status to healthy. 40 func (p *GRPCProbe) Healthy() { 41 p.h.Resume() 42 } 43 44 // NotHealthy sets components status to not healthy with given error as a cause. 45 func (p *GRPCProbe) NotHealthy(err error) { 46 p.h.Shutdown() 47 }