Skip to content

Commit 2de056a

Browse files
authored
[ResourceScaler] Wait 30 seconds before scaling to / from zero (#34)
1 parent 8f6d199 commit 2de056a

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

pkg/resourcescaler/resourcescaler.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,23 +309,61 @@ func (s *AppResourceScaler) patchIguazioTenantAppServiceSets(ctx context.Context
309309

310310
func (s *AppResourceScaler) waitForNoProvisioningInProcess(ctx context.Context) error {
311311
s.logger.DebugWithCtx(ctx, "Waiting for IguazioTenantAppServiceSet to finish provisioning")
312+
313+
finiteStateDiscoveryTimeout := 30 * time.Second
314+
315+
var finiteStateDiscoveryTime *time.Time
312316
for {
313317
select {
314318
case <-ctx.Done():
315319
return ctx.Err()
316320

317-
case <-time.After(10 * time.Second):
321+
case <-time.After(5 * time.Second):
322+
s.logger.DebugWithCtx(ctx, "Checking the state of the Iguazio tenant app service sets")
318323
_, _, state, err := s.getIguazioTenantAppServiceSets(ctx)
319324
if err != nil {
320-
return errors.Wrap(err, "Failed to get iguazio tenant app service sets")
325+
s.logger.WarnWithCtx(ctx, "Failed to get iguazio tenant app service sets",
326+
"err", err.Error())
327+
continue
321328
}
322329

323330
if state == "ready" || state == "error" {
324-
s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet finished provisioning")
325-
return nil
331+
if finiteStateDiscoveryTime == nil {
332+
now := time.Now()
333+
finiteStateDiscoveryTime = &now
334+
s.logger.DebugWithCtx(ctx,
335+
"IguazioTenantAppServiceSet finished provisioning", "state", state)
336+
}
337+
} else {
338+
339+
// reset the time if the state is not stable
340+
if finiteStateDiscoveryTime != nil {
341+
s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet is provisioning again, "+
342+
"resetting discovery time",
343+
"state", state,
344+
"finiteStateDiscoveryTime", time.Since(*finiteStateDiscoveryTime).String())
345+
}
346+
finiteStateDiscoveryTime = nil
326347
}
327348

328-
s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet is still provisioning", "state", state)
349+
if finiteStateDiscoveryTime != nil {
350+
351+
// it has been finite for finiteStateDiscoveryTimeout amount of time
352+
// we can safely assume that other services waiting for app services to be ready
353+
// captured the state change. now it would be our turn
354+
timeSince := time.Since(*finiteStateDiscoveryTime)
355+
if timeSince >= finiteStateDiscoveryTimeout {
356+
s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet state is stabled")
357+
return nil
358+
359+
}
360+
s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet waiting for the state to be stable",
361+
"state", state,
362+
"timeSince", timeSince.String())
363+
} else {
364+
s.logger.DebugWithCtx(ctx, "IguazioTenantAppServiceSet is still provisioning",
365+
"state", state)
366+
}
329367
}
330368

331369
}

0 commit comments

Comments
 (0)