diff --git a/spectator-ext-aws2/src/main/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptor.java b/spectator-ext-aws2/src/main/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptor.java index 5e1bcaf1e..da32a2002 100644 --- a/spectator-ext-aws2/src/main/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptor.java +++ b/spectator-ext-aws2/src/main/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptor.java @@ -95,25 +95,34 @@ private void logRetryAttempt(ExecutionAttributes attrs) { /** * Extract the attempt number from the {@code amz-sdk-retry} header. */ - private IpcAttempt extractAttempt(SdkHttpRequest request) { + private void updateAttempts(IpcLogEntry logEntry, SdkHttpRequest request) { int attempt = 0; - List vs = request.headers().get("amz-sdk-retry"); + int max = 0; + List vs = request.headers().get("amz-sdk-request"); if (vs != null) { for (String v : vs) { - // Format is: {requestCount - 1}/{lastBackoffDelay}/{availableRetryCapacity} - // See internal RetryHandler for more details. - int pos = v.indexOf('/'); + // Format is: attempt={}; max={} + // https://github.com/aws/aws-sdk-java-v2/pull/2179/files + int pos = v.indexOf(';'); if (pos > 0) { - try { - attempt = Integer.parseInt(v.substring(0, pos)) + 1; - } catch (NumberFormatException e) { - // If we cannot parse it, then attempt is unknown - attempt = 0; - } + attempt = parseFieldValue(v.substring(0, pos)); + max = parseFieldValue(v.substring(pos + 1)); } } } - return IpcAttempt.forAttemptNumber(attempt); + logEntry + .withAttempt(IpcAttempt.forAttemptNumber(attempt)) + .withAttemptFinal(attempt == max); + } + + private int parseFieldValue(String field) { + int pos = field.indexOf("="); + try { + return pos > 0 ? Integer.parseInt(field.substring(pos + 1)) : 0; + } catch (NumberFormatException e) { + // If we cannot parse it, then attempt is unknown + return 0; + } } @Override @@ -131,9 +140,8 @@ public void beforeTransmission(Context.BeforeTransmission context, ExecutionAttr .withProtocol(IpcProtocol.http_1) .withHttpMethod(request.method().name()) .withUri(request.getUri()) - .withEndpoint(endpoint) - .withAttempt(extractAttempt(request)) - .withAttemptFinal(false); // Don't know if it is the final attempt + .withEndpoint(endpoint); + updateAttempts(logEntry, request); request.headers().forEach((k, vs) -> vs.forEach(v -> logEntry.addRequestHeader(k, v))); diff --git a/spectator-ext-aws2/src/test/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptorTest.java b/spectator-ext-aws2/src/test/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptorTest.java index 0900d15a5..6fdd36232 100644 --- a/spectator-ext-aws2/src/test/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptorTest.java +++ b/spectator-ext-aws2/src/test/java/com/netflix/spectator/aws2/SpectatorExecutionInterceptorTest.java @@ -220,7 +220,7 @@ private void parseRetryHeaderTest(String expected, String header) { SdkHttpRequest request = SdkHttpRequest.builder() .method(SdkHttpMethod.POST) .uri(URI.create("https://ec2.us-east-1.amazonaws.com")) - .appendHeader("amz-sdk-retry", header) + .appendHeader("amz-sdk-request", header) .build(); SdkHttpResponse response = SdkHttpResponse.builder() .statusCode(200) @@ -238,27 +238,27 @@ private void parseRetryHeaderTest(String expected, String header) { @Test public void parseRetryHeaderInitial() { - parseRetryHeaderTest("initial", "0/NotUsed"); + parseRetryHeaderTest("initial", "attempt=1; max=4"); } @Test public void parseRetryHeaderSecond() { - parseRetryHeaderTest("second", "1/NotUsed"); + parseRetryHeaderTest("second", "attempt=2; max=4"); } @Test public void parseRetryHeaderThird() { - parseRetryHeaderTest("third_up", "2/NotUsed"); + parseRetryHeaderTest("third_up", "attempt=3; max=4"); } @Test public void parseRetryHeader50() { - parseRetryHeaderTest("third_up", "50/NotUsed"); + parseRetryHeaderTest("third_up", "attempt=50; max=50"); } @Test public void parseRetryHeaderInvalidNumber() { - parseRetryHeaderTest("unknown", "foo/bar"); + parseRetryHeaderTest("unknown", "attempt=foo; max=bar"); } @Test