From 13169e40970e57ffd7c2cf7f0c5162977a3cc5de Mon Sep 17 00:00:00 2001 From: Christian Simon Date: Fri, 14 Jan 2022 12:39:25 +0000 Subject: [PATCH] Remove logger and return forget errors directly --- ring/basic_lifecycler.go | 2 +- ring/http.go | 14 +++++++------- ring/lifecycler.go | 2 +- ring/ring.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ring/basic_lifecycler.go b/ring/basic_lifecycler.go index 480eab2d1..32775c982 100644 --- a/ring/basic_lifecycler.go +++ b/ring/basic_lifecycler.go @@ -507,5 +507,5 @@ func (l *BasicLifecycler) getRing(ctx context.Context) (*Desc, error) { } func (l *BasicLifecycler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - newRingPageHandler(l.logger, l, l.cfg.HeartbeatPeriod).handle(w, req) + newRingPageHandler(l, l.cfg.HeartbeatPeriod).handle(w, req) } diff --git a/ring/http.go b/ring/http.go index c71a32d8b..1d6c10e80 100644 --- a/ring/http.go +++ b/ring/http.go @@ -10,9 +10,6 @@ import ( "sort" "strings" "time" - - "github.com/go-kit/log" - "github.com/go-kit/log/level" ) const pageContent = ` @@ -115,14 +112,12 @@ type ringAccess interface { } type ringPageHandler struct { - logger log.Logger r ringAccess heartbeatPeriod time.Duration } -func newRingPageHandler(logger log.Logger, r ringAccess, heartbeatPeriod time.Duration) *ringPageHandler { +func newRingPageHandler(r ringAccess, heartbeatPeriod time.Duration) *ringPageHandler { return &ringPageHandler{ - logger: logger, r: r, heartbeatPeriod: heartbeatPeriod, } @@ -132,7 +127,12 @@ func (h *ringPageHandler) handle(w http.ResponseWriter, req *http.Request) { if req.Method == http.MethodPost { ingesterID := req.FormValue("forget") if err := h.forget(req.Context(), ingesterID); err != nil { - level.Error(h.logger).Log("msg", "error forgetting instance", "err", err) + http.Error( + w, + fmt.Errorf("error forgetting instance '%s': %w", ingesterID, err).Error(), + http.StatusInternalServerError, + ) + return } // Implement PRG pattern to prevent double-POST and work with CSRF middleware. diff --git a/ring/lifecycler.go b/ring/lifecycler.go index 51ed43e63..e8d1655e7 100644 --- a/ring/lifecycler.go +++ b/ring/lifecycler.go @@ -864,7 +864,7 @@ func (i *Lifecycler) getRing(ctx context.Context) (*Desc, error) { } func (i *Lifecycler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - newRingPageHandler(i.logger, i, i.cfg.HeartbeatPeriod).handle(w, req) + newRingPageHandler(i, i.cfg.HeartbeatPeriod).handle(w, req) } // unregister removes our entry from consul. diff --git a/ring/ring.go b/ring/ring.go index 37bed221b..5553c6b72 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -861,7 +861,7 @@ func (r *Ring) getRing(ctx context.Context) (*Desc, error) { } func (r *Ring) ServeHTTP(w http.ResponseWriter, req *http.Request) { - newRingPageHandler(r.logger, r, r.cfg.HeartbeatTimeout).handle(w, req) + newRingPageHandler(r, r.cfg.HeartbeatTimeout).handle(w, req) } // Operation describes which instances can be included in the replica set, based on their state.