Skip to content
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

Improve readiness probe output #556

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/weaveworks/common/user"
Expand All @@ -18,6 +19,8 @@ import (
"github.com/grafana/loki/pkg/logproto"
)

var readinessProbeSuccess = []byte("Ready")

var flushQueueLength = promauto.NewGauge(prometheus.GaugeOpts{
Name: "cortex_ingester_flush_queue_length",
Help: "The total number of series pending in the flush queue.",
Expand Down Expand Up @@ -195,13 +198,17 @@ func (*Ingester) Watch(*grpc_health_v1.HealthCheckRequest, grpc_health_v1.Health
}

// ReadinessHandler is used to indicate to k8s when the ingesters are ready for
// the addition removal of another ingester. Returns 204 when the ingester is
// the addition removal of another ingester. Returns 200 when the ingester is
// ready, 500 otherwise.
func (i *Ingester) ReadinessHandler(w http.ResponseWriter, r *http.Request) {
if err := i.lifecycler.CheckReady(r.Context()); err == nil {
w.WriteHeader(http.StatusNoContent)
} else {
w.WriteHeader(http.StatusInternalServerError)
if err := i.lifecycler.CheckReady(r.Context()); err != nil {
http.Error(w, "Not ready: "+err.Error(), http.StatusInternalServerError)
steven-sheehy marked this conversation as resolved.
Show resolved Hide resolved
return
}

w.WriteHeader(http.StatusOK)
if _, err := w.Write(readinessProbeSuccess); err != nil {
level.Error(util.Logger).Log("msg", "error writing success message", "error", err)
}
}

Expand Down
19 changes: 15 additions & 4 deletions pkg/promtail/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"text/template"

logutil "github.com/cortexproject/cortex/pkg/util"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/common/version"
serverww "github.com/weaveworks/common/server"
Expand All @@ -18,6 +20,11 @@ import (
"github.com/grafana/loki/pkg/promtail/targets"
)

var (
readinessProbeFailure = "Not ready: Unable to find any logs to tail. Please verify permissions, volumes, scrape_config, etc."
readinessProbeSuccess = []byte("Ready")
)

// Server embed weaveworks server with static file and templating capability
type Server struct {
*serverww.Server
Expand Down Expand Up @@ -155,10 +162,14 @@ func (s *Server) targets(rw http.ResponseWriter, _ *http.Request) {

// ready serves the ready endpoint
func (s *Server) ready(rw http.ResponseWriter, _ *http.Request) {
if s.tms.Ready() {
rw.WriteHeader(http.StatusNoContent)
} else {
rw.WriteHeader(http.StatusInternalServerError)
if !s.tms.Ready() {
http.Error(rw, readinessProbeFailure, http.StatusInternalServerError)
steven-sheehy marked this conversation as resolved.
Show resolved Hide resolved
return
}

rw.WriteHeader(http.StatusOK)
if _, err := rw.Write(readinessProbeSuccess); err != nil {
level.Error(logutil.Logger).Log("msg", "error writing success message", "error", err)
}
}

Expand Down