Skip to content

Commit

Permalink
api: make readiness check optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Sep 8, 2023
1 parent ff88160 commit 9f348bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (h *APIHandler) healthz(w http.ResponseWriter, _ *http.Request) {
}

func (h *APIHandler) readyz(w http.ResponseWriter, r *http.Request) {
if h.ready(r.Context()) {
if h.ready == nil || h.ready(r.Context()) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("OK"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/forwarder/httpbin/httpbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *command) runE(cmd *cobra.Command, _ []string) error {
defer s.Close()

r := prometheus.NewRegistry()
a, err := forwarder.NewHTTPServer(c.apiServerConfig, forwarder.NewAPIHandler(r, s.Ready, config, ""), logger.Named("api"))
a, err := forwarder.NewHTTPServer(c.apiServerConfig, forwarder.NewAPIHandler(r, nil, config, ""), logger.Named("api"))
if err != nil {
return err
}
Expand Down
13 changes: 8 additions & 5 deletions cmd/forwarder/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,17 @@ func (c *command) runE(cmd *cobra.Command, _ []string) error {
}

var g runctx.Group
p, err := forwarder.NewHTTPProxy(c.httpProxyConfig, pr, cm, rt, logger.Named("proxy"))
if err != nil {
return err
{
p, err := forwarder.NewHTTPProxy(c.httpProxyConfig, pr, cm, rt, logger.Named("proxy"))
if err != nil {
return err
}
defer p.Close()
g.Add(p.Run)
}
g.Add(p.Run)

if c.apiServerConfig.Addr != "" {
h := forwarder.NewAPIHandler(c.promReg, p.Ready, config, script)
h := forwarder.NewAPIHandler(c.promReg, nil, config, script)
a, err := forwarder.NewHTTPServer(c.apiServerConfig, h, logger.Named("api"))
if err != nil {
return err
Expand Down

0 comments on commit 9f348bd

Please sign in to comment.