From eb7d43f4cfe910bd06d107176866494c2f7df5cd Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Tue, 16 Jul 2019 08:48:09 -0500 Subject: [PATCH] Log write failures for watcher history document. (#44129) (#44357) The failure is correctly getting propagated, this commit adds support to explicitly look for .watch-history failures using the same logging strategy as triggered watch failures. --- .../elasticsearch/xpack/watcher/Watcher.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index f5f12d4fd24..8ce5901b353 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -334,14 +334,23 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin, Reloa @Override public void afterBulk(long executionId, BulkRequest request, BulkResponse response) { if (response.hasFailures()) { - Map triggeredWatches = Arrays.stream(response.getItems()) + Map triggeredFailures = Arrays.stream(response.getItems()) .filter(BulkItemResponse::isFailed) .filter(r -> r.getIndex().startsWith(TriggeredWatchStoreField.INDEX_NAME)) .collect(Collectors.toMap(BulkItemResponse::getId, BulkItemResponse::getFailureMessage)); - if (triggeredWatches.isEmpty() == false) { - String failure = triggeredWatches.values().stream().collect(Collectors.joining(", ")); + Map historyFailures = Arrays.stream(response.getItems()) + .filter(BulkItemResponse::isFailed) + .filter(r -> r.getIndex().startsWith(HistoryStoreField.INDEX_PREFIX)) + .collect(Collectors.toMap(BulkItemResponse::getId, BulkItemResponse::getFailureMessage)); + if (triggeredFailures.isEmpty() == false) { + String failure = triggeredFailures.values().stream().collect(Collectors.joining(", ")); logger.error("triggered watches could not be deleted {}, failure [{}]", - triggeredWatches.keySet(), Strings.substring(failure, 0, 2000)); + triggeredFailures.keySet(), Strings.substring(failure, 0, 2000)); + } + if (historyFailures.isEmpty() == false) { + String failure = historyFailures.values().stream().collect(Collectors.joining(", ")); + logger.error("watch history could not be written {}, failure [{}]", + historyFailures.keySet(), Strings.substring(failure, 0, 2000)); } Map overwrittenIds = Arrays.stream(response.getItems())