Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/server/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)

type healthChecker struct {
type HealthChecker struct {
grpc *health.Server
ok uint32
name string
}

func NewHealthChecker(grpcHealthServer *health.Server, name string) *healthChecker {
ret := &healthChecker{}
func NewHealthChecker(grpcHealthServer *health.Server, name string) *HealthChecker {
ret := &HealthChecker{}
ret.ok = 1
ret.name = name

Expand All @@ -37,7 +37,7 @@ func NewHealthChecker(grpcHealthServer *health.Server, name string) *healthCheck
return ret
}

func (hc *healthChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (hc *HealthChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ok := atomic.LoadUint32(&hc.ok)
if ok == 1 {
w.Write([]byte("OK"))
Expand All @@ -46,7 +46,11 @@ func (hc *healthChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

func (hc *healthChecker) Fail() {
func (hc *HealthChecker) Fail() {
atomic.StoreUint32(&hc.ok, 0)
hc.grpc.SetServingStatus(hc.name, healthpb.HealthCheckResponse_NOT_SERVING)
}

func (hc *HealthChecker) Server() *health.Server {
return hc.grpc
}
4 changes: 2 additions & 2 deletions src/server/server_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type server struct {
scope stats.Scope
runtime loader.IFace
debugListener serverDebugListener
health *healthChecker
health *HealthChecker
}

func (server *server) AddDebugHttpEndpoint(path string, help string, handler http.HandlerFunc) {
Expand Down Expand Up @@ -144,7 +144,7 @@ func newServer(name string, opts ...settings.Option) *server {
// setup healthcheck path
ret.health = NewHealthChecker(health.NewServer(), "ratelimit")
ret.router.Path("/healthcheck").Handler(ret.health)
healthpb.RegisterHealthServer(ret.grpcServer, ret.health.grpc)
healthpb.RegisterHealthServer(ret.grpcServer, ret.health.Server())

// setup default debug listener
ret.debugListener.debugMux = http.NewServeMux()
Expand Down