@@ -88,7 +88,11 @@ public void testNodeCounts() {
8888 Map <String , Integer > expectedCounts = getExpectedCounts (1 , 1 , 1 , 1 , 1 , 0 , 0 );
8989 int numNodes = randomIntBetween (1 , 5 );
9090
91- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
91+ ClusterStatsResponse response = client ().admin ()
92+ .cluster ()
93+ .prepareClusterStats ()
94+ .useOptimizedClusterStatsResponse (randomBoolean ())
95+ .get ();
9296 assertCounts (response .getNodesStats ().getCounts (), total , expectedCounts );
9397
9498 for (int i = 0 ; i < numNodes ; i ++) {
@@ -153,7 +157,11 @@ public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException,
153157 Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 0 , 0 , 0 );
154158
155159 Client client = client ();
156- ClusterStatsResponse response = client .admin ().cluster ().prepareClusterStats ().get ();
160+ ClusterStatsResponse response = client .admin ()
161+ .cluster ()
162+ .prepareClusterStats ()
163+ .useOptimizedClusterStatsResponse (randomBoolean ())
164+ .get ();
157165 assertCounts (response .getNodesStats ().getCounts (), total , expectedCounts );
158166
159167 Set <String > expectedRoles = Set .of (DiscoveryNodeRole .MASTER_ROLE .roleName ());
@@ -179,7 +187,11 @@ private void assertShardStats(ClusterStatsIndices.ShardStats stats, int indices,
179187 public void testIndicesShardStats () throws ExecutionException , InterruptedException {
180188 internalCluster ().startNode ();
181189 ensureGreen ();
182- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
190+ ClusterStatsResponse response = client ().admin ()
191+ .cluster ()
192+ .prepareClusterStats ()
193+ .useOptimizedClusterStatsResponse (randomBoolean ())
194+ .get ();
183195 assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
184196
185197 prepareCreate ("test1" ).setSettings (Settings .builder ().put ("number_of_shards" , 2 ).put ("number_of_replicas" , 1 )).get ();
@@ -195,14 +207,14 @@ public void testIndicesShardStats() throws ExecutionException, InterruptedExcept
195207 ensureGreen ();
196208 index ("test1" , "type" , "1" , "f" , "f" );
197209 refresh (); // make the doc visible
198- response = client ().admin ().cluster ().prepareClusterStats ().get ();
210+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
199211 assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
200212 assertThat (response .indicesStats .getDocs ().getCount (), Matchers .equalTo (1L ));
201213 assertShardStats (response .getIndicesStats ().getShards (), 1 , 4 , 2 , 1.0 );
202214
203215 prepareCreate ("test2" ).setSettings (Settings .builder ().put ("number_of_shards" , 3 ).put ("number_of_replicas" , 0 )).get ();
204216 ensureGreen ();
205- response = client ().admin ().cluster ().prepareClusterStats ().get ();
217+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
206218 assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
207219 assertThat (response .indicesStats .getIndexCount (), Matchers .equalTo (2 ));
208220 assertShardStats (response .getIndicesStats ().getShards (), 2 , 7 , 5 , 2.0 / 5 );
@@ -225,7 +237,11 @@ public void testValuesSmokeScreen() throws IOException, ExecutionException, Inte
225237 internalCluster ().startNodes (randomIntBetween (1 , 3 ));
226238 index ("test1" , "type" , "1" , "f" , "f" );
227239
228- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
240+ ClusterStatsResponse response = client ().admin ()
241+ .cluster ()
242+ .prepareClusterStats ()
243+ .useOptimizedClusterStatsResponse (randomBoolean ())
244+ .get ();
229245 String msg = response .toString ();
230246 assertThat (msg , response .getTimestamp (), Matchers .greaterThan (946681200000L )); // 1 Jan 2000
231247 assertThat (msg , response .indicesStats .getStore ().getSizeInBytes (), Matchers .greaterThan (0L ));
@@ -265,13 +281,21 @@ public void testAllocatedProcessors() throws Exception {
265281 internalCluster ().startNode (Settings .builder ().put (OpenSearchExecutors .NODE_PROCESSORS_SETTING .getKey (), 7 ).build ());
266282 waitForNodes (1 );
267283
268- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
284+ ClusterStatsResponse response = client ().admin ()
285+ .cluster ()
286+ .prepareClusterStats ()
287+ .useOptimizedClusterStatsResponse (randomBoolean ())
288+ .get ();
269289 assertThat (response .getNodesStats ().getOs ().getAllocatedProcessors (), equalTo (7 ));
270290 }
271291
272292 public void testClusterStatusWhenStateNotRecovered () throws Exception {
273293 internalCluster ().startClusterManagerOnlyNode (Settings .builder ().put ("gateway.recover_after_nodes" , 2 ).build ());
274- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
294+ ClusterStatsResponse response = client ().admin ()
295+ .cluster ()
296+ .prepareClusterStats ()
297+ .useOptimizedClusterStatsResponse (randomBoolean ())
298+ .get ();
275299 assertThat (response .getStatus (), equalTo (ClusterHealthStatus .RED ));
276300
277301 if (randomBoolean ()) {
@@ -281,14 +305,18 @@ public void testClusterStatusWhenStateNotRecovered() throws Exception {
281305 }
282306 // wait for the cluster status to settle
283307 ensureGreen ();
284- response = client ().admin ().cluster ().prepareClusterStats ().get ();
308+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
285309 assertThat (response .getStatus (), equalTo (ClusterHealthStatus .GREEN ));
286310 }
287311
288312 public void testFieldTypes () {
289313 internalCluster ().startNode ();
290314 ensureGreen ();
291- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
315+ ClusterStatsResponse response = client ().admin ()
316+ .cluster ()
317+ .prepareClusterStats ()
318+ .useOptimizedClusterStatsResponse (randomBoolean ())
319+ .get ();
292320 assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
293321 assertTrue (response .getIndicesStats ().getMappings ().getFieldTypeStats ().isEmpty ());
294322
@@ -301,7 +329,7 @@ public void testFieldTypes() {
301329 + "\" eggplant\" :{\" type\" :\" integer\" }}}}}"
302330 )
303331 .get ();
304- response = client ().admin ().cluster ().prepareClusterStats ().get ();
332+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
305333 assertThat (response .getIndicesStats ().getMappings ().getFieldTypeStats ().size (), equalTo (3 ));
306334 Set <IndexFeatureStats > stats = response .getIndicesStats ().getMappings ().getFieldTypeStats ();
307335 for (IndexFeatureStats stat : stats ) {
@@ -329,7 +357,11 @@ public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, I
329357 Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 1 , 0 , 0 );
330358
331359 Client client = client ();
332- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
360+ ClusterStatsResponse clusterStatsResponse = client .admin ()
361+ .cluster ()
362+ .prepareClusterStats ()
363+ .useOptimizedClusterStatsResponse (randomBoolean ())
364+ .get ();
333365 assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedCounts );
334366
335367 Set <String > expectedRoles = Set .of (
@@ -359,7 +391,11 @@ public void testNodeRolesWithClusterManagerRole() throws ExecutionException, Int
359391 Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 1 , 0 , 0 );
360392
361393 Client client = client ();
362- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
394+ ClusterStatsResponse clusterStatsResponse = client .admin ()
395+ .cluster ()
396+ .prepareClusterStats ()
397+ .useOptimizedClusterStatsResponse (randomBoolean ())
398+ .get ();
363399 assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedCounts );
364400
365401 Set <String > expectedRoles = Set .of (
@@ -383,7 +419,11 @@ public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionExcept
383419 Map <String , Integer > expectedRoleCounts = getExpectedCounts (1 , 1 , 1 , 0 , 1 , 0 , 0 );
384420
385421 Client client = client ();
386- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
422+ ClusterStatsResponse clusterStatsResponse = client .admin ()
423+ .cluster ()
424+ .prepareClusterStats ()
425+ .useOptimizedClusterStatsResponse (randomBoolean ())
426+ .get ();
387427 assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedRoleCounts );
388428
389429 Set <String > expectedRoles = Set .of (
@@ -410,7 +450,11 @@ public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException,
410450 Map <String , Integer > expectedRoleCounts = getExpectedCounts (1 , 1 , 1 , 0 , 1 , 0 , 0 );
411451
412452 Client client = client ();
413- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
453+ ClusterStatsResponse clusterStatsResponse = client .admin ()
454+ .cluster ()
455+ .prepareClusterStats ()
456+ .useOptimizedClusterStatsResponse (randomBoolean ())
457+ .get ();
414458 assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedRoleCounts );
415459
416460 Set <Set <String >> expectedNodesRoles = Set .of (
0 commit comments