-
Notifications
You must be signed in to change notification settings - Fork 214
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
Add document_version and document_version_type parameters to the open… #3591
Changes from all 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 |
---|---|---|
|
@@ -646,9 +646,11 @@ public void testOpenSearchBulkActionsCreateWithExpression() throws IOException, | |
pluginSetting.getSettings().put(IndexConfiguration.DOCUMENT_ID_FIELD, testIdField); | ||
Event event = (Event)testRecords.get(0).getData(); | ||
event.getMetadata().setAttribute("action", "create"); | ||
final String actionFormatExpression = "${getMetadata(\"action\")}"; | ||
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. It may be good to add an integration test which creates two documents with the same id and version and then we see the error handled correctly. But, it's not critical. |
||
when(expressionEvaluator.isValidFormatExpressions(actionFormatExpression)).thenReturn(true); | ||
when(expressionEvaluator.isValidExpressionStatement("getMetadata(\"action\")")).thenReturn(true); | ||
when(expressionEvaluator.evaluate("getMetadata(\"action\")", event)).thenReturn(event.getMetadata().getAttribute("action")); | ||
pluginSetting.getSettings().put(IndexConfiguration.ACTION, "${getMetadata(\"action\")}"); | ||
pluginSetting.getSettings().put(IndexConfiguration.ACTION, actionFormatExpression); | ||
final OpenSearchSink sink = createObjectUnderTest(pluginSetting, true); | ||
sink.output(testRecords); | ||
final List<Map<String, Object>> retSources = getSearchResponseDocSources(testIndexAlias); | ||
|
@@ -677,9 +679,11 @@ public void testOpenSearchBulkActionsCreateWithInvalidExpression() throws IOExce | |
pluginSetting.getSettings().put(IndexConfiguration.DOCUMENT_ID_FIELD, testIdField); | ||
Event event = (Event)testRecords.get(0).getData(); | ||
event.getMetadata().setAttribute("action", "unknown"); | ||
final String actionFormatExpression = "${getMetadata(\"action\")}"; | ||
when(expressionEvaluator.isValidFormatExpressions(actionFormatExpression)).thenReturn(true); | ||
when(expressionEvaluator.isValidExpressionStatement("getMetadata(\"action\")")).thenReturn(true); | ||
when(expressionEvaluator.evaluate("getMetadata(\"action\")", event)).thenReturn(event.getMetadata().getAttribute("action")); | ||
pluginSetting.getSettings().put(IndexConfiguration.ACTION, "${getMetadata(\"action\")}"); | ||
pluginSetting.getSettings().put(IndexConfiguration.ACTION, actionFormatExpression); | ||
final OpenSearchSink sink = createObjectUnderTest(pluginSetting, true); | ||
sink.output(testRecords); | ||
final List<Map<String, Object>> retSources = getSearchResponseDocSources(testIndexAlias); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,10 @@ public final class BulkRetryStrategy { | |
public static final String BULK_REQUEST_NOT_FOUND_ERRORS = "bulkRequestNotFoundErrors"; | ||
public static final String BULK_REQUEST_TIMEOUT_ERRORS = "bulkRequestTimeoutErrors"; | ||
public static final String BULK_REQUEST_SERVER_ERRORS = "bulkRequestServerErrors"; | ||
public static final String DOCUMENTS_VERSION_CONFLICT_ERRORS = "documentsVersionConflictErrors"; | ||
static final long INITIAL_DELAY_MS = 50; | ||
static final long MAXIMUM_DELAY_MS = Duration.ofMinutes(10).toMillis(); | ||
static final String VERSION_CONFLICT_EXCEPTION_TYPE = "version_conflict_engine_exception"; | ||
|
||
private static final Set<Integer> NON_RETRY_STATUS = new HashSet<>( | ||
Arrays.asList( | ||
|
@@ -116,6 +118,7 @@ public final class BulkRetryStrategy { | |
private final Counter bulkRequestNotFoundErrors; | ||
private final Counter bulkRequestTimeoutErrors; | ||
private final Counter bulkRequestServerErrors; | ||
private final Counter documentsVersionConflictErrors; | ||
private static final Logger LOG = LoggerFactory.getLogger(BulkRetryStrategy.class); | ||
|
||
static class BulkOperationRequestResponse { | ||
|
@@ -160,6 +163,7 @@ public BulkRetryStrategy(final RequestFunction<AccumulatingBulkRequest<BulkOpera | |
bulkRequestNotFoundErrors = pluginMetrics.counter(BULK_REQUEST_NOT_FOUND_ERRORS); | ||
bulkRequestTimeoutErrors = pluginMetrics.counter(BULK_REQUEST_TIMEOUT_ERRORS); | ||
bulkRequestServerErrors = pluginMetrics.counter(BULK_REQUEST_SERVER_ERRORS); | ||
documentsVersionConflictErrors = pluginMetrics.counter(DOCUMENTS_VERSION_CONFLICT_ERRORS); | ||
} | ||
|
||
private void incrementErrorCounters(final Exception e) { | ||
|
@@ -240,7 +244,7 @@ private BulkOperationRequestResponse handleRetriesAndFailures(final Accumulating | |
LOG.warn("Bulk Operation Failed. Number of retries {}. Retrying... ", retryCount, e); | ||
if (e == null) { | ||
for (final BulkResponseItem bulkItemResponse : bulkResponse.items()) { | ||
if (Objects.nonNull(bulkItemResponse.error())) { | ||
if (bulkItemResponse.error() != null) { | ||
LOG.warn("operation = {}, error = {}", bulkItemResponse.operationType(), bulkItemResponse.error().reason()); | ||
} | ||
} | ||
|
@@ -255,15 +259,16 @@ 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); | ||
if (failure == null) { | ||
for (final BulkResponseItem bulkItemResponse : bulkResponse.items()) { | ||
if (Objects.nonNull(bulkItemResponse.error())) { | ||
// Skip logging the error for version conflicts | ||
if (bulkItemResponse.error() != null && !VERSION_CONFLICT_EXCEPTION_TYPE.equals(bulkItemResponse.error().type())) { | ||
LOG.warn("operation = {}, error = {}", bulkItemResponse.operationType(), bulkItemResponse.error().reason()); | ||
} | ||
} | ||
handleFailures(bulkRequest, bulkResponse.items()); | ||
} else { | ||
LOG.warn("Bulk Operation Failed.", failure); | ||
handleFailures(bulkRequest, failure); | ||
} | ||
bulkRequestFailedCounter.increment(); | ||
|
@@ -313,6 +318,10 @@ private AccumulatingBulkRequest<BulkOperationWrapper, BulkRequest> createBulkReq | |
if (bulkItemResponse.error() != null) { | ||
if (!NON_RETRY_STATUS.contains(bulkItemResponse.status())) { | ||
requestToReissue.addOperation(bulkOperation); | ||
} else if (VERSION_CONFLICT_EXCEPTION_TYPE.equals(bulkItemResponse.error().type())) { | ||
documentsVersionConflictErrors.increment(); | ||
LOG.debug("Received version conflict from OpenSearch: {}", bulkItemResponse.error().reason()); | ||
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. I'm generally keen on this logging, but we should also be consistent. Why log here when we often don't log? 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. It's debug log to share details about version conflicts. Some users may wish to know which records had conflicts 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. Other failures are logged, just elsewhere. This one is dropped instead of sending to DLQ or logging the failure i |
||
bulkOperation.releaseEventHandle(true); | ||
} else { | ||
nonRetryableFailures.add(FailedBulkOperation.builder() | ||
.withBulkOperation(bulkOperation) | ||
|
@@ -338,10 +347,16 @@ private void handleFailures(final AccumulatingBulkRequest<BulkOperationWrapper, | |
final BulkResponseItem bulkItemResponse = itemResponses.get(i); | ||
final BulkOperationWrapper bulkOperation = accumulatingBulkRequest.getOperationAt(i); | ||
if (bulkItemResponse.error() != null) { | ||
failures.add(FailedBulkOperation.builder() | ||
.withBulkOperation(bulkOperation) | ||
.withBulkResponseItem(bulkItemResponse) | ||
.build()); | ||
if (VERSION_CONFLICT_EXCEPTION_TYPE.equals(bulkItemResponse.error().type())) { | ||
documentsVersionConflictErrors.increment(); | ||
LOG.debug("Received version conflict from OpenSearch: {}", bulkItemResponse.error().reason()); | ||
bulkOperation.releaseEventHandle(true); | ||
} else { | ||
failures.add(FailedBulkOperation.builder() | ||
.withBulkOperation(bulkOperation) | ||
.withBulkResponseItem(bulkItemResponse) | ||
.build()); | ||
} | ||
documentErrorsCounter.increment(); | ||
} else { | ||
sentDocumentsCounter.increment(); | ||
|
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.
You have a typo here. This takes a singular expression, but the name uses plural "expressions."