Skip to content

Commit

Permalink
Merge pull request #312 from RachelTucker/response_logging
Browse files Browse the repository at this point in the history
Improved network client logging to include request id
  • Loading branch information
Denver authored Aug 2, 2016
2 parents f18e66a + a43103f commit ddda02b
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class NetworkClientImpl implements NetworkClient {
final static private String CONTENT_CRC32C = "Content-CRC32C";
final static private int MAX_CONNECTION_PER_ROUTE = 50;
final static private int MAX_CONNECTION_TOTAL = 100;
final static private String REQUEST_ID_HEADER = "x-amz-request-id";

final private ConnectionDetails connectionDetails;

Expand Down Expand Up @@ -187,13 +188,21 @@ public WebResponse getResponse(final Ds3Request request) throws IOException {
int redirectCount = 0;
do {
final CloseableHttpResponse response = requestExecutor.execute();
String requestId = "Unknown";
if (response.containsHeader(REQUEST_ID_HEADER)) {
requestId = response.getFirstHeader(REQUEST_ID_HEADER).getValue();
}
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT) {
redirectCount++;
LOG.info("Performing retry - attempt: {} for request #{}",
redirectCount,
requestId);
response.close();
LOG.info("Performing retry - attempt: {}", redirectCount);
}
else {
LOG.info("Got response from server");
LOG.info("Server responded with {} for request #{}",
response.getStatusLine().getStatusCode(),
requestId);
return new WebResponseImpl(response);
}
} while (redirectCount < this.connectionDetails.getRetries());
Expand Down

0 comments on commit ddda02b

Please sign in to comment.