@@ -148,7 +148,7 @@ public void testCalculateValidations() {
148
148
AutoShardingResult autoShardingResult = disabledAutoshardingService .calculate (
149
149
state .projectState (projectId ),
150
150
dataStream ,
151
- createIndexStats (1 , 2 .0 , 9999.0 , 9999 .0 )
151
+ createIndexStats (1 , 9999 .0 , 9999.0 , 2 .0 )
152
152
);
153
153
assertThat (autoShardingResult , is (NOT_APPLICABLE_RESULT ));
154
154
}
@@ -182,7 +182,7 @@ public void testCalculateIncreaseShardingRecommendations_noPreviousShardingEvent
182
182
AutoShardingResult autoShardingResult = service .calculate (
183
183
state .projectState (projectId ),
184
184
dataStream ,
185
- createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
185
+ createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
186
186
);
187
187
assertThat (autoShardingResult .type (), is (INCREASE_SHARDS ));
188
188
// no pre-existing scaling event so the cool down must be zero
@@ -221,7 +221,7 @@ public void testCalculateIncreaseShardingRecommendations_preventedByCooldown() {
221
221
AutoShardingResult autoShardingResult = service .calculate (
222
222
state .projectState (projectId ),
223
223
dataStream ,
224
- createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
224
+ createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
225
225
);
226
226
assertThat (autoShardingResult .type (), is (COOLDOWN_PREVENTED_INCREASE ));
227
227
// no pre-existing scaling event so the cool down must be zero
@@ -259,7 +259,7 @@ public void testCalculateIncreaseShardingRecommendations_notPreventedByPreviousI
259
259
AutoShardingResult autoShardingResult = service .calculate (
260
260
state .projectState (projectId ),
261
261
dataStream ,
262
- createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
262
+ createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
263
263
);
264
264
assertThat (autoShardingResult .type (), is (INCREASE_SHARDS ));
265
265
// no pre-existing scaling event so the cool down must be zero
@@ -268,7 +268,7 @@ public void testCalculateIncreaseShardingRecommendations_notPreventedByPreviousI
268
268
}
269
269
270
270
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
272
272
var projectId = randomProjectIdOrDefault ();
273
273
ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
274
274
DataStream dataStream = createDataStream (
@@ -299,8 +299,8 @@ public void testCalculateIncreaseShardingRecommendations_usingRecentWriteLoad()
299
299
});
300
300
}
301
301
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
304
304
var projectId = randomProjectIdOrDefault ();
305
305
ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
306
306
DataStream dataStream = createDataStream (
@@ -318,11 +318,11 @@ public void testCalculateIncreaseShardingRecommendations_usingPeakWriteLoad() {
318
318
.putProjectMetadata (builder .build ())
319
319
.build ();
320
320
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 , () -> {
322
322
AutoShardingResult autoShardingResult = service .calculate (
323
323
state .projectState (projectId ),
324
324
dataStream ,
325
- createIndexStats (1 , 9999.0 , 9999.0 , 2.5 )
325
+ createIndexStats (1 , 2.5 , 9999.0 , 9999.0 )
326
326
);
327
327
assertThat (autoShardingResult .type (), is (INCREASE_SHARDS ));
328
328
// no pre-existing scaling event so the cool down must be zero
@@ -343,7 +343,7 @@ public void testCalculateDecreaseShardingRecommendations_dataStreamNotOldEnough(
343
343
3 ,
344
344
now ,
345
345
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 ),
347
347
null
348
348
);
349
349
builder .put (dataStream );
@@ -355,7 +355,7 @@ public void testCalculateDecreaseShardingRecommendations_dataStreamNotOldEnough(
355
355
AutoShardingResult autoShardingResult = service .calculate (
356
356
state .projectState (projectId ),
357
357
dataStream ,
358
- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
358
+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
359
359
);
360
360
// the cooldown period for the decrease shards event hasn't lapsed since the data stream was created
361
361
assertThat (autoShardingResult .type (), is (COOLDOWN_PREVENTED_DECREASE ));
@@ -380,7 +380,7 @@ public void testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent
380
380
now - TimeValue .timeValueDays (2 ).getMillis (),
381
381
now - 1000
382
382
),
383
- getWriteLoad (3 , 0.333 , 9999.0 , 9999.0 ),
383
+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.333 ),
384
384
null
385
385
);
386
386
builder .put (dataStream );
@@ -392,7 +392,7 @@ public void testCalculateDecreaseShardingRecommendations_noPreviousShardingEvent
392
392
AutoShardingResult autoShardingResult = service .calculate (
393
393
state .projectState (projectId ),
394
394
dataStream ,
395
- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
395
+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
396
396
);
397
397
assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
398
398
assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -424,7 +424,7 @@ public void testCalculateDecreaseShardingRecommendations_notPreventedByPreviousD
424
424
now - TimeValue .timeValueDays (2 ).getMillis (),
425
425
now - 1000
426
426
),
427
- getWriteLoad (3 , 0.333 , 9999.0 , 9999.0 ),
427
+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.333 ),
428
428
autoShardingEvent
429
429
);
430
430
builder .put (dataStream );
@@ -436,7 +436,7 @@ public void testCalculateDecreaseShardingRecommendations_notPreventedByPreviousD
436
436
AutoShardingResult autoShardingResult = service .calculate (
437
437
state .projectState (projectId ),
438
438
dataStream ,
439
- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
439
+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
440
440
);
441
441
assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
442
442
assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -466,7 +466,7 @@ public void testCalculateDecreaseShardingRecommendations_preventedByCooldown() {
466
466
now - TimeValue .timeValueDays (1 ).getMillis (),
467
467
now - 1000
468
468
),
469
- getWriteLoad (3 , 0.25 , 9999.0 , 9999.0 ),
469
+ getWriteLoad (3 , 9999.0 , 9999.0 , 0.25 ),
470
470
autoShardingEvent
471
471
);
472
472
builder .put (dataStream );
@@ -478,7 +478,7 @@ public void testCalculateDecreaseShardingRecommendations_preventedByCooldown() {
478
478
AutoShardingResult autoShardingResult = service .calculate (
479
479
state .projectState (projectId ),
480
480
dataStream ,
481
- createIndexStats (3 , 1.0 / 3 , 9999.0 , 9999.0 )
481
+ createIndexStats (3 , 9999.0 , 9999.0 , 1.0 / 3 )
482
482
);
483
483
assertThat (autoShardingResult .type (), is (COOLDOWN_PREVENTED_DECREASE ));
484
484
assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -515,15 +515,15 @@ public void testCalculateDecreaseShardingRecommendations_noChangeRequired() {
515
515
AutoShardingResult autoShardingResult = service .calculate (
516
516
state .projectState (projectId ),
517
517
dataStream ,
518
- createIndexStats (3 , 4.0 / 3 , 9999.0 , 9999.0 )
518
+ createIndexStats (3 , 9999.0 , 9999.0 , 4.0 / 3 )
519
519
);
520
520
assertThat (autoShardingResult .type (), is (NO_CHANGE_REQUIRED ));
521
521
assertThat (autoShardingResult .targetNumberOfShards (), is (3 ));
522
522
assertThat (autoShardingResult .coolDownRemaining (), is (TimeValue .ZERO ));
523
523
}
524
524
525
525
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
527
527
var projectId = randomProjectIdOrDefault ();
528
528
ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
529
529
DataStream dataStream = createDataStream (
@@ -551,16 +551,16 @@ public void testCalculateDecreaseShardingRecommendations_usingRecentWriteLoad()
551
551
AutoShardingResult autoShardingResult = service .calculate (
552
552
state .projectState (projectId ),
553
553
dataStream ,
554
- createIndexStats (3 , 0.5 / 3 , 1.0 / 3 , 9999.0 )
554
+ createIndexStats (3 , 9999.0 , 1.0 / 3 , 0.5 / 3 )
555
555
);
556
556
assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
557
557
assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
558
558
assertThat (autoShardingResult .coolDownRemaining (), is (TimeValue .ZERO ));
559
559
});
560
560
}
561
561
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
564
564
var projectId = randomProjectIdOrDefault ();
565
565
ProjectMetadata .Builder builder = ProjectMetadata .builder (projectId );
566
566
DataStream dataStream = createDataStream (
@@ -588,7 +588,7 @@ public void testCalculateDecreaseShardingRecommendations_usingPeakWriteLoad() {
588
588
AutoShardingResult autoShardingResult = service .calculate (
589
589
state .projectState (projectId ),
590
590
dataStream ,
591
- createIndexStats (3 , 0.5 / 3 , 9999.0 , 1.0 / 3 )
591
+ createIndexStats (3 , 1.0 / 3 , 9999.0 , 0.5 / 3 )
592
592
);
593
593
assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
594
594
assertThat (autoShardingResult .targetNumberOfShards (), is (1 ));
@@ -629,7 +629,7 @@ public void testCalculateDecreaseShardingRecommendations_correctDecisionData() {
629
629
AutoShardingResult autoShardingResult = service .calculate (
630
630
state .projectState (projectId ),
631
631
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 )
633
633
);
634
634
assertThat (autoShardingResult .type (), is (DECREASE_SHARDS ));
635
635
assertThat (autoShardingResult .currentNumberOfShards (), is (3 ));
@@ -653,13 +653,13 @@ public void testCalculateDecreaseShardingRecommendations_correctDecisionData() {
653
653
decision .inputs ().maxWriteThreads (),
654
654
equalTo (DataStreamAutoShardingService .CLUSTER_AUTO_SHARDING_MAX_WRITE_THREADS .getDefault (Settings .EMPTY ))
655
655
);
656
- assertThat (decision .inputs ().increaseShardsMetric (), equalTo (WriteLoadMetric .ALL_TIME ));
656
+ assertThat (decision .inputs ().increaseShardsMetric (), equalTo (WriteLoadMetric .PEAK ));
657
657
assertThat (decision .inputs ().decreaseShardsMetric (), equalTo (WriteLoadMetric .RECENT ));
658
658
assertThat (decision .inputs ().dataStream (), equalTo (dataStreamName ));
659
659
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 ));
661
661
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 ));
663
663
assertThat (decision .inputs ().currentNumberOfWriteIndexShards (), equalTo (3 ));
664
664
assertThat (decision .increaseCalculation ().writeIndexLoadForIncrease (), closeTo (1.9 , 1.0e-8 )); // all-time
665
665
// Increase shard count based on all-time load of 1.9 for write index:
@@ -1022,7 +1022,7 @@ public void testAutoShardingResultValidation_validCooldownPreventedDecrease() {
1022
1022
assertThat (cooldownPreventedDecrease .coolDownRemaining (), is (TimeValue .timeValueSeconds (7 )));
1023
1023
}
1024
1024
1025
- IndexStats createIndexStats (int numberOfShards , double shardWriteLoad , double shardRecentWriteLoad , double shardPeakWriteLoad ) {
1025
+ private IndexStats createIndexStats (int numberOfShards , double shardWriteLoad , double shardRecentWriteLoad , double shardPeakWriteLoad ) {
1026
1026
String indexName = DataStream .getDefaultBackingIndexName (dataStreamName , 99 ); // the generation number here is not used
1027
1027
Index index = new Index (indexName , randomUUID ());
1028
1028
IndexStats .IndexStatsBuilder builder = new IndexStats .IndexStatsBuilder (indexName , randomUUID (), null , null );
0 commit comments