From 79a66d1331df2ee1d46fbbe690bd2d90b2c51c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20D=C3=A9nari=C3=A9?= Date: Fri, 11 Oct 2024 17:54:52 +0200 Subject: [PATCH] fix: Ensure to display version_conflict ES error message as warn - EXO-74730 When we send analytics to ES, we firstly try to send it in a bulk. If an element of the bulk generates an error in ES, we resend each request of the bulk one by one. If the failed one is the i-st element, then request 1..i-1 will generated a version_conflict_engine_exception. In 6.5, this was seen as a warn, an not generates an error. In 7.0, it is seen as error, and then, like for each error, we try to resend it 5 times before dropping it, which could generate a log of logs. This commit ensure to not raise an exception in this case : - ES answer contains "error":true AND ES answer contains "type":"version_conflict_engine_exception" AND ES anwser concern only one entry. If we have more than one entry, then we are in a bulk, and we cannot know which entry generated the version conflict, so we have to consider this as an error, and rerun each request separatly. Resolves meesd-io/meeds#2487 --- .../storage/ElasticsearchAnalyticsStorage.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/analytics-services/src/main/java/io/meeds/analytics/elasticsearch/storage/ElasticsearchAnalyticsStorage.java b/analytics-services/src/main/java/io/meeds/analytics/elasticsearch/storage/ElasticsearchAnalyticsStorage.java index 96000c7f2..fee11e60b 100644 --- a/analytics-services/src/main/java/io/meeds/analytics/elasticsearch/storage/ElasticsearchAnalyticsStorage.java +++ b/analytics-services/src/main/java/io/meeds/analytics/elasticsearch/storage/ElasticsearchAnalyticsStorage.java @@ -370,13 +370,24 @@ private boolean isError(int status) { } private ElasticsearchResponse handleESResponse(ElasticsearchResponse response, String uri, String content) { - if (isError(response) || StringUtils.contains(response.getMessage(), "\"errors\":true")) { + if (isError(response)) { throw new IllegalStateException(String.format("Error message returned from ES: %s. URI: %s. Content: %s", response.getMessage(), uri, content)); - } else if (StringUtils.contains(response.getMessage(), "\"type\":\"version_conflict_engine_exception\"")) { - LOG.warn("ID conflict in some content: {}", response.getMessage()); + } + if (StringUtils.contains(response.getMessage(), "\"errors\":true")) { + if (StringUtils.contains(response.getMessage(), "\"type\":\"version_conflict_engine_exception\"") + && StringUtils.countMatches(response.getMessage(),"{\"create\":{") == 1) { + //the ES response is not answer of a bulk, but of a single insert + //it means the entry already exists in ES, no need to raise an error + LOG.warn("ID conflict in some content: {}", response.getMessage()); + } else { + throw new IllegalStateException(String.format("Error message returned from ES: %s. URI: %s. Content: %s", + response.getMessage(), + uri, + content)); + } } return response; }