@@ -88,7 +88,11 @@ public void testNodeCounts() {
88
88
Map <String , Integer > expectedCounts = getExpectedCounts (1 , 1 , 1 , 1 , 1 , 0 , 0 );
89
89
int numNodes = randomIntBetween (1 , 5 );
90
90
91
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
91
+ ClusterStatsResponse response = client ().admin ()
92
+ .cluster ()
93
+ .prepareClusterStats ()
94
+ .useOptimizedClusterStatsResponse (randomBoolean ())
95
+ .get ();
92
96
assertCounts (response .getNodesStats ().getCounts (), total , expectedCounts );
93
97
94
98
for (int i = 0 ; i < numNodes ; i ++) {
@@ -153,7 +157,11 @@ public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException,
153
157
Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 0 , 0 , 0 );
154
158
155
159
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 ();
157
165
assertCounts (response .getNodesStats ().getCounts (), total , expectedCounts );
158
166
159
167
Set <String > expectedRoles = Set .of (DiscoveryNodeRole .MASTER_ROLE .roleName ());
@@ -179,7 +187,11 @@ private void assertShardStats(ClusterStatsIndices.ShardStats stats, int indices,
179
187
public void testIndicesShardStats () throws ExecutionException , InterruptedException {
180
188
internalCluster ().startNode ();
181
189
ensureGreen ();
182
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
190
+ ClusterStatsResponse response = client ().admin ()
191
+ .cluster ()
192
+ .prepareClusterStats ()
193
+ .useOptimizedClusterStatsResponse (randomBoolean ())
194
+ .get ();
183
195
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
184
196
185
197
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
195
207
ensureGreen ();
196
208
index ("test1" , "type" , "1" , "f" , "f" );
197
209
refresh (); // make the doc visible
198
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
210
+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
199
211
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
200
212
assertThat (response .indicesStats .getDocs ().getCount (), Matchers .equalTo (1L ));
201
213
assertShardStats (response .getIndicesStats ().getShards (), 1 , 4 , 2 , 1.0 );
202
214
203
215
prepareCreate ("test2" ).setSettings (Settings .builder ().put ("number_of_shards" , 3 ).put ("number_of_replicas" , 0 )).get ();
204
216
ensureGreen ();
205
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
217
+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
206
218
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
207
219
assertThat (response .indicesStats .getIndexCount (), Matchers .equalTo (2 ));
208
220
assertShardStats (response .getIndicesStats ().getShards (), 2 , 7 , 5 , 2.0 / 5 );
@@ -225,7 +237,11 @@ public void testValuesSmokeScreen() throws IOException, ExecutionException, Inte
225
237
internalCluster ().startNodes (randomIntBetween (1 , 3 ));
226
238
index ("test1" , "type" , "1" , "f" , "f" );
227
239
228
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
240
+ ClusterStatsResponse response = client ().admin ()
241
+ .cluster ()
242
+ .prepareClusterStats ()
243
+ .useOptimizedClusterStatsResponse (randomBoolean ())
244
+ .get ();
229
245
String msg = response .toString ();
230
246
assertThat (msg , response .getTimestamp (), Matchers .greaterThan (946681200000L )); // 1 Jan 2000
231
247
assertThat (msg , response .indicesStats .getStore ().getSizeInBytes (), Matchers .greaterThan (0L ));
@@ -265,13 +281,21 @@ public void testAllocatedProcessors() throws Exception {
265
281
internalCluster ().startNode (Settings .builder ().put (OpenSearchExecutors .NODE_PROCESSORS_SETTING .getKey (), 7 ).build ());
266
282
waitForNodes (1 );
267
283
268
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
284
+ ClusterStatsResponse response = client ().admin ()
285
+ .cluster ()
286
+ .prepareClusterStats ()
287
+ .useOptimizedClusterStatsResponse (randomBoolean ())
288
+ .get ();
269
289
assertThat (response .getNodesStats ().getOs ().getAllocatedProcessors (), equalTo (7 ));
270
290
}
271
291
272
292
public void testClusterStatusWhenStateNotRecovered () throws Exception {
273
293
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 ();
275
299
assertThat (response .getStatus (), equalTo (ClusterHealthStatus .RED ));
276
300
277
301
if (randomBoolean ()) {
@@ -281,14 +305,18 @@ public void testClusterStatusWhenStateNotRecovered() throws Exception {
281
305
}
282
306
// wait for the cluster status to settle
283
307
ensureGreen ();
284
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
308
+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
285
309
assertThat (response .getStatus (), equalTo (ClusterHealthStatus .GREEN ));
286
310
}
287
311
288
312
public void testFieldTypes () {
289
313
internalCluster ().startNode ();
290
314
ensureGreen ();
291
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
315
+ ClusterStatsResponse response = client ().admin ()
316
+ .cluster ()
317
+ .prepareClusterStats ()
318
+ .useOptimizedClusterStatsResponse (randomBoolean ())
319
+ .get ();
292
320
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
293
321
assertTrue (response .getIndicesStats ().getMappings ().getFieldTypeStats ().isEmpty ());
294
322
@@ -301,7 +329,7 @@ public void testFieldTypes() {
301
329
+ "\" eggplant\" :{\" type\" :\" integer\" }}}}}"
302
330
)
303
331
.get ();
304
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
332
+ response = client ().admin ().cluster ().prepareClusterStats ().useOptimizedClusterStatsResponse ( randomBoolean ()). get ();
305
333
assertThat (response .getIndicesStats ().getMappings ().getFieldTypeStats ().size (), equalTo (3 ));
306
334
Set <IndexFeatureStats > stats = response .getIndicesStats ().getMappings ().getFieldTypeStats ();
307
335
for (IndexFeatureStats stat : stats ) {
@@ -329,7 +357,11 @@ public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, I
329
357
Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 1 , 0 , 0 );
330
358
331
359
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 ();
333
365
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedCounts );
334
366
335
367
Set <String > expectedRoles = Set .of (
@@ -359,7 +391,11 @@ public void testNodeRolesWithClusterManagerRole() throws ExecutionException, Int
359
391
Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 1 , 0 , 0 );
360
392
361
393
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 ();
363
399
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedCounts );
364
400
365
401
Set <String > expectedRoles = Set .of (
@@ -383,7 +419,11 @@ public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionExcept
383
419
Map <String , Integer > expectedRoleCounts = getExpectedCounts (1 , 1 , 1 , 0 , 1 , 0 , 0 );
384
420
385
421
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 ();
387
427
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedRoleCounts );
388
428
389
429
Set <String > expectedRoles = Set .of (
@@ -410,7 +450,11 @@ public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException,
410
450
Map <String , Integer > expectedRoleCounts = getExpectedCounts (1 , 1 , 1 , 0 , 1 , 0 , 0 );
411
451
412
452
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 ();
414
458
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedRoleCounts );
415
459
416
460
Set <Set <String >> expectedNodesRoles = Set .of (
0 commit comments