Skip to content

Commit

Permalink
Handle all errors as recoverable
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Oct 18, 2024
1 parent 819d9cf commit 66dbf98
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 115 deletions.
33 changes: 5 additions & 28 deletions exporter/otlpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (e *baseExporter) pushTraces(ctx context.Context, td ptrace.Traces) (err er
}()
req := ptraceotlp.NewExportRequestFromTraces(td)
resp, respErr := e.traceExporter.Export(e.enhanceContext(ctx), req, e.callOptions...)
if err = e.processError(respErr); err != nil {
if err = processError(respErr); err != nil {
return
}
partialSuccess := resp.PartialSuccess()
Expand All @@ -117,7 +117,7 @@ func (e *baseExporter) pushMetrics(ctx context.Context, md pmetric.Metrics) (err
}()
req := pmetricotlp.NewExportRequestFromMetrics(md)
resp, respErr := e.metricExporter.Export(e.enhanceContext(ctx), req, e.callOptions...)
if err = e.processError(respErr); err != nil {
if err = processError(respErr); err != nil {
return
}
partialSuccess := resp.PartialSuccess()
Expand All @@ -136,7 +136,7 @@ func (e *baseExporter) pushLogs(ctx context.Context, ld plog.Logs) (err error) {
}()
req := plogotlp.NewExportRequestFromLogs(ld)
resp, respErr := e.logExporter.Export(e.enhanceContext(ctx), req, e.callOptions...)
if err = e.processError(respErr); err != nil {
if err = processError(respErr); err != nil {
return
}
partialSuccess := resp.PartialSuccess()
Expand All @@ -152,7 +152,7 @@ func (e *baseExporter) pushLogs(ctx context.Context, ld plog.Logs) (err error) {
func (e *baseExporter) pushProfiles(ctx context.Context, td pprofile.Profiles) error {
req := pprofileotlp.NewExportRequestFromProfiles(td)
resp, respErr := e.profileExporter.Export(e.enhanceContext(ctx), req, e.callOptions...)
if err := e.processError(respErr); err != nil {
if err := processError(respErr); err != nil {
return err
}
partialSuccess := resp.PartialSuccess()
Expand All @@ -172,7 +172,7 @@ func (e *baseExporter) enhanceContext(ctx context.Context) context.Context {
return ctx
}

func (e *baseExporter) processError(err error) error {
func processError(err error) error {
if err == nil {
// Request is successful, we are done.
return nil
Expand All @@ -185,11 +185,6 @@ func (e *baseExporter) processError(err error) error {
return nil
}

// Now, this is a real error.
if isComponentPermanentError(st) {
componentstatus.ReportStatus(e.host, componentstatus.NewPermanentErrorEvent(err))
}

retryInfo := getRetryInfo(st)

if !shouldRetry(st.Code(), retryInfo) {
Expand Down Expand Up @@ -253,21 +248,3 @@ func getThrottleDuration(t *errdetails.RetryInfo) time.Duration {
}
return 0
}

// A component status of PermanentError indicates the component is in a state that will require user
// intervention to fix. Typically this is a misconfiguration detected at runtime. A component
// PermanentError has different semantics than a consumererror. For more information, see:
// https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-status.md
func isComponentPermanentError(st *status.Status) bool {
switch st.Code() {
case codes.NotFound:
return true
case codes.PermissionDenied:
return true
case codes.Unauthenticated:
return true
default:
return false
}

}
21 changes: 3 additions & 18 deletions exporter/otlpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,21 +1048,6 @@ func TestComponentStatus(t *testing.T) {
exportError: nil,
componentStatus: componentstatus.StatusOK,
},
{
name: "Permission Denied",
exportError: status.Error(codes.PermissionDenied, "permission denied"),
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "Not Found",
exportError: status.Error(codes.NotFound, "not found"),
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "Unauthenticated",
exportError: status.Error(codes.Unauthenticated, "unauthenticated"),
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "Resource Exhausted",
exportError: status.Error(codes.ResourceExhausted, "resource exhausted"),
Expand Down Expand Up @@ -1092,7 +1077,7 @@ func TestComponentStatus(t *testing.T) {
set := exportertest.NewNopSettings()
host := &testHost{Host: componenttest.NewNopHost()}

exp, err := factory.CreateTracesExporter(context.Background(), set, cfg)
exp, err := factory.CreateTraces(context.Background(), set, cfg)
require.NoError(t, err)
require.NotNil(t, exp)
require.NoError(t, exp.Start(context.Background(), host))
Expand Down Expand Up @@ -1133,7 +1118,7 @@ func TestComponentStatus(t *testing.T) {
set := exportertest.NewNopSettings()
host := &testHost{Host: componenttest.NewNopHost()}

exp, err := factory.CreateMetricsExporter(context.Background(), set, cfg)
exp, err := factory.CreateMetrics(context.Background(), set, cfg)
require.NoError(t, err)
require.NotNil(t, exp)
require.NoError(t, exp.Start(context.Background(), host))
Expand Down Expand Up @@ -1173,7 +1158,7 @@ func TestComponentStatus(t *testing.T) {
set := exportertest.NewNopSettings()
host := &testHost{Host: componenttest.NewNopHost()}

exp, err := factory.CreateLogsExporter(context.Background(), set, cfg)
exp, err := factory.CreateLogs(context.Background(), set, cfg)
require.NoError(t, err)
require.NotNil(t, exp)
require.NoError(t, exp.Start(context.Background(), host))
Expand Down
29 changes: 0 additions & 29 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ func (e *baseExporter) export(ctx context.Context, url string, request []byte, p
}
formattedErr = httphelper.NewStatusFromMsgAndHTTPCode(errString, resp.StatusCode).Err()

if isComponentPermanentError(resp.StatusCode) {
componentstatus.ReportStatus(e.host, componentstatus.NewPermanentErrorEvent(formattedErr))
}

if isRetryableStatusCode(resp.StatusCode) {
// A retry duration of 0 seconds will trigger the default backoff policy
// of our caller (retry handler).
Expand Down Expand Up @@ -277,31 +273,6 @@ func isRetryableStatusCode(code int) bool {
}
}

// A component status of PermanentError indicates the component is in a state that will require user
// intervention to fix. Typically this is a misconfiguration detected at runtime. A component
// PermanentError has different semantics than a consumererror. For more information, see:
// https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-status.md
func isComponentPermanentError(code int) bool {
switch code {
case http.StatusUnauthorized:
return true
case http.StatusForbidden:
return true
case http.StatusNotFound:
return true
case http.StatusMethodNotAllowed:
return true
case http.StatusRequestEntityTooLarge:
return true
case http.StatusRequestURITooLong:
return true
case http.StatusRequestHeaderFieldsTooLarge:
return true
default:
return false
}
}

func readResponseBody(resp *http.Response) ([]byte, error) {
if resp.ContentLength == 0 {
return nil, nil
Expand Down
40 changes: 0 additions & 40 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,46 +1150,6 @@ func TestComponentStatus(t *testing.T) {
responseStatus: http.StatusOK,
componentStatus: componentstatus.StatusOK,
},
{
name: "401",
responseStatus: http.StatusUnauthorized,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "403",
responseStatus: http.StatusForbidden,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "404",
responseStatus: http.StatusNotFound,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "405",
responseStatus: http.StatusMethodNotAllowed,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "413",
responseStatus: http.StatusRequestEntityTooLarge,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "414",
responseStatus: http.StatusRequestURITooLong,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "419",
responseStatus: http.StatusTooManyRequests,
componentStatus: componentstatus.StatusRecoverableError,
},
{
name: "431",
responseStatus: http.StatusRequestHeaderFieldsTooLarge,
componentStatus: componentstatus.StatusPermanentError,
},
{
name: "503",
responseStatus: http.StatusServiceUnavailable,
Expand Down

0 comments on commit 66dbf98

Please sign in to comment.