@@ -148,7 +148,7 @@ public void testCalculateValidations() {
148148 AutoShardingResult autoShardingResult = disabledAutoshardingService .calculate (
149149 state .projectState (projectId ),
150150 dataStream ,
151- createIndexStats (1 , 2 .0 , 9999.0 , 9999 .0 )
151+ createIndexStats (1 , 9999 .0 , 9999.0 , 2 .0 )
152152 );
153153 assertThat (autoShardingResult , is (NOT_APPLICABLE_RESULT ));
154154 }
@@ -182,7 +182,7 @@ public void testCalculateIncreaseShardingRecommendations_noPreviousShardingEvent
182182 AutoShardingResult autoShardingResult = service .calculate (
183183 state .projectState (projectId ),
184184 dataStream ,
185- createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
185+ createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
186186 );
187187 assertThat (autoShardingResult .type (), is (INCREASE_SHARDS ));
188188 // no pre-existing scaling event so the cool down must be zero
@@ -221,7 +221,7 @@ public void testCalculateIncreaseShardingRecommendations_preventedByCooldown() {
221221 AutoShardingResult autoShardingResult = service .calculate (
222222 state .projectState (projectId ),
223223 dataStream ,
224- createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
224+ createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
225225 );
226226 assertThat (autoShardingResult .type (), is (COOLDOWN_PREVENTED_INCREASE ));
227227 // no pre-existing scaling event so the cool down must be zero
@@ -259,7 +259,7 @@ public void testCalculateIncreaseShardingRecommendations_notPreventedByPreviousI
259259 AutoShardingResult autoShardingResult = service .calculate (
260260 state .projectState (projectId ),
261261 dataStream ,
262- createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
262+ createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
263263 );
264264 assertThat (autoShardingResult .type (), is (INCREASE_SHARDS ));
265265 // no pre-existing scaling event so the cool down must be zero
@@ -268,7 +268,7 @@ public void testCalculateIncreaseShardingRecommendations_notPreventedByPreviousI
268268 }
269269
270270 public void testCalculateIncreaseShardingRecommendations_usingRecentWriteLoad () {
271- // Repeated testCalculateIncreaseShardingRecommendations_noPreviousShardingEvent but with RECENT rather than ALL_TIME write load
271+ // Repeated testCalculateIncreaseShardingRecommendations_noPreviousShardingEvent but with RECENT rather than PEAK write load
272272 var projectId = randomProjectIdOrDefault ();
273273 ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
274274 DataStream dataStream = createDataStream (
@@ -299,8 +299,8 @@ public void testCalculateIncreaseShardingRecommendations_usingRecentWriteLoad()
299299 });
300300 }
301301
302- public void testCalculateIncreaseShardingRecommendations_usingPeakWriteLoad () {
303- // Repeated testCalculateIncreaseShardingRecommendations_noPreviousShardingEvent but with PEAK rather than ALL_TIME write load
302+ public void testCalculateIncreaseShardingRecommendations_usingAllTimeWriteLoad () {
303+ // Repeated testCalculateIncreaseShardingRecommendations_noPreviousShardingEvent but with ALL_TIME rather than PEAK write load
304304 var projectId = randomProjectIdOrDefault ();
305305 ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
306306 DataStream dataStream = createDataStream (
@@ -318,11 +318,11 @@ public void testCalculateIncreaseShardingRecommendations_usingPeakWriteLoad() {
318318 .putProjectMetadata (builder .build ())
319319 .build ();
320320
321- doWithMetricSelection (DATA_STREAMS_AUTO_SHARDING_INCREASE_SHARDS_LOAD_METRIC , WriteLoadMetric .PEAK , () -> {
321+ doWithMetricSelection (DATA_STREAMS_AUTO_SHARDING_INCREASE_SHARDS_LOAD_METRIC , WriteLoadMetric .ALL_TIME , () -> {
322322 AutoShardingResult autoShardingResult = service .calculate (
323323 state .projectState (projectId ),
324324 dataStream ,
325- createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
325+ createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
326326 );
327327 assertThat (autoShardingResult .type (), is (INCREASE_SHARDS ));
328328 // no pre-existing scaling event so the cool down must be zero
@@ -343,7 +343,7 @@ public void testCalculateDecreaseShardingRecommendations_dataStreamNotOldEnough(
343343 3 ,
344344 now ,
345345 List .of (now - 10_000 , now - 7000 , now - 5000 , now - 2000 , now - 1000 ),
346- getWriteLoad (3 , 0.25 , 9999.0 , 9999.0 ),
346+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.25 ),
347347 null
348348 );
349349 builder .put (dataStream );
@@ -355,7 +355,7 @@ public void testCalculateDecreaseShardingRecommendations_dataStreamNotOldEnough(
355355 AutoShardingResult autoShardingResult = service .calculate (
356356 state .projectState (projectId ),
357357 dataStream ,
358- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
358+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
359359 );
360360 // the cooldown period for the decrease shards event hasn't lapsed since the data stream was created
361361 assertThat (autoShardingResult .type (), is (COOLDOWN_PREVENTED_DECREASE ));
@@ -380,7 +380,7 @@ public void testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent
380380 now - TimeValue .timeValueDays (2 ).getMillis (),
381381 now - 1000
382382 ),
383- getWriteLoad (3 , 0.333 , 9999.0 , 9999.0 ),
383+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.333 ),
384384 null
385385 );
386386 builder .put (dataStream );
@@ -392,7 +392,7 @@ public void testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent
392392 AutoShardingResult autoShardingResult = service .calculate (
393393 state .projectState (projectId ),
394394 dataStream ,
395- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
395+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
396396 );
397397 assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
398398 assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -424,7 +424,7 @@ public void testCalculateDecreaseShardingRecommendations_notPreventedByPreviousD
424424 now - TimeValue .timeValueDays (2 ).getMillis (),
425425 now - 1000
426426 ),
427- getWriteLoad (3 , 0.333 , 9999.0 , 9999.0 ),
427+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.333 ),
428428 autoShardingEvent
429429 );
430430 builder .put (dataStream );
@@ -436,7 +436,7 @@ public void testCalculateDecreaseShardingRecommendations_notPreventedByPreviousD
436436 AutoShardingResult autoShardingResult = service .calculate (
437437 state .projectState (projectId ),
438438 dataStream ,
439- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
439+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
440440 );
441441 assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
442442 assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -466,7 +466,7 @@ public void testCalculateDecreaseShardingRecommendations_preventedByCooldown() {
466466 now - TimeValue .timeValueDays (1 ).getMillis (),
467467 now - 1000
468468 ),
469- getWriteLoad (3 , 0.25 , 9999.0 , 9999.0 ),
469+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.25 ),
470470 autoShardingEvent
471471 );
472472 builder .put (dataStream );
@@ -478,7 +478,7 @@ public void testCalculateDecreaseShardingRecommendations_preventedByCooldown() {
478478 AutoShardingResult autoShardingResult = service .calculate (
479479 state .projectState (projectId ),
480480 dataStream ,
481- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
481+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
482482 );
483483 assertThat (autoShardingResult .type (), is (COOLDOWN_PREVENTED_DECREASE ));
484484 assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -515,15 +515,15 @@ public void testCalculateDecreaseShardingRecommendations_noChangeRequired() {
515515 AutoShardingResult autoShardingResult = service .calculate (
516516 state .projectState (projectId ),
517517 dataStream ,
518- createIndexStats (3 , 4.0 / 3 , 9999.0 , 9999.0 )
518+ createIndexStats (3 , 9999.0 , 9999.0 , 4.0 / 3 )
519519 );
520520 assertThat (autoShardingResult .type (), is (NO_CHANGE_REQUIRED ));
521521 assertThat (autoShardingResult .targetNumberOfShards (), is (3 ));
522522 assertThat (autoShardingResult .coolDownRemaining (), is (TimeValue .ZERO ));
523523 }
524524
525525 public void testCalculateDecreaseShardingRecommendations_usingRecentWriteLoad () {
526- // Repeated testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent but with RECENT rather than ALL_TIME write load
526+ // Repeated testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent but with RECENT rather than PEAK write load
527527 var projectId = randomProjectIdOrDefault ();
528528 ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
529529 DataStream dataStream = createDataStream (
@@ -551,16 +551,16 @@ public void testCalculateDecreaseShardingRecommendations_usingRecentWriteLoad()
551551 AutoShardingResult autoShardingResult = service .calculate (
552552 state .projectState (projectId ),
553553 dataStream ,
554- createIndexStats (3 , 0.5 / 3 , 1.0 / 3 , 9999.0 )
554+ createIndexStats (3 , 9999.0 , 1.0 / 3 , 0.5 / 3 )
555555 );
556556 assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
557557 assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
558558 assertThat (autoShardingResult .coolDownRemaining (), is (TimeValue .ZERO ));
559559 });
560560 }
561561
562- public void testCalculateDecreaseShardingRecommendations_usingPeakWriteLoad () {
563- // Repeated testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent but with PEAK rather than ALL_TIME write load
562+ public void testCalculateDecreaseShardingRecommendations_usingAllTimeWriteLoad () {
563+ // Repeated testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent but with ALL_TIME rather than PEAK write load
564564 var projectId = randomProjectIdOrDefault ();
565565 ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
566566 DataStream dataStream = createDataStream (
@@ -588,7 +588,7 @@ public void testCalculateDecreaseShardingRecommendations_usingPeakWriteLoad() {
588588 AutoShardingResult autoShardingResult = service .calculate (
589589 state .projectState (projectId ),
590590 dataStream ,
591- createIndexStats (3 , 0.5 / 3 , 9999.0 , 1.0 / 3 )
591+ createIndexStats (3 , 1.0 / 3 , 9999.0 , 0.5 / 3 )
592592 );
593593 assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
594594 assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -629,7 +629,7 @@ public void testCalculateDecreaseShardingRecommendations_correctDecisionData() {
629629 AutoShardingResult autoShardingResult = service .calculate (
630630 state .projectState (projectId ),
631631 dataStream ,
632- createIndexStats (3 , 1 .9 / 3 , 0.3 / 3 , 0 .9 / 3 )
632+ createIndexStats (3 , 0 .9 / 3 , 0.3 / 3 , 1 .9 / 3 )
633633 );
634634 assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
635635 assertThat (autoShardingResult .currentNumberOfShards (), is (3 ));
@@ -653,13 +653,13 @@ public void testCalculateDecreaseShardingRecommendations_correctDecisionData() {
653653 decision .inputs ().maxWriteThreads (),
654654 equalTo (DataStreamAutoShardingService .CLUSTER_AUTO_SHARDING_MAX_WRITE_THREADS .getDefault (Settings .EMPTY ))
655655 );
656- assertThat (decision .inputs ().increaseShardsMetric (), equalTo (WriteLoadMetric .ALL_TIME ));
656+ assertThat (decision .inputs ().increaseShardsMetric (), equalTo (WriteLoadMetric .PEAK ));
657657 assertThat (decision .inputs ().decreaseShardsMetric (), equalTo (WriteLoadMetric .RECENT ));
658658 assertThat (decision .inputs ().dataStream (), equalTo (dataStreamName ));
659659 assertThat (decision .inputs ().writeIndex (), equalTo (DataStream .getDefaultBackingIndexName (dataStreamName , 5 , now - 1000 )));
660- assertThat (decision .inputs ().writeIndexAllTimeLoad (), closeTo (1 .9 , 1.0e-8 ));
660+ assertThat (decision .inputs ().writeIndexAllTimeLoad (), closeTo (0 .9 , 1.0e-8 ));
661661 assertThat (decision .inputs ().writeIndexRecentLoad (), closeTo (0.3 , 1.0e-8 ));
662- assertThat (decision .inputs ().writeIndexPeakLoad (), closeTo (0 .9 , 1.0e-8 ));
662+ assertThat (decision .inputs ().writeIndexPeakLoad (), closeTo (1 .9 , 1.0e-8 ));
663663 assertThat (decision .inputs ().currentNumberOfWriteIndexShards (), equalTo (3 ));
664664 assertThat (decision .increaseCalculation ().writeIndexLoadForIncrease (), closeTo (1.9 , 1.0e-8 )); // all-time
665665 // Increase shard count based on all-time load of 1.9 for write index:
@@ -1022,7 +1022,7 @@ public void testAutoShardingResultValidation_validCooldownPreventedDecrease() {
10221022 assertThat (cooldownPreventedDecrease .coolDownRemaining (), is (TimeValue .timeValueSeconds (7 )));
10231023 }
10241024
1025- IndexStats createIndexStats (int numberOfShards , double shardWriteLoad , double shardRecentWriteLoad , double shardPeakWriteLoad ) {
1025+ private IndexStats createIndexStats (int numberOfShards , double shardWriteLoad , double shardRecentWriteLoad , double shardPeakWriteLoad ) {
10261026 String indexName = DataStream .getDefaultBackingIndexName (dataStreamName , 99 ); // the generation number here is not used
10271027 Index index = new Index (indexName , randomUUID ());
10281028 IndexStats .IndexStatsBuilder builder = new IndexStats .IndexStatsBuilder (indexName , randomUUID (), null , null );
0 commit comments