You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
otlptracehttp, otlpmetrichttp: Retry temporary HTTP request failures (#4679)
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -147,6 +148,10 @@ func (c *client) UploadMetrics(ctx context.Context, protoMetrics *metricpb.Resou
|
||||
|
||||
request.reset(iCtx)
|
||||
resp, err := c.httpClient.Do(request.Request)
|
||||
var urlErr *url.Error
|
||||
if errors.As(err, &urlErr) && urlErr.Temporary() {
|
||||
return newResponseError(http.Header{})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -65,6 +65,13 @@ func TestClient(t *testing.T) {
|
||||
t.Run("Integration", otest.RunClientTests(factory))
|
||||
}
|
||||
|
||||
func TestNewWithInvalidEndpoint(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
exp, err := New(ctx, WithEndpoint("host:invalid-port"))
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, exp)
|
||||
}
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
factoryFunc := func(ePt string, rCh <-chan otest.ExportResult, o ...Option) (metric.Exporter, *otest.HTTPCollector) {
|
||||
coll, err := otest.NewHTTPCollector(ePt, rCh)
|
||||
@@ -113,7 +120,7 @@ func TestConfig(t *testing.T) {
|
||||
t.Cleanup(func() { close(rCh) })
|
||||
t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) })
|
||||
err := exp.Export(ctx, &metricdata.ResourceMetrics{})
|
||||
assert.ErrorContains(t, err, context.DeadlineExceeded.Error())
|
||||
assert.ErrorAs(t, err, new(retryableError))
|
||||
})
|
||||
|
||||
t.Run("WithCompressionGZip", func(t *testing.T) {
|
||||
@@ -174,17 +181,6 @@ func TestConfig(t *testing.T) {
|
||||
assert.Len(t, coll.Collect().Dump(), 1)
|
||||
})
|
||||
|
||||
t.Run("WithURLPath", func(t *testing.T) {
|
||||
path := "/prefix/v2/metrics"
|
||||
ePt := fmt.Sprintf("http://localhost:0%s", path)
|
||||
exp, coll := factoryFunc(ePt, nil, WithURLPath(path))
|
||||
ctx := context.Background()
|
||||
t.Cleanup(func() { require.NoError(t, coll.Shutdown(ctx)) })
|
||||
t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) })
|
||||
assert.NoError(t, exp.Export(ctx, &metricdata.ResourceMetrics{}))
|
||||
assert.Len(t, coll.Collect().Dump(), 1)
|
||||
})
|
||||
|
||||
t.Run("WithTLSClientConfig", func(t *testing.T) {
|
||||
ePt := "https://localhost:0"
|
||||
tlsCfg := &tls.Config{InsecureSkipVerify: true}
|
||||
|
||||
Reference in New Issue
Block a user