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

Commit 9fdd280

Browse files
authored
Correctly implement connect health checker service (#491)
Connect healthcheck service is now correctly checking for services health and only registered on the http port. Fixes #472
1 parent afd84cc commit 9fdd280

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

pkg/phlare/health.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package phlare
2+
3+
import (
4+
"context"
5+
6+
grpchealth "github.com/bufbuild/connect-grpchealth-go"
7+
"github.com/gorilla/mux"
8+
"github.com/grafana/dskit/grpcutil"
9+
)
10+
11+
type checker struct {
12+
checks []grpcutil.Check
13+
}
14+
15+
func RegisterHealthServer(mux *mux.Router, checks ...grpcutil.Check) {
16+
prefix, handler := grpchealth.NewHandler(&checker{checks: checks})
17+
mux.NewRoute().PathPrefix(prefix).Handler(handler)
18+
}
19+
20+
func (c *checker) Check(ctx context.Context, req *grpchealth.CheckRequest) (*grpchealth.CheckResponse, error) {
21+
for _, check := range c.checks {
22+
if !check(ctx) {
23+
return &grpchealth.CheckResponse{Status: grpchealth.StatusNotServing}, nil
24+
}
25+
}
26+
return &grpchealth.CheckResponse{Status: grpchealth.StatusServing}, nil
27+
}

pkg/phlare/modules.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77
"os"
88

9-
grpchealth "github.com/bufbuild/connect-grpchealth-go"
109
"github.com/felixge/fgprof"
1110
"github.com/go-kit/log"
1211
"github.com/go-kit/log/level"
@@ -206,8 +205,6 @@ func (f *Phlare) initIngester() (_ services.Service, err error) {
206205
if err != nil {
207206
return nil, err
208207
}
209-
prefix, handler := grpchealth.NewHandler(grpchealth.NewStaticChecker(ingesterv1connect.IngesterServiceName))
210-
f.Server.HTTP.NewRoute().PathPrefix(prefix).Handler(handler)
211208
ingesterv1connect.RegisterIngesterServiceHandler(f.Server.HTTP, ingester, f.auth)
212209
return ingester, nil
213210
}

pkg/phlare/phlare.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/weaveworks/common/server"
2929
"github.com/weaveworks/common/signals"
3030
wwtracing "github.com/weaveworks/common/tracing"
31-
"google.golang.org/grpc/health/grpc_health_v1"
3231

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

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

312311
serviceFailed := func(service services.Service) {

0 commit comments

Comments
 (0)