Skip to content

Commit b84a5bc

Browse files
andrzej-stencelbrian-mckinney
authored andcommitted
Revert "fix(otelconsumer): do not retry 401 errors from Elasticsearch (elastic#50261)" (elastic#50341)
This reverts commit fdea8cd.
1 parent a804c16 commit b84a5bc

2 files changed

Lines changed: 1 addition & 49 deletions

File tree

libbeat/otel/otelconsumer/otelconsumer.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24-
"net/http"
2524
"os"
2625
"runtime"
2726
"time"
@@ -48,12 +47,6 @@ const (
4847
esDocumentIDAttribute = "elasticsearch.document_id"
4948
)
5049

51-
// statusCodeError is satisfied by errors that carry an HTTP status code,
52-
// such as docappender.ErrorFlushFailed errors returned from the OTelCol Elasticsearch exporter.
53-
type statusCodeError interface {
54-
StatusCode() int
55-
}
56-
5750
type otelConsumer struct {
5851
observer outputs.Observer
5952
logsConsumer consumer.Logs
@@ -200,20 +193,13 @@ func (out *otelConsumer) logsPublish(ctx context.Context, batch publisher.Batch)
200193

201194
err := out.logsConsumer.ConsumeLogs(otelctx.NewConsumerContext(ctx, out.beatInfo), pLogs)
202195
if err != nil {
203-
// Work around the fact that Elasticsearch exporter returns 401 as a non-permanent error.
204-
isAuthorizationError := false
205-
var statusErr statusCodeError
206-
if errors.As(err, &statusErr) {
207-
isAuthorizationError = statusErr.StatusCode() == http.StatusUnauthorized
208-
}
209-
210196
// Permanent errors shouldn't be retried. This tipically means
211197
// the data cannot be serialized by the exporter that is attached
212198
// to the pipeline or when the destination refuses the data because
213199
// it cannot decode it. Retrying in this case is useless.
214200
//
215201
// See https://github.com/open-telemetry/opentelemetry-collector/blob/1c47d89/receiver/doc.go#L23-L40
216-
if consumererror.IsPermanent(err) || isAuthorizationError {
202+
if consumererror.IsPermanent(err) {
217203
st.PermanentErrors(len(events))
218204
batch.Drop()
219205
} else {

libbeat/otel/otelconsumer/otelconsumer_test.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -240,32 +240,6 @@ func TestPublish(t *testing.T) {
240240
assert.Equal(t, outest.BatchRetry, batch.Signals[0].Tag)
241241
})
242242

243-
t.Run("drops batch on 401 Unauthorized error", func(t *testing.T) {
244-
batch := outest.NewBatch(event1, event2, event3)
245-
246-
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {
247-
return &testStatusCodeError{statusCode: 401, msg: "flush failed (401): unauthorized"}
248-
})
249-
250-
err := otelConsumer.Publish(ctx, batch)
251-
assert.NoError(t, err)
252-
assert.Len(t, batch.Signals, 1)
253-
assert.Equal(t, outest.BatchDrop, batch.Signals[0].Tag)
254-
})
255-
256-
t.Run("retries batch on non-401 status code error", func(t *testing.T) {
257-
batch := outest.NewBatch(event1, event2, event3)
258-
259-
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {
260-
return &testStatusCodeError{statusCode: 500, msg: "flush failed (500): internal server error"}
261-
})
262-
263-
err := otelConsumer.Publish(ctx, batch)
264-
assert.NoError(t, err)
265-
assert.Len(t, batch.Signals, 1)
266-
assert.Equal(t, outest.BatchRetry, batch.Signals[0].Tag)
267-
})
268-
269243
t.Run("sets the elasticsearchexporter doc id attribute from metadata", func(t *testing.T) {
270244
batch := outest.NewBatch(event4)
271245

@@ -390,11 +364,3 @@ func checkEventsActive(reg *monitoring.Registry) int64 {
390364
outputSnapshot := monitoring.CollectFlatSnapshot(reg, monitoring.Full, true)
391365
return outputSnapshot.Ints["events.active"]
392366
}
393-
394-
type testStatusCodeError struct {
395-
statusCode int
396-
msg string
397-
}
398-
399-
func (e *testStatusCodeError) Error() string { return e.msg }
400-
func (e *testStatusCodeError) StatusCode() int { return e.statusCode }

0 commit comments

Comments
 (0)