Skip to content

Commit

Permalink
[chore] [exporterhelper] Fix requeuing of partially failed request (#…
Browse files Browse the repository at this point in the history
…8992)

After
#8985, the
whole request is requeued even with the partial request error. This
change fixes it and restores the previous behavior. No changelog is
needed since the bug is not released yet.
  • Loading branch information
dmitryax authored Nov 27, 2023
1 parent 8cec790 commit 0ae738f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion exporter/exporterhelper/queue_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (qs *queueSender) consume(ctx context.Context, req Request) {
return
}

if qs.queue.Offer(ctx, req) == nil {
if qs.queue.Offer(ctx, extractPartialRequest(req, err)) == nil {
qs.logger.Error(
"Exporting failed. Putting back to the end of the queue.",
zap.Error(err),
Expand Down
8 changes: 3 additions & 5 deletions exporter/exporterhelper/queue_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/testdata"
"go.opentelemetry.io/collector/obsreport/obsreporttest"
)

Expand Down Expand Up @@ -240,8 +238,7 @@ func TestQueuedRetry_RequeuingEnabled(t *testing.T) {
assert.NoError(t, be.Shutdown(context.Background()))
})

traceErr := consumererror.NewTraces(errors.New("some error"), testdata.GenerateTraces(1))
mockR := newMockRequest(1, traceErr)
mockR := newMockRequest(4, errors.New("transient error"))
ocs.run(func() {
ocs.waitGroup.Add(1) // necessary because we'll call send() again after requeueing
// This is asynchronous so it should just enqueue, no errors expected.
Expand All @@ -251,8 +248,9 @@ func TestQueuedRetry_RequeuingEnabled(t *testing.T) {

// In the newMockConcurrentExporter we count requests and items even for failed requests
mockR.checkNumRequests(t, 2)
// ensure that only 1 item was sent which correspond to items count in the error returned by mockRequest.OnError()
ocs.checkSendItemsCount(t, 1)
ocs.checkDroppedItemsCount(t, 1) // not actually dropped, but ocs counts each failed send here
ocs.checkDroppedItemsCount(t, 4) // not actually dropped, but ocs counts each failed send here
}

// disabling retry sender should disable requeuing.
Expand Down
9 changes: 9 additions & 0 deletions exporter/exporterhelper/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ type RequestMarshaler func(req Request) ([]byte, error)
// This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
type RequestUnmarshaler func(data []byte) (Request, error)

// extractPartialRequest returns a new Request that may contain the items left to be sent
// if only some items failed to process and can be retried. Otherwise, it returns the original Request.
func extractPartialRequest(req Request, err error) Request {
if errReq, ok := req.(RequestErrorHandler); ok {
return errReq.OnError(err)
}
return req
}
6 changes: 1 addition & 5 deletions exporter/exporterhelper/retry_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ func (rs *retrySender) send(ctx context.Context, req Request) error {
return err
}

// Give the request a chance to extract signal data to retry if only some data
// failed to process.
if errReq, ok := req.(RequestErrorHandler); ok {
req = errReq.OnError(err)
}
req = extractPartialRequest(req, err)

backoffDelay := expBackoff.NextBackOff()
if backoffDelay == backoff.Stop {
Expand Down

0 comments on commit 0ae738f

Please sign in to comment.