25
25
import org .elasticsearch .common .settings .Settings ;
26
26
import org .elasticsearch .core .Strings ;
27
27
import 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 ;
28
31
import org .elasticsearch .health .node .HealthInfoCache ;
32
+ import org .elasticsearch .health .node .selection .HealthNode ;
29
33
import org .elasticsearch .reservedstate .action .ReservedClusterSettingsAction ;
30
34
import org .elasticsearch .test .ESIntegTestCase ;
31
35
import org .junit .Before ;
47
51
import static org .hamcrest .Matchers .containsInAnyOrder ;
48
52
import static org .hamcrest .Matchers .containsString ;
49
53
import static org .hamcrest .Matchers .equalTo ;
54
+ import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
50
55
import static org .hamcrest .Matchers .hasSize ;
51
56
import static org .hamcrest .Matchers .is ;
57
+ import static org .hamcrest .Matchers .not ;
52
58
import static org .hamcrest .Matchers .notNullValue ;
53
59
import static org .hamcrest .Matchers .nullValue ;
54
60
@@ -501,23 +507,28 @@ public void testSettingsAppliedOnMasterReElection() throws Exception {
501
507
502
508
public void testHealthIndicator () throws Exception {
503
509
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" ));
510
512
511
513
logger .info ("--> start master node" );
512
514
final String masterNode = internalCluster ().startMasterOnlyNode (
513
515
Settings .builder ().put (INITIAL_STATE_TIMEOUT_SETTING .getKey (), "0s" ).build ()
514
516
);
515
517
FileSettingsService masterFileSettingsService = internalCluster ().getInstance (FileSettingsService .class , masterNode );
516
518
assertBusy (() -> assertTrue (masterFileSettingsService .watching ()));
519
+
517
520
ensureStableCluster (2 );
518
521
522
+ var healthNode = HealthNode .findHealthNode (clusterService ().state ()).getName ();
523
+
519
524
// 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
+ });
521
532
522
533
logger .info ("--> induce an error and wait for it to be processed" );
523
534
var savedClusterState = setupClusterStateListenerForError (masterNode );
@@ -526,7 +537,13 @@ public void testHealthIndicator() throws Exception {
526
537
assertTrue (awaitSuccessful );
527
538
528
539
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
+ });
530
547
}
531
548
532
549
private void assertHasErrors (AtomicLong waitForMetadataVersion , String expectedError ) {
0 commit comments