Skip to content

Commit

Permalink
Rename methods
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <[email protected]>
  • Loading branch information
kakkoyun committed Jul 30, 2020
1 parent 4554982 commit 6d6695e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
18 changes: 8 additions & 10 deletions pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (h *Handler) receiveHTTP(w http.ResponseWriter, r *http.Request) {
level.Debug(h.logger).Log("msg", "failed to handle request", "err", err)
}

switch rootCause(err) {
switch writeErrorCause(err) {
case nil:
return
case errNotReady:
Expand Down Expand Up @@ -453,7 +453,7 @@ func (h *Handler) fanoutForward(pctx context.Context, tenant string, replicas ma
// When a MultiError is added to another MultiError, the error slices are concatenated, not nested.
// To avoid breaking the counting logic, we need to flatten the error.
level.Debug(h.logger).Log("msg", "local tsdb write failed", "err", err.Error())
ec <- errors.Wrapf(findCause(err, 1), "store locally for endpoint %v", endpoint)
ec <- errors.Wrapf(writeErrorCause(err), "store locally for endpoint %v", endpoint)
return
}
ec <- nil
Expand Down Expand Up @@ -605,7 +605,7 @@ func (h *Handler) replicate(ctx context.Context, tenant string, wreq *prompb.Wri
quorum := h.writeQuorum()
// fanoutForward only returns an error if successThreshold (quorum) is not reached.
if err := h.fanoutForward(ctx, tenant, replicas, wreqs, quorum); err != nil {
return errors.Wrap(findCause(err, quorum), "quorum not reached")
return errors.Wrap(determineWriteErrorCause(err, quorum), "quorum not reached")
}
return nil
}
Expand All @@ -619,7 +619,7 @@ func (h *Handler) RemoteWrite(ctx context.Context, r *storepb.WriteRequest) (*st
if err != nil {
level.Debug(h.logger).Log("msg", "failed to handle request", "err", err)
}
switch rootCause(err) {
switch writeErrorCause(err) {
case nil:
return &storepb.WriteResponse{}, nil
case errNotReady:
Expand Down Expand Up @@ -677,10 +677,10 @@ func (a expectedErrors) Len() int { return len(a) }
func (a expectedErrors) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a expectedErrors) Less(i, j int) bool { return a[i].count < a[j].count }

// findCause returns a sentinel error that has occurred more than the given threshold.
// determineWriteErrorCause extracts a sentinel error that has occurred more than the given threshold from a given fan-out error.
// It will inspect the error's cause if the error is a MultiError,
// It will return cause of each contained error but will not traverse any deeper.
func findCause(err error, threshold int) error {
func determineWriteErrorCause(err error, threshold int) error {
if err == nil {
return nil
}
Expand Down Expand Up @@ -714,10 +714,8 @@ func findCause(err error, threshold int) error {
return err
}

// rootCause extracts the root cause of a fan-out error.
func rootCause(err error) error {
return errors.Cause(findCause(err, 1))
}
// writeErrorCause extracts the root cause of a write error.
func writeErrorCause(err error) error { return determineWriteErrorCause(err, 1) }

func newPeerGroup(dialOpts ...grpc.DialOption) *peerGroup {
return &peerGroup{
Expand Down
10 changes: 5 additions & 5 deletions pkg/receive/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/thanos-io/thanos/pkg/testutil"
)

func TestFindCause(t *testing.T) {
func TestDetermineWriteErrorCause(t *testing.T) {
for _, tc := range []struct {
name string
err error
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestFindCause(t *testing.T) {
},
} {

err := findCause(tc.err, tc.threshold)
err := determineWriteErrorCause(tc.err, tc.threshold)
if tc.exp != nil {
testutil.NotOk(t, err)
testutil.Equals(t, tc.exp.Error(), err.Error())
Expand All @@ -176,7 +176,7 @@ func TestFindCause(t *testing.T) {
}
}

func TestRootCause(t *testing.T) {
func TestWriteErrorCause(t *testing.T) {
for _, tc := range []struct {
name string
err error
Expand All @@ -201,10 +201,10 @@ func TestRootCause(t *testing.T) {
errors.New("foo"),
errors.New("bar"),
}), "baz"),
exp: errors.New("3 errors: 2 errors: qux; rpc error: code = AlreadyExists desc = conflict; foo; bar"),
exp: errors.New("baz: 3 errors: 2 errors: qux; rpc error: code = AlreadyExists desc = conflict; foo; bar"),
},
} {
err := rootCause(tc.err)
err := writeErrorCause(tc.err)
if tc.exp != nil {
testutil.NotOk(t, err)
testutil.Equals(t, tc.exp.Error(), err.Error())
Expand Down

0 comments on commit 6d6695e

Please sign in to comment.