From 5e752bf343e221b274319074d358cd4dceca0bb8 Mon Sep 17 00:00:00 2001 From: alexanderGalushka Date: Wed, 8 Apr 2020 14:22:48 -0700 Subject: [PATCH] feat: tms readiness check bypass implementation fix: renamed flag to health_check_target, default to true fix: flattened nested if statements --- docs/clients/promtail/configuration.md | 3 +++ pkg/promtail/server/server.go | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/clients/promtail/configuration.md b/docs/clients/promtail/configuration.md index 83420401c066..9672fdfdf120 100644 --- a/docs/clients/promtail/configuration.md +++ b/docs/clients/promtail/configuration.md @@ -133,6 +133,9 @@ The `server_config` block configures Promtail's behavior as an HTTP server: # Base path to server all API routes from (e.g., /v1/). [http_path_prefix: ] + +# Target managers check flag for promtail readiness, if set to false the check is ignored +[health_check_target: | default = true] ``` ## client_config diff --git a/pkg/promtail/server/server.go b/pkg/promtail/server/server.go index 2d135421567b..d478acba0cc3 100644 --- a/pkg/promtail/server/server.go +++ b/pkg/promtail/server/server.go @@ -28,14 +28,16 @@ var ( // Server embed weaveworks server with static file and templating capability type Server struct { *serverww.Server - tms *targets.TargetManagers - externalURL *url.URL + tms *targets.TargetManagers + externalURL *url.URL + healthCheckTarget bool } // Config extends weaveworks server config type Config struct { - serverww.Config `yaml:",inline"` - ExternalURL string `yaml:"external_url"` + serverww.Config `yaml:",inline"` + ExternalURL string `yaml:"external_url"` + HealthCheckTarget *bool `yaml:"health_check_target"` } // New makes a new Server @@ -51,10 +53,16 @@ func New(cfg Config, tms *targets.TargetManagers) (*Server, error) { } cfg.PathPrefix = externalURL.Path + healthCheckTargetFlag := true + if cfg.HealthCheckTarget != nil { + healthCheckTargetFlag = *cfg.HealthCheckTarget + } + serv := &Server{ - Server: wws, - tms: tms, - externalURL: externalURL, + Server: wws, + tms: tms, + externalURL: externalURL, + healthCheckTarget: healthCheckTargetFlag, } serv.HTTP.Path("/").Handler(http.RedirectHandler(path.Join(serv.externalURL.Path, "/targets"), 303)) @@ -169,7 +177,7 @@ func (s *Server) targets(rw http.ResponseWriter, req *http.Request) { // ready serves the ready endpoint func (s *Server) ready(rw http.ResponseWriter, _ *http.Request) { - if !s.tms.Ready() { + if s.healthCheckTarget && !s.tms.Ready() { http.Error(rw, readinessProbeFailure, http.StatusInternalServerError) return }