Skip to content

Commit 786add0

Browse files
authored
fix: filter ES error responses (#206)
1 parent e81f4f4 commit 786add0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

appender_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
748748
for i, item := range result.Items {
749749
itemResp := item["create"]
750750
itemResp.Index = "an_index"
751-
switch i % 4 {
751+
switch i % 5 {
752752
case 0:
753753
itemResp.Error.Type = "error_type"
754754
itemResp.Error.Reason = "error_reason_even. Preview of field's value: 'abc def ghi'"
@@ -761,7 +761,9 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
761761
case 3:
762762
itemResp.Error.Type = "x_content_parse_exception"
763763
itemResp.Error.Reason = "this reason should not be logged"
764-
764+
case 4:
765+
itemResp.Error.Type = "document_parsing_exception"
766+
itemResp.Error.Reason = "this reason should not be logged"
765767
}
766768
item["create"] = itemResp
767769
}
@@ -777,7 +779,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
777779
require.NoError(t, err)
778780
defer indexer.Close(context.Background())
779781

780-
const N = 4 * 2
782+
const N = 5 * 2
781783
for i := 0; i < N; i++ {
782784
addMinimalDoc(t, indexer, "logs-foo-testing")
783785
}
@@ -789,14 +791,16 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
789791
return entries[i].Message < entries[j].Message
790792
})
791793
require.Len(t, entries, N/2)
792-
assert.Equal(t, "failed to index documents in 'an_index' (error_type): error_reason_even", entries[0].Message)
794+
assert.Equal(t, "failed to index documents in 'an_index' (document_parsing_exception): ", entries[0].Message)
793795
assert.Equal(t, int64(2), entries[0].Context[0].Integer)
794-
assert.Equal(t, "failed to index documents in 'an_index' (error_type): error_reason_odd", entries[1].Message)
796+
assert.Equal(t, "failed to index documents in 'an_index' (error_type): error_reason_even", entries[1].Message)
795797
assert.Equal(t, int64(2), entries[1].Context[0].Integer)
796-
assert.Equal(t, "failed to index documents in 'an_index' (unavailable_shards_exception): ", entries[2].Message)
798+
assert.Equal(t, "failed to index documents in 'an_index' (error_type): error_reason_odd", entries[2].Message)
797799
assert.Equal(t, int64(2), entries[2].Context[0].Integer)
798-
assert.Equal(t, "failed to index documents in 'an_index' (x_content_parse_exception): ", entries[3].Message)
800+
assert.Equal(t, "failed to index documents in 'an_index' (unavailable_shards_exception): ", entries[3].Message)
799801
assert.Equal(t, int64(2), entries[3].Context[0].Integer)
802+
assert.Equal(t, "failed to index documents in 'an_index' (x_content_parse_exception): ", entries[4].Message)
803+
assert.Equal(t, int64(2), entries[4].Context[0].Integer)
800804
}
801805

802806
func TestAppenderRetryLimit(t *testing.T) {

bulk_indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func init() {
158158
return true
159159
})
160160
// For specific exceptions, remove item.Error.Reason as it may contain sensitive request content.
161-
if item.Error.Type == "unavailable_shards_exception" || item.Error.Type == "x_content_parse_exception" {
161+
if item.Error.Type == "unavailable_shards_exception" || item.Error.Type == "x_content_parse_exception" || item.Error.Type == "document_parsing_exception" {
162162
item.Error.Reason = ""
163163
}
164164

0 commit comments

Comments
 (0)