diff --git a/CHANGELOG.md b/CHANGELOG.md index fb611b946f9..596adea6944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm See the "API Implementations" section of the `go.opentelemetry.io/otel/trace` package documentation for more informatoin about how to accomplish this. (#4620) - `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` does no longer depend on `go.opentelemetry.io/otel/exporters/otlp/otlpmetric`. (#4660) - `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` does no longer depend on `go.opentelemetry.io/otel/exporters/otlp/otlpmetric`. (#4660) +- Retry for `502 Bad Gateway` and `504 Gateway Timeout` HTTP statuses in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4670) +- Retry for `502 Bad Gateway` and `504 Gateway Timeout` HTTP statuses in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#4670) - Retry for `RESOURCE_EXHAUSTED` only if RetryInfo is returned in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#4669) - Retry for `RESOURCE_EXHAUSTED` only if RetryInfo is returned in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#4669) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index 385965a9363..af2e40d2782 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -178,7 +178,10 @@ func (c *client) UploadMetrics(ctx context.Context, protoMetrics *metricpb.Resou } } return nil - case sc == http.StatusTooManyRequests, sc == http.StatusServiceUnavailable: + case sc == http.StatusTooManyRequests, + sc == http.StatusBadGateway, + sc == http.StatusServiceUnavailable, + sc == http.StatusGatewayTimeout: // Retry-able failure. rErr = newResponseError(resp.Header) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go index 88cc5be9ee2..b14e10c3419 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go @@ -127,9 +127,9 @@ func TestConfig(t *testing.T) { t.Run("WithRetry", func(t *testing.T) { emptyErr := errors.New("") - rCh := make(chan otest.ExportResult, 3) + rCh := make(chan otest.ExportResult, 5) header := http.Header{http.CanonicalHeaderKey("Retry-After"): {"10"}} - // Both retryable errors. + // All retryable errors. rCh <- otest.ExportResult{Err: &otest.HTTPResponseError{ Status: http.StatusServiceUnavailable, Err: emptyErr, @@ -139,6 +139,14 @@ func TestConfig(t *testing.T) { Status: http.StatusTooManyRequests, Err: emptyErr, }} + rCh <- otest.ExportResult{Err: &otest.HTTPResponseError{ + Status: http.StatusGatewayTimeout, + Err: emptyErr, + }} + rCh <- otest.ExportResult{Err: &otest.HTTPResponseError{ + Status: http.StatusBadGateway, + Err: emptyErr, + }} rCh <- otest.ExportResult{} exp, coll := factoryFunc("", rCh, WithRetry(RetryConfig{ Enabled: true, diff --git a/exporters/otlp/otlptrace/otlptracehttp/client.go b/exporters/otlp/otlptrace/otlptracehttp/client.go index 3a3cfec0cde..0990b88f147 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client.go @@ -190,7 +190,10 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc } return nil - case sc == http.StatusTooManyRequests, sc == http.StatusServiceUnavailable: + case sc == http.StatusTooManyRequests, + sc == http.StatusBadGateway, + sc == http.StatusServiceUnavailable, + sc == http.StatusGatewayTimeout: // Retry-able failures. Drain the body to reuse the connection. if _, err := io.Copy(io.Discard, resp.Body); err != nil { otel.Handle(err) diff --git a/exporters/otlp/otlptrace/otlptracehttp/client_test.go b/exporters/otlp/otlptrace/otlptracehttp/client_test.go index 2020b15058b..1fb58fcb69a 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client_test.go @@ -95,7 +95,7 @@ func TestEndToEnd(t *testing.T) { }), }, mcCfg: mockCollectorConfig{ - InjectHTTPStatus: []int{503, 503}, + InjectHTTPStatus: []int{503, 502}, }, }, { @@ -110,7 +110,7 @@ func TestEndToEnd(t *testing.T) { }), }, mcCfg: mockCollectorConfig{ - InjectHTTPStatus: []int{503}, + InjectHTTPStatus: []int{504}, InjectResponseHeader: []map[string]string{ {"Retry-After": "10"}, },