-
Notifications
You must be signed in to change notification settings - Fork 11
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
bulk_indexer: track all response status codes #177
Changes from 2 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 |
---|---|---|
|
@@ -351,10 +351,19 @@ func (b *BulkIndexer) Flush(ctx context.Context) (BulkIndexerResponseStat, error | |
b.bytesUncompFlushed = bytesUncompFlushed | ||
var resp BulkIndexerResponseStat | ||
if res.IsError() { | ||
if res.StatusCode == http.StatusTooManyRequests { | ||
return resp, errorTooManyRequests{res: res} | ||
e := errorFlushFailed{resp: res.String(), statusCode: res.StatusCode} | ||
if res.StatusCode >= 400 { | ||
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. nit: can we have the switch case here as well? I find it more readable than nested if. Here we'll get the added benefit of fewer return statements. |
||
if res.StatusCode == http.StatusTooManyRequests { | ||
e.tooMany = true | ||
return resp, e | ||
} | ||
if res.StatusCode >= 500 { | ||
e.serverError = true | ||
return resp, e | ||
} | ||
e.clientError = true | ||
} | ||
return resp, fmt.Errorf("flush failed: %s", res.String()) | ||
return resp, e | ||
} | ||
|
||
if err := jsoniter.NewDecoder(res.Body).Decode(&resp); err != nil { | ||
|
@@ -530,10 +539,14 @@ func indexnth(s []byte, nth int, sep rune) int { | |
}) | ||
} | ||
|
||
type errorTooManyRequests struct { | ||
res *esapi.Response | ||
type errorFlushFailed struct { | ||
resp string | ||
statusCode int | ||
tooMany bool | ||
clientError bool | ||
serverError bool | ||
Comment on lines
+539
to
+544
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. nice 👍🏼 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. one other option would be to have a typed error for each case, and then wrapping them into an error returned on the specific branch, but we can always change that later |
||
} | ||
|
||
func (e errorTooManyRequests) Error() string { | ||
return fmt.Sprintf("flush failed: %s", e.res.String()) | ||
func (e errorFlushFailed) Error() string { | ||
return fmt.Sprintf("flush failed (%d): %s", e.statusCode, e.resp) | ||
} |
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.
go-elasticsearch client treats
StatusCode > 299
as Error here. I'm not sure how relevant handling of 3xx is, but right now any 3xx will be skipped in here