Skip to content

improvement: Log request retry details #385

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-385.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Log request retry details
links:
- https://github.com/palantir/conjure-go-runtime/pull/385
19 changes: 18 additions & 1 deletion conjure-go-client/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"net/http"
"net/url"
"strconv"
"strings"

"github.com/palantir/conjure-go-runtime/v2/conjure-go-client/httpclient/internal"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/palantir/pkg/refreshable"
werror "github.com/palantir/witchcraft-go-error"
"github.com/palantir/witchcraft-go-logging/wlog/svclog/svc1log"
wparams "github.com/palantir/witchcraft-go-params"
)

// A Client executes requests to a configured service.
Expand Down Expand Up @@ -82,6 +84,10 @@ func (c *clientImpl) Delete(ctx context.Context, params ...RequestParam) (*http.
}

func (c *clientImpl) Do(ctx context.Context, params ...RequestParam) (*http.Response, error) {
if methodName := getRPCMethodName(ctx); methodName != "" {
ctx = wparams.ContextWithSafeParam(ctx, "rpcMethodName", methodName)
}

uris := c.uriScorer.CurrentURIScoringMiddleware().GetURIsInOrderOfIncreasingScore()
if len(uris) == 0 {
return nil, werror.ErrorWithContextParams(ctx, "no base URIs are configured")
Expand All @@ -94,17 +100,28 @@ func (c *clientImpl) Do(ctx context.Context, params ...RequestParam) (*http.Resp
}
}

// Used for logging maxAttempts
maxAttemptsLogParam := strconv.Itoa(attempts)
if attempts == 0 {
maxAttemptsLogParam = "unlimited"
}

var err error
var resp *http.Response

retrier := internal.NewRequestRetrier(uris, c.backoffOptions.CurrentRetryParams().Start(ctx), attempts)
failureCount := 0
for {
uri, isRelocated := retrier.GetNextURI(resp, err)
if uri == "" {
break
}
if err != nil {
svc1log.FromContext(ctx).Debug("Retrying request", svc1log.Stacktrace(err))
failureCount++
svc1log.FromContext(ctx).Info("Retrying request",
svc1log.Stacktrace(err),
svc1log.SafeParam("failures", failureCount),
svc1log.SafeParam("maxAttempts", maxAttemptsLogParam))
}
resp, err = c.doOnce(ctx, uri, isRelocated, params...)
}
Expand Down