Skip to content

Commit e2d98b1

Browse files
committed
autoscaler: ignore ScaleDownDelay if not reachable
1 parent 3c3e59c commit e2d98b1

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

pkg/autoscaler/scaling/autoscaler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ func (a *autoscaler) Scale(logger *zap.SugaredLogger, now time.Time) ScaleResult
247247
logger.Debug("Operating in stable mode.")
248248
}
249249

250-
// Delay scale down decisions, if a ScaleDownDelay was specified.
250+
// Delay scale down decisions if reachable and if a ScaleDownDelay was specified.
251251
// We only do this if there's a non-nil delayWindow because although a
252252
// one-element delay window is _almost_ the same as no delay at all, it is
253253
// not the same in the case where two Scale()s happen in the same time
254254
// interval (because the largest will be picked rather than the most recent
255255
// in that case).
256-
if a.delayWindow != nil {
256+
if a.deciderSpec.Reachable && a.delayWindow != nil {
257257
a.delayWindow.Record(now, desiredPodCount)
258258
delayedPodCount := a.delayWindow.Current()
259259
if delayedPodCount != desiredPodCount {

pkg/autoscaler/scaling/autoscaler_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func TestAutoscalerScaleDownDelay(t *testing.T) {
7676
MaxScaleUpRate: 10,
7777
PanicThreshold: 100,
7878
ScaleDownDelay: 5 * time.Minute,
79+
Reachable: true,
7980
}
8081
as := New(context.Background(), testNamespace, testRevision, metrics, pc, spec)
8182

@@ -128,6 +129,51 @@ func TestAutoscalerScaleDownDelay(t *testing.T) {
128129
})
129130
}
130131

132+
func TestAutoscalerScaleDownDelayNotReachable(t *testing.T) {
133+
134+
pc := &fakePodCounter{}
135+
metrics := &metricClient{}
136+
spec := &DeciderSpec{
137+
TargetValue: 10,
138+
MaxScaleDownRate: 10,
139+
MaxScaleUpRate: 10,
140+
PanicThreshold: 100,
141+
ScaleDownDelay: 5 * time.Minute,
142+
Reachable: true,
143+
}
144+
as := New(context.Background(), testNamespace, testRevision, metrics, pc, spec)
145+
146+
now := time.Time{}
147+
148+
// scale up.
149+
metrics.SetStableAndPanicConcurrency(40, 40)
150+
expectScale(t, as, now.Add(2*time.Second), ScaleResult{
151+
ScaleValid: true,
152+
DesiredPodCount: 4,
153+
})
154+
// one minute passes at reduced concurrency - should not scale down (less than delay).
155+
metrics.SetStableAndPanicConcurrency(0, 0)
156+
expectScale(t, as, now.Add(1*time.Minute), ScaleResult{
157+
ScaleValid: true,
158+
DesiredPodCount: 4,
159+
})
160+
// mark as unreachable to simulate another revision coming up
161+
unreachableSpec := &DeciderSpec{
162+
TargetValue: 10,
163+
MaxScaleDownRate: 10,
164+
MaxScaleUpRate: 10,
165+
PanicThreshold: 100,
166+
ScaleDownDelay: 5 * time.Minute,
167+
Reachable: false,
168+
}
169+
as.Update(unreachableSpec)
170+
// 2 seconds pass at reduced concurrency - now we scale down.
171+
expectScale(t, as, now.Add(2*time.Second), ScaleResult{
172+
ScaleValid: true,
173+
DesiredPodCount: 0,
174+
})
175+
}
176+
131177
func TestAutoscalerScaleDownDelayZero(t *testing.T) {
132178
pc := &fakePodCounter{}
133179
metrics := &metricClient{}

0 commit comments

Comments
 (0)