Skip to content

Commit

Permalink
feat: tms readiness check bypass implementation
Browse files Browse the repository at this point in the history
fix: renamed flag to health_check_target, default to true

fix: flattened nested if statements
  • Loading branch information
alexanderGalushka authored and Ed Welch committed Apr 9, 2020
1 parent 6df6ef1 commit 5e752bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions docs/clients/promtail/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <string>]
# Target managers check flag for promtail readiness, if set to false the check is ignored
[health_check_target: <bool> | default = true]
```

## client_config
Expand Down
24 changes: 16 additions & 8 deletions pkg/promtail/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5e752bf

Please sign in to comment.