77
88import org .elasticsearch .client .Request ;
99import org .elasticsearch .client .Response ;
10+ import org .elasticsearch .client .ResponseException ;
1011import org .elasticsearch .common .Strings ;
1112import org .elasticsearch .common .settings .SecureString ;
1213import 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