Skip to content

Commit

Permalink
Remove item.Error.Reason for unavailable_shards_exception (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip committed Jun 3, 2024
1 parent 8729c8c commit c6aa3e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions appender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,16 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
for i, item := range result.Items {
itemResp := item["create"]
itemResp.Index = "an_index"
itemResp.Error.Type = "error_type"
if i%2 == 0 {
switch i % 3 {
case 0:
itemResp.Error.Type = "error_type"
itemResp.Error.Reason = "error_reason_even. Preview of field's value: 'abc def ghi'"
} else {
case 1:
itemResp.Error.Type = "error_type"
itemResp.Error.Reason = "error_reason_odd. Preview of field's value: some field value"
case 2:
itemResp.Error.Type = "unavailable_shards_exception"
itemResp.Error.Reason = "this reason should not be logged"
}
item["create"] = itemResp
}
Expand All @@ -583,7 +588,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
require.NoError(t, err)
defer indexer.Close(context.Background())

const N = 4
const N = 3 * 2
for i := 0; i < N; i++ {
addMinimalDoc(t, indexer, "logs-foo-testing")
}
Expand All @@ -599,6 +604,8 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
assert.Equal(t, int64(2), entries[0].Context[0].Integer)
assert.Equal(t, "failed to index documents in 'an_index' (error_type): error_reason_odd", entries[1].Message)
assert.Equal(t, int64(2), entries[1].Context[0].Integer)
assert.Equal(t, "failed to index documents in 'an_index' (unavailable_shards_exception): ", entries[2].Message)
assert.Equal(t, int64(2), entries[2].Context[0].Integer)
}

func TestAppenderRetryLimit(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions bulk_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func init() {
}
return true
})
// For unavailable_shards_exception, remove item.Error.Reason as it may contain sensitive request content.
if item.Error.Type == "unavailable_shards_exception" {
item.Error.Reason = ""
}

item.Position = idx
idx++
if item.Error.Type != "" || item.Status > 201 {
Expand Down

0 comments on commit c6aa3e0

Please sign in to comment.