2525import org .elasticsearch .common .settings .Settings ;
2626import org .elasticsearch .core .Strings ;
2727import org .elasticsearch .core .Tuple ;
28+ import org .elasticsearch .health .node .DataStreamLifecycleHealthInfo ;
29+ import org .elasticsearch .health .node .DslErrorInfo ;
30+ import org .elasticsearch .health .node .FetchHealthInfoCacheAction ;
2831import org .elasticsearch .health .node .HealthInfoCache ;
32+ import org .elasticsearch .health .node .selection .HealthNode ;
2933import org .elasticsearch .reservedstate .action .ReservedClusterSettingsAction ;
3034import org .elasticsearch .test .ESIntegTestCase ;
3135import org .junit .Before ;
4751import static org .hamcrest .Matchers .containsInAnyOrder ;
4852import static org .hamcrest .Matchers .containsString ;
4953import static org .hamcrest .Matchers .equalTo ;
54+ import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
5055import static org .hamcrest .Matchers .hasSize ;
5156import static org .hamcrest .Matchers .is ;
57+ import static org .hamcrest .Matchers .not ;
5258import static org .hamcrest .Matchers .notNullValue ;
5359import static org .hamcrest .Matchers .nullValue ;
5460
@@ -501,23 +507,28 @@ public void testSettingsAppliedOnMasterReElection() throws Exception {
501507
502508 public void testHealthIndicator () throws Exception {
503509 internalCluster ().setBootstrapMasterNodeIndex (0 );
504- logger .info ("--> start a second node to act as the health node" );
505- String dataNode = internalCluster ().startNode (Settings .builder ().put (dataOnlyNode ()).put ("discovery.initial_state_timeout" , "1s" ));
506-
507- // Note that we assume the data node is the health node
508- // TODO: Can we do better?
509- var actualHealthInfoCache = internalCluster ().getInstance (HealthInfoCache .class , dataNode );
510+ logger .info ("--> start a data node to act as the health node" );
511+ internalCluster ().startNode (Settings .builder ().put (dataOnlyNode ()).put ("discovery.initial_state_timeout" , "1s" ));
510512
511513 logger .info ("--> start master node" );
512514 final String masterNode = internalCluster ().startMasterOnlyNode (
513515 Settings .builder ().put (INITIAL_STATE_TIMEOUT_SETTING .getKey (), "0s" ).build ()
514516 );
515517 FileSettingsService masterFileSettingsService = internalCluster ().getInstance (FileSettingsService .class , masterNode );
516518 assertBusy (() -> assertTrue (masterFileSettingsService .watching ()));
519+
517520 ensureStableCluster (2 );
518521
522+ var healthNode = HealthNode .findHealthNode (clusterService ().state ()).getName ();
523+
519524 // Initially, all is well
520- assertBusy (() -> assertEquals (0 , actualHealthInfoCache .getHealthInfo ().fileSettingsHealthInfo ().failureStreak ()));
525+ assertBusy (() -> {
526+ FetchHealthInfoCacheAction .Response healthNodeResponse = client (healthNode ).execute (
527+ FetchHealthInfoCacheAction .INSTANCE ,
528+ new FetchHealthInfoCacheAction .Request ()
529+ ).get ();
530+ assertEquals (0 , healthNodeResponse .getHealthInfo ().fileSettingsHealthInfo ().failureStreak ());
531+ });
521532
522533 logger .info ("--> induce an error and wait for it to be processed" );
523534 var savedClusterState = setupClusterStateListenerForError (masterNode );
@@ -526,7 +537,13 @@ public void testHealthIndicator() throws Exception {
526537 assertTrue (awaitSuccessful );
527538
528539 logger .info ("--> ensure the health node also reports it" );
529- assertBusy (() -> assertEquals (1 , actualHealthInfoCache .getHealthInfo ().fileSettingsHealthInfo ().failureStreak ()));
540+ assertBusy (() -> {
541+ FetchHealthInfoCacheAction .Response healthNodeResponse = client (healthNode ).execute (
542+ FetchHealthInfoCacheAction .INSTANCE ,
543+ new FetchHealthInfoCacheAction .Request ()
544+ ).get ();
545+ assertEquals (1 , healthNodeResponse .getHealthInfo ().fileSettingsHealthInfo ().failureStreak ());
546+ });
530547 }
531548
532549 private void assertHasErrors (AtomicLong waitForMetadataVersion , String expectedError ) {
0 commit comments