-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add grpc health, deprecate old health #861
Changes from all commits
93a9069
4648c26
a00ae5a
9c2fa3e
c26e569
465add4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"time" | ||
|
||
schemaConnectV1 "buf.build/gen/go/open-feature/flagd/bufbuild/connect-go/schema/v1/schemav1connect" | ||
"connectrpc.com/grpchealth" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this package is a connect-compatible implementation of a gRPC healthcheck. |
||
"github.com/open-feature/flagd/core/pkg/eval" | ||
"github.com/open-feature/flagd/core/pkg/logger" | ||
"github.com/open-feature/flagd/core/pkg/service" | ||
|
@@ -101,6 +102,7 @@ func (s *ConnectService) Notify(n service.Notification) { | |
s.eventingConfiguration.emitToAll(n) | ||
} | ||
|
||
// nolint: funlen | ||
func (s *ConnectService) setupServer(svcConf service.Configuration) (net.Listener, error) { | ||
var lis net.Listener | ||
var err error | ||
|
@@ -127,18 +129,29 @@ func (s *ConnectService) setupServer(svcConf service.Configuration) (net.Listene | |
protojson.UnmarshalOptions{DiscardUnknown: true}, | ||
) | ||
|
||
path, handler := schemaConnectV1.NewServiceHandler(fes, append(svcConf.Options, marshalOpts)...) | ||
mux.Handle(path, handler) | ||
mux.Handle(schemaConnectV1.NewServiceHandler(fes, append(svcConf.Options, marshalOpts)...)) | ||
mux.Handle(grpchealth.NewHandler(grpchealth.NewStaticChecker( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standard implementation, recommended by buf/conntect. You can test this locally with grpcurl -import-path '/home/{your-user}/Downloads/' -proto health.proto -plaintext localhost:8013 grpc.health.v1.Health/Check |
||
schemaConnectV1.ServiceName, | ||
))) | ||
mux.Handle("/healthz", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
})) | ||
mux.Handle("/readyz", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if s.readinessEnabled && svcConf.ReadinessProbe() { | ||
w.WriteHeader(http.StatusOK) | ||
} else { | ||
w.WriteHeader(http.StatusPreconditionFailed) | ||
} | ||
})) | ||
|
||
s.serverMtx.Lock() | ||
s.server = &http.Server{ | ||
ReadHeaderTimeout: time.Second, | ||
Handler: handler, | ||
Handler: mux, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
s.serverMtx.Unlock() | ||
|
||
// Add middlewares | ||
|
||
metricsMiddleware := metricsmw.NewHTTPMetric(metricsmw.Config{ | ||
Service: svcConf.ServiceName, | ||
MetricRecorder: s.metrics, | ||
|
@@ -206,8 +219,12 @@ func (s *ConnectService) startMetricsServer(svcConf service.Configuration) error | |
s.metricsServer.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
switch r.URL.Path { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my new implementation, I've used |
||
case "/healthz": | ||
s.logger.Warn( | ||
fmt.Sprintf("/healthz endpoint on port %d is deprecated, use port %d instead", svcConf.MetricsPort, svcConf.Port)) | ||
w.WriteHeader(http.StatusOK) | ||
case "/readyz": | ||
s.logger.Warn( | ||
fmt.Sprintf("/readyz endpoint on port %d is deprecated, use port %d instead", svcConf.MetricsPort, svcConf.Port)) | ||
if s.readinessEnabled && svcConf.ReadinessProbe() { | ||
w.WriteHeader(http.StatusOK) | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, adapt also the ZD tests manifest to use the new port :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thisthat flagd-proxy uses the sync package from core, NOT the
flag-evaluation
package. For this reason, the health-checks of flagd-proxy are not impacted by this change (which may or may not be good, since things will be a bit inconsistent.Problem is, I'm not 100% sure I can add HTTP 1.1 health-check support to the sync package since it doesn't use
connect
.