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

OpenSearch Sink: Add log messages when there is no exception #3532

Merged
merged 2 commits into from
Oct 31, 2023

Conversation

kkondaka
Copy link
Collaborator

@kkondaka kkondaka commented Oct 19, 2023

Description

OpenSearch Sink: Add log messages when there is no exception.
OpenSearch Sink BulkOperation failure logs messages only if there is an exception. It is possible that it fails without exception, it is good to log the error reasons for each operation in those cases as well.

Resolves #3508

Issues Resolved

Resolves #3508

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [ X] 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.

Signed-off-by: Kondaka <krishkdk@amazon.com>
Copy link
Member

@graytaylor0 graytaylor0 left a comment

Choose a reason for hiding this comment

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

Implementation looks good. Should add some unit tests

@@ -238,6 +238,13 @@ private BulkOperationRequestResponse handleRetriesAndFailures(final Accumulating
if (doRetry) {
if (retryCount % 5 == 0) {
LOG.warn("Bulk Operation Failed. Number of retries {}. Retrying... ", retryCount, e);
if (Objects.isNull(e)) {
for (final BulkResponseItem bulkItemResponse : bulkResponse.items()) {
if (Objects.nonNull(bulkItemResponse.error())) {
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure that this will be non-null for successful records? Did you test and see no log here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean to say "it will be NULL for successful records"?
Don't know how to test this path easily. But based on the following existing code, I think it will be set to null for successful records.

if (bulkItemResponse.error() == null) {
                    sentDocumentsOnFirstAttemptCounter.increment();
 }

if (Objects.nonNull(bulkItemResponse.error())) {
LOG.warn("operation = {}, error = {}", bulkItemResponse.operationType(), bulkItemResponse.error());
}
}
handleFailures(bulkRequest, bulkResponse.items());
} else {
handleFailures(bulkRequest, failure);
Copy link
Member

Choose a reason for hiding this comment

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

The problem is that right now we only hit this block I think (or at least that is the case when max_retries is reached). But as long as the failure is actually useful this makes sense

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The new change, prints "failure" in both cases. If it is non-null, it will be printed. If it is non-null, I think it would be useful.

graytaylor0
graytaylor0 previously approved these changes Oct 30, 2023
@@ -238,6 +238,13 @@ private BulkOperationRequestResponse handleRetriesAndFailures(final Accumulating
if (doRetry) {
if (retryCount % 5 == 0) {
LOG.warn("Bulk Operation Failed. Number of retries {}. Retrying... ", retryCount, e);
if (Objects.isNull(e)) {
Copy link
Member

Choose a reason for hiding this comment

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

The reason isNull exists is to help with streams. I think outside of a stream, we should use x == null.

if (Objects.isNull(failure)) {
for (final BulkResponseItem bulkItemResponse : bulkResponse.items()) {
if (Objects.nonNull(bulkItemResponse.error())) {
Copy link
Member

Choose a reason for hiding this comment

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

Again, let's use bulkItemResponse.error() == null.

@@ -248,7 +255,13 @@ private BulkOperationRequestResponse handleRetriesAndFailures(final Accumulating
}

private void handleFailures(final AccumulatingBulkRequest<BulkOperationWrapper, BulkRequest> bulkRequest, final BulkResponse bulkResponse, final Throwable failure) {
LOG.warn("Bulk Operation Failed.", failure);
Copy link
Member

Choose a reason for hiding this comment

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

Do we want the full stack trace here? We know where the exception is thrown from right?

Or should this be the following?

 LOG.warn("Bulk Operation Failed. {}", failure.getMessage());

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function may be called from multiple paths, right?

Signed-off-by: Kondaka <krishkdk@amazon.com>
@dlvenable dlvenable merged commit a30fdb5 into opensearch-project:main Oct 31, 2023
54 checks passed
@kkondaka kkondaka deleted the bulk-retry-log-messages branch May 13, 2024 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants