@@ -129,13 +129,13 @@ public void testEndToEnd() throws Exception {
129
129
130
130
setDefaultMetrics (metricsCollector );
131
131
132
- // We haven't left the stabilization period
133
- // => no metrics reporting and collection should take place
132
+ // We haven't left the stabilization period, but we're collecting and returning the metrics
133
+ // for reporting
134
134
var collectedMetrics = metricsCollector .updateMetrics (context , stateStore );
135
- assertTrue ( collectedMetrics .getMetricHistory ().isEmpty ());
135
+ assertEquals ( 1 , collectedMetrics .getMetricHistory ().size ());
136
136
137
- // We haven't collected a full window yet, no metrics should be reported but metrics should
138
- // still get collected.
137
+ // We haven't collected a full window yet, but we're collecting and returning the metrics
138
+ // for reporting
139
139
clock = Clock .offset (clock , conf .get (AutoScalerOptions .STABILIZATION_INTERVAL ));
140
140
metricsCollector .setClock (clock );
141
141
collectedMetrics = metricsCollector .updateMetrics (context , stateStore );
@@ -294,12 +294,12 @@ public void testJobDetailsRestCompatibility() throws JsonProcessingException {
294
294
public void testMetricCollectorWindow () throws Exception {
295
295
setDefaultMetrics (metricsCollector );
296
296
var metricsHistory = metricsCollector .updateMetrics (context , stateStore );
297
- assertEquals (0 , metricsHistory .getMetricHistory ().size ());
297
+ assertEquals (1 , metricsHistory .getMetricHistory ().size ());
298
298
299
- // Not stable, nothing should be collected
299
+ // Not stable, metrics collected and reported
300
300
metricsCollector .setClock (Clock .offset (clock , Duration .ofSeconds (1 )));
301
301
metricsHistory = metricsCollector .updateMetrics (context , stateStore );
302
- assertEquals (0 , metricsHistory .getMetricHistory ().size ());
302
+ assertEquals (2 , metricsHistory .getMetricHistory ().size ());
303
303
304
304
// Update clock to stable time
305
305
var conf = context .getConfiguration ();
@@ -336,10 +336,10 @@ public void testMetricCollectorWindow() throws Exception {
336
336
metricsHistory = metricsCollector .updateMetrics (context , stateStore );
337
337
assertEquals (1 , metricsHistory .getMetricHistory ().size ());
338
338
339
- // Existing metrics should be cleared on job updates
339
+ // Existing metrics should be cleared on job updates, and start collecting from fresh
340
340
metricsCollector .setJobUpdateTs (clock .instant ().plus (Duration .ofDays (10 )));
341
341
metricsHistory = metricsCollector .updateMetrics (context , stateStore );
342
- assertEquals (0 , metricsHistory .getMetricHistory ().size ());
342
+ assertEquals (1 , metricsHistory .getMetricHistory ().size ());
343
343
}
344
344
345
345
@ Test
@@ -351,10 +351,11 @@ public void testClearHistoryOnTopoChange() throws Exception {
351
351
352
352
setDefaultMetrics (metricsCollector );
353
353
354
- // We haven't left the stabilization period
355
- // => no metrics reporting and collection should take place
354
+ // We haven't left the stabilization period, we're returning the metrics
355
+ // but don't act on it since the metric window is not full yet
356
356
var collectedMetrics = metricsCollector .updateMetrics (context , stateStore );
357
- assertTrue (collectedMetrics .getMetricHistory ().isEmpty ());
357
+ assertFalse (collectedMetrics .getMetricHistory ().isEmpty ());
358
+ assertFalse (collectedMetrics .isFullyCollected ());
358
359
}
359
360
360
361
@ Test
@@ -571,19 +572,18 @@ public void testMetricCollectionDuringStabilization() throws Exception {
571
572
.set (AutoScalerOptions .STABILIZATION_INTERVAL , Duration .ofMillis (100 ));
572
573
context .getConfiguration ().set (AutoScalerOptions .METRICS_WINDOW , Duration .ofMillis (100 ));
573
574
574
- // Within stabilization period we simply collect metrics but do not return them
575
+ // Until window is full (time=200) we keep returning stabilizing metrics
575
576
metricsCollector .setClock (Clock .fixed (Instant .ofEpochMilli (50 ), ZoneId .systemDefault ()));
576
- assertTrue (
577
- metricsCollector .updateMetrics (context , stateStore ).getMetricHistory ().isEmpty ());
577
+ assertEquals (
578
+ 1 , metricsCollector .updateMetrics (context , stateStore ).getMetricHistory ().size ());
578
579
assertEquals (1 , stateStore .getCollectedMetrics (context ).size ());
579
580
metricsCollector .setClock (Clock .fixed (Instant .ofEpochMilli (60 ), ZoneId .systemDefault ()));
580
- assertTrue (
581
- metricsCollector .updateMetrics (context , stateStore ).getMetricHistory ().isEmpty ());
581
+ assertEquals (
582
+ 2 , metricsCollector .updateMetrics (context , stateStore ).getMetricHistory ().size ());
582
583
assertEquals (2 , stateStore .getCollectedMetrics (context ).size ());
583
584
584
585
testTolerateMetricsMissingDuringStabilizationPhase (topology );
585
586
586
- // Until window is full (time=200) we keep returning stabilizing metrics
587
587
metricsCollector .setClock (Clock .fixed (Instant .ofEpochMilli (150 ), ZoneId .systemDefault ()));
588
588
assertEquals (
589
589
3 , metricsCollector .updateMetrics (context , stateStore ).getMetricHistory ().size ());
0 commit comments