Skip to content
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

Parse errormsgs in retryable status codes #5541

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
170861d
parse-errormsgs-in-retry-able-statuscodes: In case of retyable scenar…
pree-dew Jun 24, 2024
6c740ac
parse-errormsgs-in-retry-able-statuscodes: add change log detail and …
pree-dew Jun 24, 2024
17cc1e8
parse-errormsgs-in-retry-able-statuscodes: 1. Add capability to pass …
pree-dew Jun 26, 2024
a2c49e6
parse-errormsgs-in-retry-able-statuscodes: fix lint issues
pree-dew Jun 28, 2024
abe63e9
parse-errormsgs-in-retry-able-statuscodes: 1. Include msg parsing fro…
pree-dew Jul 4, 2024
7884731
parse-errormsgs-in-retry-able-statuscodes: change errors.New to fmt.E…
pree-dew Jul 4, 2024
2709f7c
parse-errormsgs-in-retry-able-statuscodes: 1. Correct changlog and co…
pree-dew Jul 4, 2024
ae806df
parse-errormsgs-in-retry-able-statuscodes: resolve merge conflicts
pree-dew Jul 8, 2024
2bfb551
parse-errormsgs-in-retry-able-statuscodes: sync with main
pree-dew Jul 11, 2024
d1a5da6
parse-errormsgs-in-retry-able-statuscodes: 1. Provide Unwrap and As m…
pree-dew Jul 11, 2024
999b4d5
parse-errormsgs-in-retry-able-statuscodes: 1. Don't pre-render the er…
pree-dew Jul 11, 2024
0e2dd7c
parse-errormsgs-in-retry-able-statuscodes: 1. Use better assert funct…
pree-dew Jul 12, 2024
75af2ca
parse-errormsgs-in-retry-able-statuscodes: cover unwrap and As functi…
pree-dew Jul 12, 2024
ed9f12e
parse-errormsgs-in-retry-able-statuscodes: sync with main and resolve…
pree-dew Jul 17, 2024
cd4a639
Merge branch 'main' into parse-errormsgs-in-retry-able-statuscodes
dmathieu Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- `client.UploadMetrics` in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` now returns error shared by collector instead of generic retry-able failure error for retry-able applicable code. (#5541)
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
- `Tracer.Start` in `go.opentelemetry.io/otel/trace/noop` no longer allocates a span for empty span context. (#5457)
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to `go.opentelemetry.io/otel/semconv/v1.26.0` in `go.opentelemetry.io/otel/example/otel-collector`. (#5490)
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to `go.opentelemetry.io/otel/semconv/v1.26.0` in `go.opentelemetry.io/otel/example/zipkin`. (#5490)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
}

func (e *HTTPResponseError) Error() string {
return fmt.Sprintf("%d: %s", e.Status, e.Err)
return e.Err.Error()

Check warning on line 180 in exporters/otlp/otlpmetric/otlpmetricgrpc/internal/otest/collector.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/otest/collector.go#L180

Added line #L180 was not covered by tests
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
}

func (e *HTTPResponseError) Unwrap() error { return e.Err }
Expand Down
23 changes: 18 additions & 5 deletions exporters/otlp/otlpmetric/otlpmetrichttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"

"google.golang.org/protobuf/proto"

colmetricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"

"go.opentelemetry.io/otel"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry"
colmetricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
)

type client struct {
Expand Down Expand Up @@ -189,11 +192,21 @@ func (c *client) UploadMetrics(ctx context.Context, protoMetrics *metricpb.Resou
// Retry-able failure.
rErr = newResponseError(resp.Header)

// Going to retry, drain the body to reuse the connection.
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
_ = resp.Body.Close()
// In all these cases, since the response body is
// not getting parsed, actual reason of failure is
// very hard to find out for the user.
// If body is not empty, then we can use the msg
// of underlying service as error message.
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
var respData bytes.Buffer
if _, err := io.Copy(&respData, resp.Body); err != nil {
return err
}

respStr := strings.TrimSpace(respData.String())
if respStr != "" {
rErr = errors.New(respStr)
}

default:
rErr = fmt.Errorf("failed to send metrics to %s: %s", request.URL, resp.Status)
}
Expand Down
35 changes: 32 additions & 3 deletions exporters/otlp/otlpmetric/otlpmetrichttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/otest"
mpb "go.opentelemetry.io/proto/otlp/metrics/v1"

"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
mpb "go.opentelemetry.io/proto/otlp/metrics/v1"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal/otest"
)

type clientShim struct {
Expand Down Expand Up @@ -192,6 +194,33 @@ func TestConfig(t *testing.T) {
assert.Len(t, rCh, 0, "failed HTTP responses did not occur")
})

t.Run("WithRetryAndExporterErr", func(t *testing.T) {
dmathieu marked this conversation as resolved.
Show resolved Hide resolved
exporterErr := errors.New("rpc error: code = Unavailable desc = service.name not found in resource attributes")
rCh := make(chan otest.ExportResult, 1)
header := http.Header{http.CanonicalHeaderKey("Retry-After"): {"10"}}
rCh <- otest.ExportResult{Err: &otest.HTTPResponseError{
Status: http.StatusServiceUnavailable,
Err: exporterErr,
Header: header,
}}

exp, coll := factoryFunc("", rCh, WithRetry(RetryConfig{
Enabled: true,
InitialInterval: time.Nanosecond,
MaxInterval: time.Millisecond,
MaxElapsedTime: time.Minute,
}))
ctx := context.Background()
t.Cleanup(func() { require.NoError(t, coll.Shutdown(ctx)) })
// Push this after Shutdown so the HTTP server doesn't hang.
t.Cleanup(func() { close(rCh) })
t.Cleanup(func() { require.NoError(t, exp.Shutdown(ctx)) })

target := exp.Export(ctx, &metricdata.ResourceMetrics{})
assert.ErrorAs(t, fmt.Errorf("failed to upload metrics: %s", exporterErr.Error()), &target)
assert.Len(t, rCh, 0, "failed HTTP responses did not occur")
})

t.Run("WithURLPath", func(t *testing.T) {
path := "/prefix/v2/metrics"
ePt := fmt.Sprintf("http://localhost:0%s", path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type HTTPResponseError struct {
}

func (e *HTTPResponseError) Error() string {
return fmt.Sprintf("%d: %s", e.Status, e.Err)
return e.Err.Error()
}

func (e *HTTPResponseError) Unwrap() error { return e.Err }
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/otlp/otlpmetric/otest/collector.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type HTTPResponseError struct {
}

func (e *HTTPResponseError) Error() string {
return fmt.Sprintf("%d: %s", e.Status, e.Err)
return e.Err.Error()
}

func (e *HTTPResponseError) Unwrap() error { return e.Err }
Expand Down
Loading