diff --git a/pkg/ring/kv/consul/client.go b/pkg/ring/kv/consul/client.go index a243f603e..41b5587e3 100644 --- a/pkg/ring/kv/consul/client.go +++ b/pkg/ring/kv/consul/client.go @@ -100,7 +100,6 @@ func (c *Client) cas(ctx context.Context, key string, f func(in interface{}) (ou var ( index = uint64(0) retries = 10 - retry = true ) for i := 0; i < retries; i++ { options := &consul.QueryOptions{ @@ -124,7 +123,7 @@ func (c *Client) cas(ctx context.Context, key string, f func(in interface{}) (ou intermediate = out } - intermediate, retry, err = f(intermediate) + intermediate, retry, err := f(intermediate) if err != nil { if !retry { if resp, ok := httpgrpc.HTTPResponseFromError(err); ok && resp.GetCode() != 202 { diff --git a/pkg/ring/kv/memberlist/memberlist_client_test.go b/pkg/ring/kv/memberlist/memberlist_client_test.go index b72eaa1fb..e131b5e2b 100644 --- a/pkg/ring/kv/memberlist/memberlist_client_test.go +++ b/pkg/ring/kv/memberlist/memberlist_client_test.go @@ -476,7 +476,7 @@ func runClient(t *testing.T, kv *Client, name string, ringKey string, portToConn if portToConnect > 0 { _, err := kv.kv.JoinMembers([]string{fmt.Sprintf("127.0.0.1:%d", portToConnect)}) if err != nil { - t.Fatalf("%s failed to join the cluster: %v", name, err) + t.Errorf("%s failed to join the cluster: %v", name, err) return } } diff --git a/pkg/ring/kv/memberlist/tcp_transport.go b/pkg/ring/kv/memberlist/tcp_transport.go index 283111211..ea41fea74 100644 --- a/pkg/ring/kv/memberlist/tcp_transport.go +++ b/pkg/ring/kv/memberlist/tcp_transport.go @@ -267,7 +267,7 @@ func (t *TCPTransport) handleConnection(conn *net.TCPConn) { expectedDigest := md5.Sum(buf) - if bytes.Compare(receivedDigest, expectedDigest[:]) != 0 { + if !bytes.Equal(receivedDigest, expectedDigest[:]) { t.receivedPacketsErrors.Inc() level.Warn(util.Logger).Log("msg", "TCPTransport: packet digest mismatch", "expected", fmt.Sprintf("%x", expectedDigest), "received", fmt.Sprintf("%x", receivedDigest)) } diff --git a/pkg/ring/kv/metrics.go b/pkg/ring/kv/metrics.go index 567efc445..aaf7bbae0 100644 --- a/pkg/ring/kv/metrics.go +++ b/pkg/ring/kv/metrics.go @@ -39,14 +39,14 @@ func (m metrics) CAS(ctx context.Context, key string, f func(in interface{}) (ou } func (m metrics) WatchKey(ctx context.Context, key string, f func(interface{}) bool) { - instrument.CollectedRequest(ctx, "WatchKey", requestDuration, instrument.ErrorCode, func(ctx context.Context) error { + _ = instrument.CollectedRequest(ctx, "WatchKey", requestDuration, instrument.ErrorCode, func(ctx context.Context) error { m.c.WatchKey(ctx, key, f) return nil }) } func (m metrics) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool) { - instrument.CollectedRequest(ctx, "WatchPrefix", requestDuration, instrument.ErrorCode, func(ctx context.Context) error { + _ = instrument.CollectedRequest(ctx, "WatchPrefix", requestDuration, instrument.ErrorCode, func(ctx context.Context) error { m.c.WatchPrefix(ctx, prefix, f) return nil }) diff --git a/pkg/ring/lifecycler.go b/pkg/ring/lifecycler.go index 2abe465c2..a6988aad2 100644 --- a/pkg/ring/lifecycler.go +++ b/pkg/ring/lifecycler.go @@ -202,7 +202,7 @@ func (i *Lifecycler) CheckReady(ctx context.Context) error { // Ingester always take at least minReadyDuration to become ready to work // around race conditions with ingesters exiting and updating the ring - if time.Now().Sub(i.startTime) < i.cfg.MinReadyDuration { + if time.Since(i.startTime) < i.cfg.MinReadyDuration { return fmt.Errorf("waiting for %v after startup", i.cfg.MinReadyDuration) } @@ -417,7 +417,10 @@ loop: } // Mark ourselved as Leaving so no more samples are send to us. - i.changeState(context.Background(), LEAVING) + err := i.changeState(context.Background(), LEAVING) + if err != nil { + level.Error(util.Logger).Log("msg", "failed to set state to LEAVING", "ring", i.RingName, "err", err) + } // Do the transferring / flushing on a background goroutine so we can continue // to heartbeat to consul. diff --git a/pkg/ring/ring.go b/pkg/ring/ring.go index 4b98a4819..0748ddf9f 100644 --- a/pkg/ring/ring.go +++ b/pkg/ring/ring.go @@ -59,12 +59,6 @@ const ( Reporting // Special value for inquiring about health ) -type uint32s []uint32 - -func (x uint32s) Len() int { return len(x) } -func (x uint32s) Less(i, j int) bool { return x[i] < x[j] } -func (x uint32s) Swap(i, j int) { x[i], x[j] = x[j], x[i] } - // ErrEmptyRing is the error returned when trying to get an element when nothing has been added to hash. var ErrEmptyRing = errors.New("empty ring")