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

Handle errors from OpenSearch by checking status field as well as error #4335

Merged

Conversation

dlvenable
Copy link
Member

Description

It appears that for some situations, Amazon OpenSearch Serverless is not including the error field in bulk response errors. This PR includes a check on the status field as well.

Issues Resolved

N/A

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…he error body for each bulk response item.

Signed-off-by: David Venable <dlv@amazon.com>
kkondaka
kkondaka previously approved these changes Mar 26, 2024
@@ -234,7 +235,7 @@ private BulkOperationRequestResponse handleRetriesAndFailures(final Accumulating
final boolean doRetry = (Objects.isNull(exceptionFromRequest)) ? canRetry(bulkResponse) : canRetry(exceptionFromRequest);
if (!Objects.isNull(bulkResponse) && retryCount == 1) { // first attempt
for (final BulkResponseItem bulkItemResponse : bulkResponse.items()) {
if (bulkItemResponse.error() == null) {
if (!isItemInError(bulkItemResponse)) {
sentDocumentsOnFirstAttemptCounter.increment();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's another call to BulkResponseItem::error on line 247 for logging. Not as critical but would be good to have the same check there

// Skip logging the error for version conflicts
final ErrorCause error = bulkItemResponse.error();
if (error != null && VERSION_CONFLICT_EXCEPTION_TYPE.equals(error.type())) {
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a continue in case there are non version conflict exceptions later in the response items?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, definitely. Thanks for catching this!

if (error != null && VERSION_CONFLICT_EXCEPTION_TYPE.equals(error.type())) {
break;
}
LOG.warn("operation = {}, status = {}, error = {}", bulkItemResponse.operationType(), bulkItemResponse.status(), error != null ? error.reason() : "");
}
}
handleFailures(bulkRequest, bulkResponse.items());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we do a similar rest status check on line 290 as well for the BulkResponse?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you referring to this line?

if (bulkResponse.errors()) {

I think you are suggesting that we also check the status of the HTTP response. I don't see any methods supporting this on this class. I believe that the client will throw an exception if the whole HTTP status is an error status. That's what this catch is for:

        } catch (Exception e) {
            incrementErrorCounters(e);
            return handleRetriesAndFailures(bulkRequestForRetry, retryCount, null, e);
        }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it, makes sense

Signed-off-by: David Venable <dlv@amazon.com>
@dlvenable
Copy link
Member Author

@engechas , I fixed two of your comments and an unsure for one of them.

@kkondaka , @engechas , I'll need another review on this.

@dlvenable dlvenable merged commit 3c7cb8e into opensearch-project:main Mar 26, 2024
68 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 26, 2024
…or (#4335)

Handle errors from OpenSearch by checking both the status field and the error body for each bulk response item.

Signed-off-by: David Venable <dlv@amazon.com>
(cherry picked from commit 3c7cb8e)
@dlvenable dlvenable deleted the opensearch-improved-error-handling branch March 27, 2024 23:49
dlvenable added a commit that referenced this pull request Mar 28, 2024
…or (#4335) (#4336)

Handle errors from OpenSearch by checking both the status field and the error body for each bulk response item.

Signed-off-by: David Venable <dlv@amazon.com>
(cherry picked from commit 3c7cb8e)

Co-authored-by: David Venable <dlv@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants