2424import org .elasticsearch .cluster .EstimatedHeapUsage ;
2525import org .elasticsearch .cluster .EstimatedHeapUsageCollector ;
2626import org .elasticsearch .cluster .InternalClusterInfoService ;
27- import org .elasticsearch .cluster .NodeUsageStatsForThreadPools ;
27+ import org .elasticsearch .cluster .ThreadPoolUsage ;
2828import org .elasticsearch .cluster .ThreadPoolUsageCollector ;
2929import org .elasticsearch .cluster .metadata .IndexMetadata ;
3030import org .elasticsearch .cluster .metadata .ProjectId ;
7979import org .elasticsearch .test .ESSingleNodeTestCase ;
8080import org .elasticsearch .test .IndexSettingsModule ;
8181import org .elasticsearch .test .InternalSettingsPlugin ;
82- import org .elasticsearch .threadpool .ThreadPool ;
8382import org .elasticsearch .xcontent .XContentType ;
8483import org .junit .Assert ;
8584
9291import java .util .Arrays ;
9392import java .util .Collection ;
9493import java .util .Collections ;
95- import java .util .HashMap ;
9694import java .util .List ;
9795import java .util .Locale ;
9896import java .util .Map ;
@@ -135,11 +133,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
135133
136134 @ Override
137135 protected Collection <Class <? extends Plugin >> getPlugins () {
138- return pluginList (
139- InternalSettingsPlugin .class ,
140- BogusEstimatedHeapUsagePlugin .class ,
141- BogusNodeUsageStatsForThreadPoolsCollectorPlugin .class
142- );
136+ return pluginList (InternalSettingsPlugin .class , BogusEstimatedHeapUsagePlugin .class , BogusNodeThreadPoolUsageCollectorPlugin .class );
143137 }
144138
145139 public void testLockTryingToDelete () throws Exception {
@@ -313,12 +307,11 @@ public void testHeapUsageEstimateIsPresent() {
313307 public void testNodeWriteLoadsArePresent () {
314308 InternalClusterInfoService clusterInfoService = (InternalClusterInfoService ) getInstanceFromNode (ClusterInfoService .class );
315309 ClusterInfoServiceUtils .refresh (clusterInfoService );
316- Map <String , NodeUsageStatsForThreadPools > nodeThreadPoolStats = clusterInfoService .getClusterInfo ()
317- .getNodeUsageStatsForThreadPools ();
318- assertNotNull (nodeThreadPoolStats );
310+ var writeThreadPoolUsages = clusterInfoService .getClusterInfo ().getWriteThreadPoolUsages ();
311+ assertNotNull (writeThreadPoolUsages );
319312 /** Not collecting stats yet because allocation write load stats collection is disabled by default.
320313 * see {@link WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING} */
321- assertTrue (nodeThreadPoolStats .isEmpty ());
314+ assertTrue (writeThreadPoolUsages .isEmpty ());
322315
323316 // Enable collection for node write loads.
324317 updateClusterSettings (
@@ -332,23 +325,20 @@ public void testNodeWriteLoadsArePresent() {
332325 try {
333326 // Force a ClusterInfo refresh to run collection of the node thread pool usage stats.
334327 ClusterInfoServiceUtils .refresh (clusterInfoService );
335- nodeThreadPoolStats = clusterInfoService .getClusterInfo ().getNodeUsageStatsForThreadPools ();
328+ writeThreadPoolUsages = clusterInfoService .getClusterInfo ().getWriteThreadPoolUsages ();
336329
337- /** Verify that each node has usage stats reported. The test {@link BogusThreadPoolUsageCollector } implementation
330+ /** Verify that each node has usage stats reported. The test {@link BogusNodeThreadPoolUsageCollector } implementation
338331 * generates random usage values */
339332 ClusterState state = getInstanceFromNode (ClusterService .class ).state ();
340- assertEquals (state .nodes ().size (), nodeThreadPoolStats .size ());
333+ assertEquals (state .nodes ().size (), writeThreadPoolUsages .size ());
341334 for (DiscoveryNode node : state .nodes ()) {
342- assertTrue (nodeThreadPoolStats .containsKey (node .getId ()));
343- NodeUsageStatsForThreadPools nodeUsageStatsForThreadPools = nodeThreadPoolStats .get (node .getId ());
344- assertThat (nodeUsageStatsForThreadPools .nodeId (), equalTo (node .getId ()));
345- NodeUsageStatsForThreadPools .ThreadPoolUsageStats writeThreadPoolStats = nodeUsageStatsForThreadPools
346- .threadPoolUsageStatsMap ()
347- .get (ThreadPool .Names .WRITE );
348- assertNotNull (writeThreadPoolStats );
349- assertThat (writeThreadPoolStats .totalThreadPoolThreads (), greaterThanOrEqualTo (0 ));
350- assertThat (writeThreadPoolStats .averageThreadPoolUtilization (), greaterThanOrEqualTo (0.0f ));
351- assertThat (writeThreadPoolStats .averageThreadPoolQueueLatencyMillis (), greaterThanOrEqualTo (0L ));
335+ assertTrue (writeThreadPoolUsages .containsKey (node .getId ()));
336+ var sample = writeThreadPoolUsages .get (node .getId ()).samples ().getFirst ();
337+ assertNotNull (sample );
338+ assertThat (sample .timeNano (), greaterThanOrEqualTo (0L ));
339+ assertThat (sample .totalThreads (), greaterThanOrEqualTo (0 ));
340+ assertThat (sample .averageUtilization (), greaterThanOrEqualTo (0.0f ));
341+ assertThat (sample .averageQueueLatency (), greaterThanOrEqualTo (0L ));
352342 }
353343 } finally {
354344 updateClusterSettings (
@@ -996,47 +986,45 @@ public ClusterService getClusterService() {
996986
997987 /**
998988 * A simple {@link ThreadPoolUsageCollector} implementation that creates and returns random
999- * {@link NodeUsageStatsForThreadPools } for each node in the cluster.
989+ * {@link ThreadPoolUsage } for each node in the cluster.
1000990 * <p>
1001991 * Note: there's an 'org.elasticsearch.cluster.NodeUsageStatsForThreadPoolsCollector' file that declares this implementation so that the
1002992 * plugin system can pick it up and use it for the test set-up.
1003993 */
1004- public static class BogusThreadPoolUsageCollector implements ThreadPoolUsageCollector {
994+ public static class BogusNodeThreadPoolUsageCollector implements ThreadPoolUsageCollector {
1005995
1006- private final BogusNodeUsageStatsForThreadPoolsCollectorPlugin plugin ;
996+ private final BogusNodeThreadPoolUsageCollectorPlugin plugin ;
1007997
1008- public BogusThreadPoolUsageCollector ( BogusNodeUsageStatsForThreadPoolsCollectorPlugin plugin ) {
998+ public BogusNodeThreadPoolUsageCollector ( BogusNodeThreadPoolUsageCollectorPlugin plugin ) {
1009999 this .plugin = plugin ;
10101000 }
10111001
10121002 @ Override
1013- public void collectUsageStats (ActionListener <Map <String , NodeUsageStatsForThreadPools >> listener ) {
1003+ public void collectUsageStats (String threadPoolName , ActionListener <Map <String , ThreadPoolUsage >> listener ) {
10141004 ActionListener .completeWith (
10151005 listener ,
10161006 () -> plugin .getClusterService ()
10171007 .state ()
10181008 .nodes ()
10191009 .stream ()
1020- .collect (Collectors .toUnmodifiableMap (DiscoveryNode ::getId , node -> makeRandomNodeUsageStats (node .getId ())))
1021- );
1022- }
1023-
1024- private NodeUsageStatsForThreadPools makeRandomNodeUsageStats (String nodeId ) {
1025- NodeUsageStatsForThreadPools .ThreadPoolUsageStats writeThreadPoolStats = new NodeUsageStatsForThreadPools .ThreadPoolUsageStats (
1026- randomNonNegativeInt (),
1027- randomFloat (),
1028- randomNonNegativeLong ()
1010+ .collect (
1011+ Collectors .toUnmodifiableMap (
1012+ DiscoveryNode ::getId ,
1013+ node -> new ThreadPoolUsage (
1014+ List .of (
1015+ new ThreadPoolUsage .Sample (randomNonNegativeLong (), randomInt (), randomFloat (), randomNonNegativeLong ())
1016+ )
1017+ )
1018+ )
1019+ )
10291020 );
1030- Map <String , NodeUsageStatsForThreadPools .ThreadPoolUsageStats > statsForThreadPools = new HashMap <>();
1031- statsForThreadPools .put (ThreadPool .Names .WRITE , writeThreadPoolStats );
1032- return new NodeUsageStatsForThreadPools (nodeId , statsForThreadPools );
10331021 }
10341022 }
10351023
10361024 /**
10371025 * Make a plugin to gain access to the {@link ClusterService} instance.
10381026 */
1039- public static class BogusNodeUsageStatsForThreadPoolsCollectorPlugin extends Plugin implements ClusterPlugin {
1027+ public static class BogusNodeThreadPoolUsageCollectorPlugin extends Plugin implements ClusterPlugin {
10401028
10411029 private final SetOnce <ClusterService > clusterService = new SetOnce <>();
10421030
0 commit comments