@@ -129,13 +129,13 @@ public void testEndToEnd() throws Exception {
129129
130130 setDefaultMetrics (metricsCollector );
131131
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
134134 var collectedMetrics = metricsCollector .updateMetrics (context , stateStore );
135- assertTrue ( collectedMetrics .getMetricHistory ().isEmpty ());
135+ assertEquals ( 1 , collectedMetrics .getMetricHistory ().size ());
136136
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
139139 clock = Clock .offset (clock , conf .get (AutoScalerOptions .STABILIZATION_INTERVAL ));
140140 metricsCollector .setClock (clock );
141141 collectedMetrics = metricsCollector .updateMetrics (context , stateStore );
@@ -294,12 +294,12 @@ public void testJobDetailsRestCompatibility() throws JsonProcessingException {
294294 public void testMetricCollectorWindow () throws Exception {
295295 setDefaultMetrics (metricsCollector );
296296 var metricsHistory = metricsCollector .updateMetrics (context , stateStore );
297- assertEquals (0 , metricsHistory .getMetricHistory ().size ());
297+ assertEquals (1 , metricsHistory .getMetricHistory ().size ());
298298
299- // Not stable, nothing should be collected
299+ // Not stable, metrics collected and reported
300300 metricsCollector .setClock (Clock .offset (clock , Duration .ofSeconds (1 )));
301301 metricsHistory = metricsCollector .updateMetrics (context , stateStore );
302- assertEquals (0 , metricsHistory .getMetricHistory ().size ());
302+ assertEquals (2 , metricsHistory .getMetricHistory ().size ());
303303
304304 // Update clock to stable time
305305 var conf = context .getConfiguration ();
@@ -336,10 +336,10 @@ public void testMetricCollectorWindow() throws Exception {
336336 metricsHistory = metricsCollector .updateMetrics (context , stateStore );
337337 assertEquals (1 , metricsHistory .getMetricHistory ().size ());
338338
339- // Existing metrics should be cleared on job updates
339+ // Existing metrics should be cleared on job updates, and start collecting from fresh
340340 metricsCollector .setJobUpdateTs (clock .instant ().plus (Duration .ofDays (10 )));
341341 metricsHistory = metricsCollector .updateMetrics (context , stateStore );
342- assertEquals (0 , metricsHistory .getMetricHistory ().size ());
342+ assertEquals (1 , metricsHistory .getMetricHistory ().size ());
343343 }
344344
345345 @ Test
@@ -351,10 +351,11 @@ public void testClearHistoryOnTopoChange() throws Exception {
351351
352352 setDefaultMetrics (metricsCollector );
353353
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
356356 var collectedMetrics = metricsCollector .updateMetrics (context , stateStore );
357- assertTrue (collectedMetrics .getMetricHistory ().isEmpty ());
357+ assertFalse (collectedMetrics .getMetricHistory ().isEmpty ());
358+ assertFalse (collectedMetrics .isFullyCollected ());
358359 }
359360
360361 @ Test
@@ -571,19 +572,18 @@ public void testMetricCollectionDuringStabilization() throws Exception {
571572 .set (AutoScalerOptions .STABILIZATION_INTERVAL , Duration .ofMillis (100 ));
572573 context .getConfiguration ().set (AutoScalerOptions .METRICS_WINDOW , Duration .ofMillis (100 ));
573574
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
575576 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 ());
578579 assertEquals (1 , stateStore .getCollectedMetrics (context ).size ());
579580 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 ());
582583 assertEquals (2 , stateStore .getCollectedMetrics (context ).size ());
583584
584585 testTolerateMetricsMissingDuringStabilizationPhase (topology );
585586
586- // Until window is full (time=200) we keep returning stabilizing metrics
587587 metricsCollector .setClock (Clock .fixed (Instant .ofEpochMilli (150 ), ZoneId .systemDefault ()));
588588 assertEquals (
589589 3 , metricsCollector .updateMetrics (context , stateStore ).getMetricHistory ().size ());
0 commit comments