Skip to content

Commit dc80d03

Browse files
tvernumweizijun
authored andcommitted
Enable smoke-test-watcher with logging (elastic#39169)
SmokeTestWatcherTestSuiteIT.testMonitorClusterHealth has failed a few times with various causes (not all of which we have logs for). This change enables the test again. 1. The fix from elastic#39092 should resolve any issues in assertWatchCount 2. In at least 1 case, getWatchHistoryEntry failed due to a ResponseException, which is not caught by assertBusy. This commit catches those and calls "fail" so that assertBusy will sleep and retry 3. Additional logging has been included to help diagnose any other failures causes.
1 parent ff75191 commit dc80d03

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

x-pack/qa/smoke-test-watcher/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherTestSuiteIT.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.client.Request;
99
import org.elasticsearch.client.Response;
10+
import org.elasticsearch.client.ResponseException;
1011
import org.elasticsearch.common.Strings;
1112
import org.elasticsearch.common.settings.SecureString;
1213
import org.elasticsearch.common.settings.Settings;
@@ -107,7 +108,6 @@ protected Settings restAdminSettings() {
107108
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
108109
}
109110

110-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32299")
111111
public void testMonitorClusterHealth() throws Exception {
112112
String watchId = "cluster_health_watch";
113113

@@ -168,6 +168,7 @@ private void indexWatch(String watchId, XContentBuilder builder) throws Exceptio
168168
Response response = client().performRequest(request);
169169
Map<String, Object> responseMap = entityAsMap(response);
170170
assertThat(responseMap, hasEntry("_id", watchId));
171+
logger.info("Successfully indexed watch with id [{}]", watchId);
171172
}
172173

173174
private void deleteWatch(String watchId) throws IOException {
@@ -181,7 +182,14 @@ private void deleteWatch(String watchId) throws IOException {
181182
private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
182183
final AtomicReference<ObjectPath> objectPathReference = new AtomicReference<>();
183184
assertBusy(() -> {
184-
client().performRequest(new Request("POST", "/.watcher-history-*/_refresh"));
185+
logger.info("Refreshing watcher history");
186+
try {
187+
client().performRequest(new Request("POST", "/.watcher-history-*/_refresh"));
188+
} catch (ResponseException e) {
189+
final String err = "Failed to perform refresh of watcher history - " + e;
190+
logger.info(err);
191+
fail(err);
192+
}
185193

186194
try (XContentBuilder builder = jsonBuilder()) {
187195
builder.startObject();
@@ -193,16 +201,23 @@ private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
193201
.endObject().endArray();
194202
builder.endObject();
195203

204+
logger.info("Searching watcher history");
196205
Request searchRequest = new Request("POST", "/.watcher-history-*/_search");
197206
searchRequest.addParameter(TOTAL_HITS_AS_INT_PARAM, "true");
198207
searchRequest.setJsonEntity(Strings.toString(builder));
199208
Response response = client().performRequest(searchRequest);
200209
ObjectPath objectPath = ObjectPath.createFromResponse(response);
201210
int totalHits = objectPath.evaluate("hits.total");
211+
logger.info("Found [{}] hits in watcher history", totalHits);
202212
assertThat(totalHits, is(greaterThanOrEqualTo(1)));
203-
String watchid = objectPath.evaluate("hits.hits.0._source.watch_id");
204-
assertThat(watchid, is(watchId));
213+
String foundWatchId = objectPath.evaluate("hits.hits.0._source.watch_id");
214+
logger.info("Watch hit 0 has id [{}] (expecting [{}])", foundWatchId, watchId);
215+
assertThat("watch_id for hit 0 in watcher history", foundWatchId, is(watchId));
205216
objectPathReference.set(objectPath);
217+
} catch (ResponseException e) {
218+
final String err = "Failed to perform search of watcher history - " + e;
219+
logger.info(err);
220+
fail(err);
206221
}
207222
});
208223
return objectPathReference.get();
@@ -212,6 +227,7 @@ private void assertWatchCount(int expectedWatches) throws IOException {
212227
Response watcherStatsResponse = adminClient().performRequest(new Request("GET", "/_watcher/stats"));
213228
ObjectPath objectPath = ObjectPath.createFromResponse(watcherStatsResponse);
214229
int watchCount = objectPath.evaluate("stats.0.watch_count");
215-
assertThat(watchCount, is(expectedWatches));
230+
assertThat("Watch count (from _watcher/stats)", watchCount, is(expectedWatches));
231+
logger.info("Watch count is [{}]", watchCount);
216232
}
217233
}

0 commit comments

Comments
 (0)