Skip to content

Commit

Permalink
Remove logger and return forget errors directly
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswine committed Jan 14, 2022
1 parent edf4b07 commit 13169e4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ring/basic_lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 7 additions & 7 deletions ring/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
"sort"
"strings"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
)

const pageContent = `
Expand Down Expand Up @@ -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,
}
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ring/lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ring/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 13169e4

Please sign in to comment.