-
Notifications
You must be signed in to change notification settings - Fork 1k
Respect Retry-After in OTLP HTTP senders #8633
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
ADITYA-CODE-SOURCE
wants to merge
1
commit into
open-telemetry:main
Choose a base branch
from
ADITYA-CODE-SOURCE:issue-8449-otlp-retry-after
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
exporters/common/src/test/java/io/opentelemetry/exporter/internal/RetryUtilTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.internal; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.params.provider.Arguments.argumentSet; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.ZoneOffset; | ||
| import java.time.ZonedDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.OptionalLong; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| class RetryUtilTest { | ||
|
|
||
| private static final Instant NOW = Instant.parse("2026-07-17T00:00:00Z"); | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("retryAfterArgs") | ||
| void retryAfterNanos(String retryAfter, Instant now, Long expectedNanos) { | ||
| OptionalLong delayNanos = RetryUtil.retryAfterNanos(retryAfter, now); | ||
|
|
||
| if (expectedNanos == null) { | ||
| assertThat(delayNanos).isEmpty(); | ||
| } else { | ||
| assertThat(delayNanos).hasValue(expectedNanos); | ||
| } | ||
| } | ||
|
|
||
| private static Stream<Arguments> retryAfterArgs() { | ||
| return Stream.of( | ||
| argumentSet("null", null, Instant.EPOCH, null), | ||
| argumentSet("seconds", "30", Instant.EPOCH, TimeUnit.SECONDS.toNanos(30)), | ||
| argumentSet("negative seconds", "-1", Instant.EPOCH, null), | ||
| argumentSet("malformed", "bad-value", Instant.EPOCH, null), | ||
| argumentSet( | ||
| "future date", | ||
| ZonedDateTime.ofInstant(NOW.plusSeconds(45), ZoneOffset.UTC) | ||
| .format(DateTimeFormatter.RFC_1123_DATE_TIME), | ||
| NOW, | ||
| TimeUnit.SECONDS.toNanos(45)), | ||
| argumentSet( | ||
| "past date clamps to zero", | ||
| ZonedDateTime.ofInstant(NOW.minusSeconds(1), ZoneOffset.UTC) | ||
| .format(DateTimeFormatter.RFC_1123_DATE_TIME), | ||
| NOW, | ||
| 0L)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -729,6 +729,53 @@ void retryableError_tooManyAttempts() { | |
| assertThat(attempts).hasValue(2); | ||
| } | ||
|
|
||
| @Test | ||
| void retryableError_retryAfterHonored() { | ||
| addHttpResponse(502, "0"); | ||
|
|
||
| assertThat( | ||
| exporter | ||
| .export(Collections.singletonList(generateFakeTelemetry())) | ||
| .join(10, TimeUnit.SECONDS) | ||
| .isSuccess()) | ||
| .isTrue(); | ||
|
|
||
| assertThat(attempts).hasValue(2); | ||
| } | ||
|
|
||
| @Test | ||
| void retryableError_malformedRetryAfterFallsBack() { | ||
|
ADITYA-CODE-SOURCE marked this conversation as resolved.
|
||
| addHttpResponse(503, "not-a-retry-after"); | ||
|
|
||
| // Configure a large enough initial backoff so the elapsed time proves we fell back to the | ||
| // retry policy rather than the (malformed) Retry-After header. | ||
| try (TelemetryExporter<T> exporter = | ||
| exporterBuilder() | ||
| .setEndpoint(server.httpUri() + path) | ||
| .setRetryPolicy( | ||
| RetryPolicy.builder() | ||
| .setMaxAttempts(2) | ||
| .setInitialBackoff(Duration.ofMillis(300)) | ||
| .setMaxBackoff(Duration.ofMillis(300)) | ||
| .build()) | ||
| .build()) { | ||
| long startTimeNanos = System.nanoTime(); | ||
| assertThat( | ||
| exporter | ||
| .export(Collections.singletonList(generateFakeTelemetry())) | ||
| .join(10, TimeUnit.SECONDS) | ||
| .isSuccess()) | ||
| .isTrue(); | ||
| long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeNanos); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good but I think we need something similar in the
|
||
|
|
||
| assertThat(attempts).hasValue(2); | ||
| // The malformed Retry-After header should be ignored, so the retry must wait at least a | ||
| // noticeable portion of the configured 300ms backoff. Keep a generous upper bound to avoid | ||
| // flaking in slow CI environments. | ||
| assertThat(elapsedMillis).isBetween(100L, 2_000L); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @SuppressLogger(HttpExporter.class) | ||
| @ValueSource(ints = {400, 401, 403, 500, 501}) | ||
|
|
@@ -1208,6 +1255,14 @@ private static void addHttpResponse(int code) { | |
| httpErrors.add(HttpResponse.of(code)); | ||
| } | ||
|
|
||
| private static void addHttpResponse(int code, String retryAfter) { | ||
| httpErrors.add( | ||
| HttpResponse.of( | ||
| ResponseHeaders.builder(HttpStatus.valueOf(code)) | ||
| .add("Retry-After", retryAfter) | ||
| .build())); | ||
| } | ||
|
|
||
| private static void addHttpResponse(int code, AbstractMessageLite<?, ?> bodyMessage) { | ||
| httpErrors.add( | ||
| HttpResponse.of( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.