Skip to content
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

Avoid process crash when elasticsearch response is nil #1467

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac
m.Delete(id)

// log individual errors, note that err might be false and these errors still present
if response.Errors {
if response != nil && response.Errors {
for _, it := range response.Items {
for key, val := range it {
if val.Error != nil {
Expand All @@ -127,13 +127,21 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac

sm.Emit(err, time.Since(start.(time.Time)))
if err != nil {
failed := len(response.Failed())
var failed int
var respval interface{}
if response == nil {
failed = 0
respval = "nil"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this logged by default as nil when it's nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , it will be logged as null by default; I will remove unneeded action

} else {
failed = len(response.Failed())
respval = response
}
total := len(requests)
logger.Error("Elasticsearch could not process bulk request",
zap.Int("request_count", total),
zap.Int("failed_count", failed),
zap.Error(err),
zap.Any("response", response))
zap.Any("response", respval))
}
}).
BulkSize(c.BulkSize).
Expand Down