2424import org .elasticsearch .cluster .EstimatedHeapUsage ;
2525import org .elasticsearch .cluster .EstimatedHeapUsageCollector ;
2626import org .elasticsearch .cluster .InternalClusterInfoService ;
27- import org .elasticsearch .cluster .NodeWriteLoad ;
28- import org .elasticsearch .cluster .WriteLoadCollector ;
27+ import org .elasticsearch .cluster .NodeExecutionLoad ;
28+ import org .elasticsearch .cluster .NodeUsageLoadCollector ;
2929import org .elasticsearch .cluster .metadata .IndexMetadata ;
3030import org .elasticsearch .cluster .node .DiscoveryNode ;
3131import org .elasticsearch .cluster .node .DiscoveryNodeUtils ;
7878import org .elasticsearch .test .ESSingleNodeTestCase ;
7979import org .elasticsearch .test .IndexSettingsModule ;
8080import org .elasticsearch .test .InternalSettingsPlugin ;
81+ import org .elasticsearch .threadpool .ThreadPool ;
8182import org .elasticsearch .xcontent .XContentType ;
8283import org .junit .Assert ;
8384
9091import java .util .Arrays ;
9192import java .util .Collection ;
9293import java .util .Collections ;
94+ import java .util .HashMap ;
9395import java .util .List ;
9496import java .util .Locale ;
9597import java .util .Map ;
@@ -131,7 +133,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
131133
132134 @ Override
133135 protected Collection <Class <? extends Plugin >> getPlugins () {
134- return pluginList (InternalSettingsPlugin .class , BogusEstimatedHeapUsagePlugin .class , BogusWriteLoadCollectorPlugin .class );
136+ return pluginList (InternalSettingsPlugin .class , BogusEstimatedHeapUsagePlugin .class , BogusNodeUsageLoadCollectorPlugin .class );
135137 }
136138
137139 public void testLockTryingToDelete () throws Exception {
@@ -305,11 +307,11 @@ public void testHeapUsageEstimateIsPresent() {
305307 public void testNodeWriteLoadsArePresent () {
306308 InternalClusterInfoService clusterInfoService = (InternalClusterInfoService ) getInstanceFromNode (ClusterInfoService .class );
307309 ClusterInfoServiceUtils .refresh (clusterInfoService );
308- Map <String , NodeWriteLoad > nodeWriteLoads = clusterInfoService .getClusterInfo ().getNodeWriteLoads ();
309- assertNotNull (nodeWriteLoads );
310+ Map <String , NodeExecutionLoad > nodeThreadPoolStats = clusterInfoService .getClusterInfo ().getNodeExecutionStats ();
311+ assertNotNull (nodeThreadPoolStats );
310312 /** Not collecting stats yet because allocation write load stats collection is disabled by default.
311313 * see {@link WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING} */
312- assertTrue (nodeWriteLoads .isEmpty ());
314+ assertTrue (nodeThreadPoolStats .isEmpty ());
313315
314316 // Enable collection for node write loads.
315317 updateClusterSettings (
@@ -323,18 +325,21 @@ public void testNodeWriteLoadsArePresent() {
323325 try {
324326 // Force a ClusterInfo refresh to run collection of the node write loads.
325327 ClusterInfoServiceUtils .refresh (clusterInfoService );
326- nodeWriteLoads = clusterInfoService .getClusterInfo ().getNodeWriteLoads ();
328+ nodeThreadPoolStats = clusterInfoService .getClusterInfo ().getNodeExecutionStats ();
327329
328- /** Verify that each node has a write load reported. The test {@link BogusWriteLoadCollector } generates random load values */
330+ /** Verify that each node has a write load reported. The test {@link BogusNodeUsageLoadCollector } generates random load values */
329331 ClusterState state = getInstanceFromNode (ClusterService .class ).state ();
330- assertEquals (state .nodes ().size (), nodeWriteLoads .size ());
332+ assertEquals (state .nodes ().size (), nodeThreadPoolStats .size ());
331333 for (DiscoveryNode node : state .nodes ()) {
332- assertTrue (nodeWriteLoads .containsKey (node .getId ()));
333- NodeWriteLoad nodeWriteLoad = nodeWriteLoads .get (node .getId ());
334- assertThat (nodeWriteLoad .nodeId (), equalTo (node .getId ()));
335- assertThat (nodeWriteLoad .totalWriteThreadPoolThreads (), greaterThanOrEqualTo (0 ));
336- assertThat (nodeWriteLoad .averageWriteThreadPoolUtilization (), greaterThanOrEqualTo (0.0f ));
337- assertThat (nodeWriteLoad .averageWriteThreadPoolQueueLatencyMillis (), greaterThanOrEqualTo (0L ));
334+ assertTrue (nodeThreadPoolStats .containsKey (node .getId ()));
335+ NodeExecutionLoad nodeExecutionLoad = nodeThreadPoolStats .get (node .getId ());
336+ assertThat (nodeExecutionLoad .nodeId (), equalTo (node .getId ()));
337+ NodeExecutionLoad .ThreadPoolUsageStats writeThreadPoolStats = nodeExecutionLoad .threadPoolUsageStatsMap ()
338+ .get (ThreadPool .Names .WRITE );
339+ assertNotNull (writeThreadPoolStats );
340+ assertThat (writeThreadPoolStats .totalThreadPoolThreads (), greaterThanOrEqualTo (0 ));
341+ assertThat (writeThreadPoolStats .averageThreadPoolUtilization (), greaterThanOrEqualTo (0.0f ));
342+ assertThat (writeThreadPoolStats .averageThreadPoolQueueLatencyMillis (), greaterThanOrEqualTo (0L ));
338343 }
339344 } finally {
340345 updateClusterSettings (
@@ -925,42 +930,48 @@ public ClusterService getClusterService() {
925930 }
926931
927932 /**
928- * A simple {@link WriteLoadCollector } implementation that creates and returns random {@link NodeWriteLoad } for each node in the
933+ * A simple {@link NodeUsageLoadCollector } implementation that creates and returns random {@link NodeExecutionLoad } for each node in the
929934 * cluster.
930935 * <p>
931936 * Note: there's an 'org.elasticsearch.cluster.WriteLoadCollector' file that declares this implementation so that the plugin system can
932937 * pick it up and use it for the test set-up.
933938 */
934- public static class BogusWriteLoadCollector implements WriteLoadCollector {
939+ public static class BogusNodeUsageLoadCollector implements NodeUsageLoadCollector {
935940
936- private final BogusWriteLoadCollectorPlugin plugin ;
941+ private final BogusNodeUsageLoadCollectorPlugin plugin ;
937942
938- public BogusWriteLoadCollector ( BogusWriteLoadCollectorPlugin plugin ) {
943+ public BogusNodeUsageLoadCollector ( BogusNodeUsageLoadCollectorPlugin plugin ) {
939944 this .plugin = plugin ;
940945 }
941946
942947 @ Override
943- public void collectWriteLoads (ActionListener <Map <String , NodeWriteLoad >> listener ) {
948+ public void collectUsageStats (ActionListener <Map <String , NodeExecutionLoad >> listener ) {
944949 ActionListener .completeWith (
945950 listener ,
946951 () -> plugin .getClusterService ()
947952 .state ()
948953 .nodes ()
949954 .stream ()
950- .collect (
951- Collectors .toUnmodifiableMap (
952- DiscoveryNode ::getId ,
953- node -> new NodeWriteLoad (node .getId (), randomNonNegativeInt (), randomNonNegativeInt (), randomNonNegativeLong ())
954- )
955- )
955+ .collect (Collectors .toUnmodifiableMap (DiscoveryNode ::getId , node -> makeRandomNodeLoad (node .getId ())))
956+ );
957+ }
958+
959+ private NodeExecutionLoad makeRandomNodeLoad (String nodeId ) {
960+ NodeExecutionLoad .ThreadPoolUsageStats writeThreadPoolStats = new NodeExecutionLoad .ThreadPoolUsageStats (
961+ randomNonNegativeInt (),
962+ randomFloat (),
963+ randomNonNegativeLong ()
956964 );
965+ Map <String , NodeExecutionLoad .ThreadPoolUsageStats > statsForThreadPools = new HashMap <>();
966+ statsForThreadPools .put (ThreadPool .Names .WRITE , writeThreadPoolStats );
967+ return new NodeExecutionLoad (nodeId , statsForThreadPools );
957968 }
958969 }
959970
960971 /**
961972 * Make a plugin to gain access to the {@link ClusterService} instance.
962973 */
963- public static class BogusWriteLoadCollectorPlugin extends Plugin implements ClusterPlugin {
974+ public static class BogusNodeUsageLoadCollectorPlugin extends Plugin implements ClusterPlugin {
964975
965976 private final SetOnce <ClusterService > clusterService = new SetOnce <>();
966977
0 commit comments