Skip to content

Commit 3db5625

Browse files
mergify[bot]andrzej-stencelcmacknz
authored
[9.4](backport #50341) Revert "fix(otelconsumer): do not retry 401 errors from Elasticsearch" (#50353)
* Revert "fix(otelconsumer): do not retry 401 errors from Elasticsearch (#50261)" (#50341) This reverts commit fdea8cd. (cherry picked from commit 4ed1c3a) # Conflicts: # libbeat/otel/otelconsumer/otelconsumer.go * Fix conflict --------- Co-authored-by: Andrzej Stencel <andrzej.stencel@elastic.co> Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>
1 parent 79ee08c commit 3db5625

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"
@@ -54,12 +53,6 @@ func init() {
5453
outputs.RegisterType("otelconsumer", makeOtelConsumer)
5554
}
5655

57-
// statusCodeError is satisfied by errors that carry an HTTP status code,
58-
// such as docappender.ErrorFlushFailed errors returned from the OTelCol Elasticsearch exporter.
59-
type statusCodeError interface {
60-
StatusCode() int
61-
}
62-
6356
type otelConsumer struct {
6457
observer outputs.Observer
6558
logsConsumer consumer.Logs
@@ -211,20 +204,13 @@ func (out *otelConsumer) logsPublish(ctx context.Context, batch publisher.Batch)
211204

212205
err := out.logsConsumer.ConsumeLogs(otelctx.NewConsumerContext(ctx, out.beatInfo), pLogs)
213206
if err != nil {
214-
// Work around the fact that Elasticsearch exporter returns 401 as a non-permanent error.
215-
isAuthorizationError := false
216-
var statusErr statusCodeError
217-
if errors.As(err, &statusErr) {
218-
isAuthorizationError = statusErr.StatusCode() == http.StatusUnauthorized
219-
}
220-
221207
// Permanent errors shouldn't be retried. This tipically means
222208
// the data cannot be serialized by the exporter that is attached
223209
// to the pipeline or when the destination refuses the data because
224210
// it cannot decode it. Retrying in this case is useless.
225211
//
226212
// See https://github.com/open-telemetry/opentelemetry-collector/blob/1c47d89/receiver/doc.go#L23-L40
227-
if consumererror.IsPermanent(err) || isAuthorizationError {
213+
if consumererror.IsPermanent(err) {
228214
st.PermanentErrors(len(events))
229215
batch.Drop()
230216
} else {

libbeat/otel/otelconsumer/otelconsumer_test.go

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

269-
t.Run("drops batch on 401 Unauthorized error", func(t *testing.T) {
270-
batch := outest.NewBatch(event1, event2, event3)
271-
272-
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {
273-
return &testStatusCodeError{statusCode: 401, msg: "flush failed (401): unauthorized"}
274-
})
275-
276-
err := otelConsumer.Publish(ctx, batch)
277-
assert.NoError(t, err)
278-
assert.Len(t, batch.Signals, 1)
279-
assert.Equal(t, outest.BatchDrop, batch.Signals[0].Tag)
280-
})
281-
282-
t.Run("retries batch on non-401 status code error", func(t *testing.T) {
283-
batch := outest.NewBatch(event1, event2, event3)
284-
285-
otelConsumer := makeOtelConsumer(t, func(ctx context.Context, ld plog.Logs) error {
286-
return &testStatusCodeError{statusCode: 500, msg: "flush failed (500): internal server error"}
287-
})
288-
289-
err := otelConsumer.Publish(ctx, batch)
290-
assert.NoError(t, err)
291-
assert.Len(t, batch.Signals, 1)
292-
assert.Equal(t, outest.BatchRetry, batch.Signals[0].Tag)
293-
})
294-
295269
t.Run("sets the elasticsearchexporter doc id attribute from metadata", func(t *testing.T) {
296270
batch := outest.NewBatch(event4)
297271

@@ -416,11 +390,3 @@ func checkEventsActive(reg *monitoring.Registry) int64 {
416390
outputSnapshot := monitoring.CollectFlatSnapshot(reg, monitoring.Full, true)
417391
return outputSnapshot.Ints["events.active"]
418392
}
419-
420-
type testStatusCodeError struct {
421-
statusCode int
422-
msg string
423-
}
424-
425-
func (e *testStatusCodeError) Error() string { return e.msg }
426-
func (e *testStatusCodeError) StatusCode() int { return e.statusCode }

0 commit comments

Comments
 (0)