Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Correctly implement connect health checker service (#491)
Browse files Browse the repository at this point in the history
Connect healthcheck service is now correctly checking for services health and only registered on the http port.

Fixes #472
  • Loading branch information
cyriltovena authored Jan 31, 2023
1 parent afd84cc commit 9fdd280
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
27 changes: 27 additions & 0 deletions pkg/phlare/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package phlare

import (
"context"

grpchealth "github.com/bufbuild/connect-grpchealth-go"
"github.com/gorilla/mux"
"github.com/grafana/dskit/grpcutil"
)

type checker struct {
checks []grpcutil.Check
}

func RegisterHealthServer(mux *mux.Router, checks ...grpcutil.Check) {
prefix, handler := grpchealth.NewHandler(&checker{checks: checks})
mux.NewRoute().PathPrefix(prefix).Handler(handler)
}

func (c *checker) Check(ctx context.Context, req *grpchealth.CheckRequest) (*grpchealth.CheckResponse, error) {
for _, check := range c.checks {
if !check(ctx) {
return &grpchealth.CheckResponse{Status: grpchealth.StatusNotServing}, nil
}
}
return &grpchealth.CheckResponse{Status: grpchealth.StatusServing}, nil
}
3 changes: 0 additions & 3 deletions pkg/phlare/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"os"

grpchealth "github.com/bufbuild/connect-grpchealth-go"
"github.com/felixge/fgprof"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -206,8 +205,6 @@ func (f *Phlare) initIngester() (_ services.Service, err error) {
if err != nil {
return nil, err
}
prefix, handler := grpchealth.NewHandler(grpchealth.NewStaticChecker(ingesterv1connect.IngesterServiceName))
f.Server.HTTP.NewRoute().PathPrefix(prefix).Handler(handler)
ingesterv1connect.RegisterIngesterServiceHandler(f.Server.HTTP, ingester, f.auth)
return ingester, nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/phlare/phlare.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/weaveworks/common/server"
"github.com/weaveworks/common/signals"
wwtracing "github.com/weaveworks/common/tracing"
"google.golang.org/grpc/health/grpc_health_v1"

pushv1connect "github.com/grafana/phlare/api/gen/proto/go/push/v1/pushv1connect"
"github.com/grafana/phlare/pkg/agent"
Expand Down Expand Up @@ -306,7 +305,7 @@ func (f *Phlare) Run() error {
}
f.Server.HTTP.Path("/ready").Methods("GET").Handler(f.readyHandler(sm))

grpc_health_v1.RegisterHealthServer(f.Server.GRPC, grpcutil.NewHealthCheck(sm))
RegisterHealthServer(f.Server.HTTP, grpcutil.WithManager(sm))
healthy := func() { level.Info(f.logger).Log("msg", "Phlare started", "version", version.Info()) }

serviceFailed := func(service services.Service) {
Expand Down

0 comments on commit 9fdd280

Please sign in to comment.