@@ -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
+ .useAggregatedNodeLevelResponses (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
+ .useAggregatedNodeLevelResponses (randomBoolean ())
164
+ .get ();
157
165
assertCounts (response .getNodesStats ().getCounts (), total , expectedCounts );
158
166
159
167
Set <String > expectedRoles = Set .of (DiscoveryNodeRole .MASTER_ROLE .roleName ());
@@ -176,15 +184,60 @@ private void assertShardStats(ClusterStatsIndices.ShardStats stats, int indices,
176
184
assertThat (stats .getReplication (), Matchers .equalTo (replicationFactor ));
177
185
}
178
186
179
- public void testIndicesShardStats () throws ExecutionException , InterruptedException {
187
+ public void testIndicesShardStatsWithoutNodeLevelAggregations () {
188
+ internalCluster ().startNode ();
189
+ ensureGreen ();
190
+ ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses (false ).get ();
191
+ assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
192
+
193
+ prepareCreate ("test1" ).setSettings (Settings .builder ().put ("number_of_shards" , 2 ).put ("number_of_replicas" , 1 )).get ();
194
+
195
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses (false ).get ();
196
+ assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .YELLOW ));
197
+ assertThat (response .indicesStats .getDocs ().getCount (), Matchers .equalTo (0L ));
198
+ assertThat (response .indicesStats .getIndexCount (), Matchers .equalTo (1 ));
199
+ assertShardStats (response .getIndicesStats ().getShards (), 1 , 2 , 2 , 0.0 );
200
+
201
+ // add another node, replicas should get assigned
202
+ internalCluster ().startNode ();
203
+ ensureGreen ();
204
+ index ("test1" , "type" , "1" , "f" , "f" );
205
+ refresh (); // make the doc visible
206
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses (false ).get ();
207
+ assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
208
+ assertThat (response .indicesStats .getDocs ().getCount (), Matchers .equalTo (1L ));
209
+ assertShardStats (response .getIndicesStats ().getShards (), 1 , 4 , 2 , 1.0 );
210
+
211
+ prepareCreate ("test2" ).setSettings (Settings .builder ().put ("number_of_shards" , 3 ).put ("number_of_replicas" , 0 )).get ();
212
+ ensureGreen ();
213
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses (false ).get ();
214
+ assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
215
+ assertThat (response .indicesStats .getIndexCount (), Matchers .equalTo (2 ));
216
+ assertShardStats (response .getIndicesStats ().getShards (), 2 , 7 , 5 , 2.0 / 5 );
217
+
218
+ assertThat (response .getIndicesStats ().getShards ().getAvgIndexPrimaryShards (), Matchers .equalTo (2.5 ));
219
+ assertThat (response .getIndicesStats ().getShards ().getMinIndexPrimaryShards (), Matchers .equalTo (2 ));
220
+ assertThat (response .getIndicesStats ().getShards ().getMaxIndexPrimaryShards (), Matchers .equalTo (3 ));
221
+
222
+ assertThat (response .getIndicesStats ().getShards ().getAvgIndexShards (), Matchers .equalTo (3.5 ));
223
+ assertThat (response .getIndicesStats ().getShards ().getMinIndexShards (), Matchers .equalTo (3 ));
224
+ assertThat (response .getIndicesStats ().getShards ().getMaxIndexShards (), Matchers .equalTo (4 ));
225
+
226
+ assertThat (response .getIndicesStats ().getShards ().getAvgIndexReplication (), Matchers .equalTo (0.5 ));
227
+ assertThat (response .getIndicesStats ().getShards ().getMinIndexReplication (), Matchers .equalTo (0.0 ));
228
+ assertThat (response .getIndicesStats ().getShards ().getMaxIndexReplication (), Matchers .equalTo (1.0 ));
229
+
230
+ }
231
+
232
+ public void testIndicesShardStatsWithNodeLevelAggregations () {
180
233
internalCluster ().startNode ();
181
234
ensureGreen ();
182
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
235
+ ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses ( true ). get ();
183
236
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
184
237
185
238
prepareCreate ("test1" ).setSettings (Settings .builder ().put ("number_of_shards" , 2 ).put ("number_of_replicas" , 1 )).get ();
186
239
187
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
240
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses ( true ). get ();
188
241
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .YELLOW ));
189
242
assertThat (response .indicesStats .getDocs ().getCount (), Matchers .equalTo (0L ));
190
243
assertThat (response .indicesStats .getIndexCount (), Matchers .equalTo (1 ));
@@ -195,14 +248,14 @@ public void testIndicesShardStats() throws ExecutionException, InterruptedExcept
195
248
ensureGreen ();
196
249
index ("test1" , "type" , "1" , "f" , "f" );
197
250
refresh (); // make the doc visible
198
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
251
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses ( true ). get ();
199
252
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
200
253
assertThat (response .indicesStats .getDocs ().getCount (), Matchers .equalTo (1L ));
201
254
assertShardStats (response .getIndicesStats ().getShards (), 1 , 4 , 2 , 1.0 );
202
255
203
256
prepareCreate ("test2" ).setSettings (Settings .builder ().put ("number_of_shards" , 3 ).put ("number_of_replicas" , 0 )).get ();
204
257
ensureGreen ();
205
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
258
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses ( true ). get ();
206
259
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
207
260
assertThat (response .indicesStats .getIndexCount (), Matchers .equalTo (2 ));
208
261
assertShardStats (response .getIndicesStats ().getShards (), 2 , 7 , 5 , 2.0 / 5 );
@@ -225,7 +278,11 @@ public void testValuesSmokeScreen() throws IOException, ExecutionException, Inte
225
278
internalCluster ().startNodes (randomIntBetween (1 , 3 ));
226
279
index ("test1" , "type" , "1" , "f" , "f" );
227
280
228
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
281
+ ClusterStatsResponse response = client ().admin ()
282
+ .cluster ()
283
+ .prepareClusterStats ()
284
+ .useAggregatedNodeLevelResponses (randomBoolean ())
285
+ .get ();
229
286
String msg = response .toString ();
230
287
assertThat (msg , response .getTimestamp (), Matchers .greaterThan (946681200000L )); // 1 Jan 2000
231
288
assertThat (msg , response .indicesStats .getStore ().getSizeInBytes (), Matchers .greaterThan (0L ));
@@ -265,13 +322,21 @@ public void testAllocatedProcessors() throws Exception {
265
322
internalCluster ().startNode (Settings .builder ().put (OpenSearchExecutors .NODE_PROCESSORS_SETTING .getKey (), 7 ).build ());
266
323
waitForNodes (1 );
267
324
268
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
325
+ ClusterStatsResponse response = client ().admin ()
326
+ .cluster ()
327
+ .prepareClusterStats ()
328
+ .useAggregatedNodeLevelResponses (randomBoolean ())
329
+ .get ();
269
330
assertThat (response .getNodesStats ().getOs ().getAllocatedProcessors (), equalTo (7 ));
270
331
}
271
332
272
333
public void testClusterStatusWhenStateNotRecovered () throws Exception {
273
334
internalCluster ().startClusterManagerOnlyNode (Settings .builder ().put ("gateway.recover_after_nodes" , 2 ).build ());
274
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
335
+ ClusterStatsResponse response = client ().admin ()
336
+ .cluster ()
337
+ .prepareClusterStats ()
338
+ .useAggregatedNodeLevelResponses (randomBoolean ())
339
+ .get ();
275
340
assertThat (response .getStatus (), equalTo (ClusterHealthStatus .RED ));
276
341
277
342
if (randomBoolean ()) {
@@ -281,14 +346,18 @@ public void testClusterStatusWhenStateNotRecovered() throws Exception {
281
346
}
282
347
// wait for the cluster status to settle
283
348
ensureGreen ();
284
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
349
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses ( randomBoolean ()). get ();
285
350
assertThat (response .getStatus (), equalTo (ClusterHealthStatus .GREEN ));
286
351
}
287
352
288
353
public void testFieldTypes () {
289
354
internalCluster ().startNode ();
290
355
ensureGreen ();
291
- ClusterStatsResponse response = client ().admin ().cluster ().prepareClusterStats ().get ();
356
+ ClusterStatsResponse response = client ().admin ()
357
+ .cluster ()
358
+ .prepareClusterStats ()
359
+ .useAggregatedNodeLevelResponses (randomBoolean ())
360
+ .get ();
292
361
assertThat (response .getStatus (), Matchers .equalTo (ClusterHealthStatus .GREEN ));
293
362
assertTrue (response .getIndicesStats ().getMappings ().getFieldTypeStats ().isEmpty ());
294
363
@@ -301,7 +370,7 @@ public void testFieldTypes() {
301
370
+ "\" eggplant\" :{\" type\" :\" integer\" }}}}}"
302
371
)
303
372
.get ();
304
- response = client ().admin ().cluster ().prepareClusterStats ().get ();
373
+ response = client ().admin ().cluster ().prepareClusterStats ().useAggregatedNodeLevelResponses ( randomBoolean ()). get ();
305
374
assertThat (response .getIndicesStats ().getMappings ().getFieldTypeStats ().size (), equalTo (3 ));
306
375
Set <IndexFeatureStats > stats = response .getIndicesStats ().getMappings ().getFieldTypeStats ();
307
376
for (IndexFeatureStats stat : stats ) {
@@ -329,7 +398,11 @@ public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, I
329
398
Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 1 , 0 , 0 );
330
399
331
400
Client client = client ();
332
- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
401
+ ClusterStatsResponse clusterStatsResponse = client .admin ()
402
+ .cluster ()
403
+ .prepareClusterStats ()
404
+ .useAggregatedNodeLevelResponses (randomBoolean ())
405
+ .get ();
333
406
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedCounts );
334
407
335
408
Set <String > expectedRoles = Set .of (
@@ -359,7 +432,11 @@ public void testNodeRolesWithClusterManagerRole() throws ExecutionException, Int
359
432
Map <String , Integer > expectedCounts = getExpectedCounts (0 , 1 , 1 , 0 , 1 , 0 , 0 );
360
433
361
434
Client client = client ();
362
- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
435
+ ClusterStatsResponse clusterStatsResponse = client .admin ()
436
+ .cluster ()
437
+ .prepareClusterStats ()
438
+ .useAggregatedNodeLevelResponses (randomBoolean ())
439
+ .get ();
363
440
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedCounts );
364
441
365
442
Set <String > expectedRoles = Set .of (
@@ -383,7 +460,11 @@ public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionExcept
383
460
Map <String , Integer > expectedRoleCounts = getExpectedCounts (1 , 1 , 1 , 0 , 1 , 0 , 0 );
384
461
385
462
Client client = client ();
386
- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
463
+ ClusterStatsResponse clusterStatsResponse = client .admin ()
464
+ .cluster ()
465
+ .prepareClusterStats ()
466
+ .useAggregatedNodeLevelResponses (randomBoolean ())
467
+ .get ();
387
468
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedRoleCounts );
388
469
389
470
Set <String > expectedRoles = Set .of (
@@ -410,7 +491,11 @@ public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException,
410
491
Map <String , Integer > expectedRoleCounts = getExpectedCounts (1 , 1 , 1 , 0 , 1 , 0 , 0 );
411
492
412
493
Client client = client ();
413
- ClusterStatsResponse clusterStatsResponse = client .admin ().cluster ().prepareClusterStats ().get ();
494
+ ClusterStatsResponse clusterStatsResponse = client .admin ()
495
+ .cluster ()
496
+ .prepareClusterStats ()
497
+ .useAggregatedNodeLevelResponses (randomBoolean ())
498
+ .get ();
414
499
assertCounts (clusterStatsResponse .getNodesStats ().getCounts (), total , expectedRoleCounts );
415
500
416
501
Set <Set <String >> expectedNodesRoles = Set .of (
0 commit comments