@@ -305,6 +305,9 @@ public void testHeapUsageEstimateIsPresent() {
305
305
}
306
306
307
307
public void testNodeWriteLoadsArePresent () {
308
+ // Disable write load decider to begin with
309
+ setWriteLoadDeciderEnablement (WriteLoadConstraintSettings .WriteLoadDeciderStatus .DISABLED );
310
+
308
311
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService ) getInstanceFromNode (ClusterInfoService .class );
309
312
ClusterInfoServiceUtils .refresh (clusterInfoService );
310
313
Map <String , NodeUsageStatsForThreadPools > nodeThreadPoolStats = clusterInfoService .getClusterInfo ()
@@ -315,15 +318,10 @@ public void testNodeWriteLoadsArePresent() {
315
318
assertTrue (nodeThreadPoolStats .isEmpty ());
316
319
317
320
// Enable collection for node write loads.
318
- updateClusterSettings (
319
- Settings .builder ()
320
- .put (
321
- WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey (),
322
- randomBoolean ()
323
- ? WriteLoadConstraintSettings .WriteLoadDeciderStatus .ENABLED
324
- : WriteLoadConstraintSettings .WriteLoadDeciderStatus .LOW_THRESHOLD_ONLY
325
- )
326
- .build ()
321
+ setWriteLoadDeciderEnablement (
322
+ randomBoolean ()
323
+ ? WriteLoadConstraintSettings .WriteLoadDeciderStatus .ENABLED
324
+ : WriteLoadConstraintSettings .WriteLoadDeciderStatus .LOW_THRESHOLD_ONLY
327
325
);
328
326
try {
329
327
// Force a ClusterInfo refresh to run collection of the node thread pool usage stats.
@@ -346,9 +344,7 @@ public void testNodeWriteLoadsArePresent() {
346
344
assertThat (writeThreadPoolStats .maxThreadPoolQueueLatencyMillis (), greaterThanOrEqualTo (0L ));
347
345
}
348
346
} finally {
349
- updateClusterSettings (
350
- Settings .builder ().putNull (WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey ()).build ()
351
- );
347
+ clearWriteLoadDeciderEnablementSetting ();
352
348
}
353
349
}
354
350
@@ -365,27 +361,25 @@ public void testShardWriteLoadsArePresent() {
365
361
366
362
final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService ) getInstanceFromNode (ClusterInfoService .class );
367
363
368
- // Not collecting stats yet because allocation write load stats collection is disabled by default.
369
- {
370
- ClusterInfoServiceUtils .refresh (clusterInfoService );
371
- final Map <ShardId , Double > shardWriteLoads = clusterInfoService .getClusterInfo ().getShardWriteLoads ();
372
- assertNotNull (shardWriteLoads );
373
- assertTrue (shardWriteLoads .isEmpty ());
374
- }
375
-
376
- // Turn on collection of write-load stats.
377
- updateClusterSettings (
378
- Settings .builder ()
379
- .put (
380
- WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey (),
381
- randomBoolean ()
382
- ? WriteLoadConstraintSettings .WriteLoadDeciderStatus .ENABLED
383
- : WriteLoadConstraintSettings .WriteLoadDeciderStatus .LOW_THRESHOLD_ONLY
384
- )
385
- .build ()
386
- );
364
+ // Explicitly disable write load decider
365
+ setWriteLoadDeciderEnablement (WriteLoadConstraintSettings .WriteLoadDeciderStatus .DISABLED );
387
366
388
367
try {
368
+ // Stats should not be collected when the decider is disabled
369
+ {
370
+ ClusterInfoServiceUtils .refresh (clusterInfoService );
371
+ final Map <ShardId , Double > shardWriteLoads = clusterInfoService .getClusterInfo ().getShardWriteLoads ();
372
+ assertNotNull (shardWriteLoads );
373
+ assertTrue (shardWriteLoads .isEmpty ());
374
+ }
375
+
376
+ // Turn on collection of write-load stats.
377
+ setWriteLoadDeciderEnablement (
378
+ randomBoolean ()
379
+ ? WriteLoadConstraintSettings .WriteLoadDeciderStatus .ENABLED
380
+ : WriteLoadConstraintSettings .WriteLoadDeciderStatus .LOW_THRESHOLD_ONLY
381
+ );
382
+
389
383
// Force a ClusterInfo refresh to run collection of the write-load stats.
390
384
ClusterInfoServiceUtils .refresh (clusterInfoService );
391
385
final Map <ShardId , Double > shardWriteLoads = clusterInfoService .getClusterInfo ().getShardWriteLoads ();
@@ -404,12 +398,14 @@ public void testShardWriteLoadsArePresent() {
404
398
assertThat (maximumLoadRecorded , greaterThan (0.0 ));
405
399
}
406
400
} finally {
407
- updateClusterSettings (
408
- Settings .builder ().putNull (WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey ()).build ()
409
- );
401
+ clearWriteLoadDeciderEnablementSetting ();
410
402
}
411
403
}
412
404
405
+ private void clearWriteLoadDeciderEnablementSetting () {
406
+ updateClusterSettings (Settings .builder ().putNull (WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey ()).build ());
407
+ }
408
+
413
409
public void testMaxHeapPerNodeIsPresent () {
414
410
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService ) getInstanceFromNode (ClusterInfoService .class );
415
411
ClusterInfoServiceUtils .refresh (clusterInfoService );
@@ -764,6 +760,12 @@ public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResul
764
760
}
765
761
}
766
762
763
+ private void setWriteLoadDeciderEnablement (WriteLoadConstraintSettings .WriteLoadDeciderStatus status ) {
764
+ updateClusterSettings (
765
+ Settings .builder ().put (WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_ENABLED_SETTING .getKey (), status ).build ()
766
+ );
767
+ }
768
+
767
769
public static final IndexShard recoverShard (IndexShard newShard ) throws IOException {
768
770
DiscoveryNode localNode = DiscoveryNodeUtils .builder ("foo" ).roles (emptySet ()).build ();
769
771
newShard .markAsRecovering ("store" , new RecoveryState (newShard .routingEntry (), localNode , null ));
0 commit comments