From d8c368ca717c12c042634bcfb79bec6107e9731a Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 9 Apr 2020 11:35:12 -0400 Subject: [PATCH] Clear recent errors when auto-follow successfully (#54997) Today, we do not clear the recent errors in AutoFollowCoordinator when we successfully auto-follow indices. This can lead to confusion for the operators. --- .../ccr/action/AutoFollowCoordinator.java | 5 ++++- .../action/AutoFollowCoordinatorTests.java | 19 +++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index c20baa6b92355..faa1e44fcbb36 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -176,15 +176,18 @@ synchronized void updateStats(List results) { LOGGER.warn(new ParameterizedMessage("failure occurred while fetching cluster state for auto follow pattern [{}]", result.autoFollowPatternName), result.clusterStateFetchException); } else { + recentAutoFollowErrors.remove(result.autoFollowPatternName); for (Map.Entry entry : result.autoFollowExecutionResults.entrySet()) { + final String patternAndIndexKey = result.autoFollowPatternName + ":" + entry.getKey().getName(); if (entry.getValue() != null) { numberOfFailedIndicesAutoFollowed++; - recentAutoFollowErrors.put(result.autoFollowPatternName + ":" + entry.getKey().getName(), + recentAutoFollowErrors.put(patternAndIndexKey, Tuple.tuple(newStatsReceivedTimeStamp, ExceptionsHelper.convertToElastic(entry.getValue()))); LOGGER.warn(new ParameterizedMessage("failure occurred while auto following index [{}] for auto follow " + "pattern [{}]", entry.getKey(), result.autoFollowPatternName), entry.getValue()); } else { numberOfSuccessfulIndicesAutoFollowed++; + recentAutoFollowErrors.remove(patternAndIndexKey); } } } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java index 5d02d129bf582..9660ad8b404b2 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinatorTests.java @@ -55,6 +55,7 @@ import static org.elasticsearch.xpack.ccr.action.AutoFollowCoordinator.AutoFollower.cleanFollowedRemoteIndices; import static org.elasticsearch.xpack.ccr.action.AutoFollowCoordinator.AutoFollower.recordLeaderIndexAsFollowFunction; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; @@ -569,18 +570,18 @@ public void testStats() { autoFollowCoordinator.updateStats(Arrays.asList( new AutoFollowCoordinator.AutoFollowResult("_alias1", - Collections.singletonList(Tuple.tuple(new Index("index1", "_na_"), new RuntimeException("error")))), + Collections.singletonList(Tuple.tuple(new Index("index1", "_na_"), new RuntimeException("error-1")))), new AutoFollowCoordinator.AutoFollowResult("_alias2", - Collections.singletonList(Tuple.tuple(new Index("index2", "_na_"), new RuntimeException("error")))) + Collections.singletonList(Tuple.tuple(new Index("index2", "_na_"), new RuntimeException("error-2")))) )); autoFollowStats = autoFollowCoordinator.getStats(); assertThat(autoFollowStats.getNumberOfFailedFollowIndices(), equalTo(2L)); assertThat(autoFollowStats.getNumberOfFailedRemoteClusterStateRequests(), equalTo(1L)); assertThat(autoFollowStats.getNumberOfSuccessfulFollowIndices(), equalTo(0L)); - assertThat(autoFollowStats.getRecentAutoFollowErrors().size(), equalTo(3)); - assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias1").v2().getCause().getMessage(), equalTo("error")); - assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias1:index1").v2().getCause().getMessage(), equalTo("error")); - assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias2:index2").v2().getCause().getMessage(), equalTo("error")); + assertThat(autoFollowStats.getRecentAutoFollowErrors().size(), equalTo(2)); + assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias1"), nullValue()); + assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias1:index1").v2().getCause().getMessage(), equalTo("error-1")); + assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias2:index2").v2().getCause().getMessage(), equalTo("error-2")); autoFollowCoordinator.updateStats(Arrays.asList( new AutoFollowCoordinator.AutoFollowResult("_alias1", @@ -592,10 +593,8 @@ public void testStats() { assertThat(autoFollowStats.getNumberOfFailedFollowIndices(), equalTo(2L)); assertThat(autoFollowStats.getNumberOfFailedRemoteClusterStateRequests(), equalTo(1L)); assertThat(autoFollowStats.getNumberOfSuccessfulFollowIndices(), equalTo(2L)); - assertThat(autoFollowStats.getRecentAutoFollowErrors().size(), equalTo(3)); - assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias1").v2().getCause().getMessage(), equalTo("error")); - assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias1:index1").v2().getCause().getMessage(), equalTo("error")); - assertThat(autoFollowStats.getRecentAutoFollowErrors().get("_alias2:index2").v2().getCause().getMessage(), equalTo("error")); + assertThat(autoFollowStats.getRecentAutoFollowErrors().keySet(), empty()); + } public void testUpdateAutoFollowers() {