Skip to content

Commit 3d830a0

Browse files
autoscaler: ignore ScaleDownDelay if not reachable (#15831)
* autoscaler: ignore ScaleDownDelay if not reachable * gofumpt --------- Co-authored-by: Dave Protasowski <[email protected]>
1 parent 8ee578e commit 3d830a0

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Diff for: 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 {

Diff for: pkg/autoscaler/scaling/autoscaler_test.go

+45
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,50 @@ func TestAutoscalerScaleDownDelay(t *testing.T) {
128129
})
129130
}
130131

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

0 commit comments

Comments
 (0)