-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[exporter/opensearch] Retry transient failures instead of dropping them as permanent #49605
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: bug_fix | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) | ||
| component: exporter/opensearch | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Retry transient OpenSearch failures instead of dropping them as permanent errors | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [49208] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | | ||
| Indexer-level failures such as connection refused, timeouts, and DNS errors were wrapped as | ||
| permanent errors, so exporterhelper dropped the batch even with retry_on_failure enabled. They | ||
| are now surfaced as retryable, and per-item transport errors (net.OpError) are retried as well, | ||
| while encoding and bad-document errors remain permanent. | ||
|
|
||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [user] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "bytes" | ||
| "context" | ||
| "errors" | ||
| "net" | ||
| "time" | ||
|
|
||
| "github.com/opensearch-project/opensearch-go/v4/opensearchapi" | ||
|
|
@@ -47,7 +48,11 @@ func (lbi *logBulkIndexer) close(ctx context.Context) { | |
|
|
||
| func (lbi *logBulkIndexer) onIndexerError(_ context.Context, indexerErr error) { | ||
| if indexerErr != nil { | ||
| lbi.appendPermanentError(consumererror.NewPermanent(indexerErr)) | ||
| // Indexer-level errors are transport/flush failures (connection refused, | ||
| // timeout, DNS). They are transient, so surface them as a retryable error | ||
| // and let exporterhelper's retry_on_failure resend the batch instead of | ||
| // dropping it as permanent. | ||
| lbi.errs = append(lbi.errs, indexerErr) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -128,8 +133,15 @@ func (lbi *logBulkIndexer) processItemFailure(resp opensearchapi.BulkRespItem, i | |
| // Non-recoverable OpenSearch error while indexing document | ||
| lbi.appendPermanentError(responseAsError(resp)) | ||
| default: | ||
| // Encoding error. We didn't even attempt to send the event | ||
| lbi.appendPermanentError(itemErr) | ||
| // A transport error (e.g. net.OpError) reported per item is transient and | ||
| // should be retried; anything else here is an encoding error we never sent, | ||
| // which is permanent. | ||
| var netErr *net.OpError | ||
| if errors.As(itemErr, &netErr) { | ||
| lbi.appendRetryLogError(itemErr, logs) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only retries |
||
| } else { | ||
| lbi.appendPermanentError(itemErr) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a flush failure, doesn't |
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,12 @@ package opensearchexporter | |
|
|
||
| import ( | ||
| "errors" | ||
| "net" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/opensearch-project/opensearch-go/v4/opensearchapi" | ||
| "go.opentelemetry.io/collector/consumer/consumererror" | ||
| "go.opentelemetry.io/collector/pdata/pcommon" | ||
| "go.opentelemetry.io/collector/pdata/plog" | ||
| ) | ||
|
|
@@ -60,6 +62,41 @@ func TestProcessItemFailure(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestOnIndexerErrorIsRetryable(t *testing.T) { | ||
| lbi := &logBulkIndexer{} | ||
| // A transport failure surfaces through the bulk indexer's OnError callback. | ||
| lbi.onIndexerError(t.Context(), &net.OpError{Op: "dial", Err: errors.New("connection refused")}) | ||
| err := lbi.joinedError() | ||
| if err == nil { | ||
| t.Fatal("expected an error") | ||
| } | ||
| if consumererror.IsPermanent(err) { | ||
| t.Error("indexer-level transport error must be retryable, not permanent (otherwise retry_on_failure silently drops the batch)") | ||
| } | ||
| } | ||
|
|
||
| func TestProcessItemFailureTransportErrorRetryable(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we drive a real flush via func TestProcessItemFailureTransportRetryable(t *testing.T) {
tests := []struct {
name string
handler http.HandlerFunc // nil => point at a dead port
}{
{"connection refused", nil},
{"connection drop mid-request", func(w http.ResponseWriter, _ *http.Request) {
conn, _, _ := w.(http.Hijacker).Hijack()
conn.Close()
}},
{"reset after read", func(w http.ResponseWriter, r *http.Request) {
io.Copy(io.Discard, r.Body)
conn, _, _ := w.(http.Hijacker).Hijack()
if tcp, ok := conn.(*net.TCPConn); ok {
tcp.SetLinger(0) // force RST
}
conn.Close()
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
endpoint := "http://127.0.0.1:1" // dead port
if tt.handler != nil {
srv := httptest.NewServer(tt.handler)
defer srv.Close()
endpoint = srv.URL
}
client, _ := newOpenSearchClient(endpoint, http.DefaultClient, zap.NewNop())
idx := newLogBulkIndexer("create", model, "")
require.NoError(t, idx.start(client))
idx.submit(context.Background(), logs, ir, cfg, time.Now())
idx.close(context.Background())
err := idx.joinedError()
require.Error(t, err)
require.False(t, consumererror.IsPermanent(err),
"transient flush failure must be retryable, else retry_on_failure drops the batch")
})
}
} |
||
| // A per-item transport error (net.OpError) with no HTTP status is transient. | ||
| lbi := &logBulkIndexer{} | ||
| lbi.processItemFailure(opensearchapi.BulkRespItem{Status: 0}, &net.OpError{Op: "read", Err: errors.New("i/o timeout")}, plog.NewLogs()) | ||
| if len(lbi.errs) != 1 { | ||
| t.Fatalf("expected 1 error, got %d", len(lbi.errs)) | ||
| } | ||
| if consumererror.IsPermanent(lbi.errs[0]) { | ||
| t.Error("per-item transport error must be retryable, not permanent") | ||
| } | ||
|
|
||
| // A genuine encoding error (never sent) stays permanent. | ||
| lbi2 := &logBulkIndexer{} | ||
| lbi2.processItemFailure(opensearchapi.BulkRespItem{Status: 0}, errors.New("encode failed"), plog.NewLogs()) | ||
| if len(lbi2.errs) != 1 { | ||
| t.Fatalf("expected 1 error, got %d", len(lbi2.errs)) | ||
| } | ||
| if !consumererror.IsPermanent(lbi2.errs[0]) { | ||
| t.Error("encoding error must remain permanent") | ||
| } | ||
| } | ||
|
|
||
| func TestNewLogBulkIndexerWithPipeline(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it also fixes #45147 and is closely related to #45120. Worth adding them to
issues:so they get closed/linked