ENG-4890: Configure Light Sleep and Deep Sleep times from CLI#299
ENG-4890: Configure Light Sleep and Deep Sleep times from CLI#299
Conversation
Add two new flags for configuring light sleep and deep sleep idle delays on services. These flags control after how long an idle service enters light sleep or deep sleep mode. - --light-sleep-delay: duration before an idle service enters light sleep - --deep-sleep-delay: duration before an idle service enters deep sleep - Set to 0 to disable either sleep mode - Both flags use Go duration format (e.g., '1m', '5m', '1h') The flags are available on service create, service update, and deploy commands. They map to the SleepIdleDelay scaling target in the API. Also upgrades koyeb-api-client-go to pick up the DeepSleepValue and LightSleepValue fields on DeploymentScalingTargetSleepIdleDelay.
There was a problem hiding this comment.
Pull request overview
Adds CLI support for configuring service idle sleep behavior by introducing flags that map to the API’s DeploymentScalingTargetSleepIdleDelay light/deep sleep delay fields.
Changes:
- Add
--light-sleep-delayand--deep-sleep-delayduration flags to service/deploy commands. - Update scaling target parsing to create/update/remove the
SleepIdleDelayscaling target based on those flags. - Add unit tests covering new/updated/disabled sleep delay scenarios.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/koyeb/services.go | Adds new duration flags and updates setScalingsTargets to manage the SleepIdleDelay target. |
| pkg/koyeb/services_test.go | Adds table-driven tests validating sleep delay flag behavior against scaling targets. |
| go.mod | Bumps koyeb-api-client-go to a version that includes the new sleep delay fields. |
| go.sum | Updates checksums for the bumped API client dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if lightSleepDuration > 0 { | ||
| sid.SetLightSleepValue(int64(lightSleepDuration.Seconds())) | ||
| } else { | ||
| sid.LightSleepValue = nil | ||
| } | ||
| } | ||
| if deepSleepChanged { | ||
| if deepSleepDuration > 0 { | ||
| sid.SetDeepSleepValue(int64(deepSleepDuration.Seconds())) | ||
| } else { |
There was a problem hiding this comment.
Duration-to-seconds conversion uses int64(duration.Seconds()) which truncates and goes through float64. For sub-second inputs (e.g. 500ms), this becomes 0 and would be treated as a configured value rather than disabling/unsetting, which is likely unintended. Prefer integer math (e.g., round/ceil to whole seconds using time.Duration arithmetic) and decide explicitly how to handle durations < 1s and negative values.
| if lightSleepChanged && lightSleepDuration > 0 { | ||
| sid.SetLightSleepValue(int64(lightSleepDuration.Seconds())) | ||
| hasValue = true | ||
| } | ||
| if deepSleepChanged && deepSleepDuration > 0 { | ||
| sid.SetDeepSleepValue(int64(deepSleepDuration.Seconds())) | ||
| hasValue = true |
There was a problem hiding this comment.
Same truncation issue when creating a new SleepIdleDelay target: int64(duration.Seconds()) can produce 0 for positive sub-second durations and relies on float conversion. Use integer Duration arithmetic to compute whole seconds (ideally rounding/ceiling) so CLI inputs don’t silently turn into 0-second delays.
Sleep delays only apply to scale-to-zero services. Return a clear error when --light-sleep-delay or --deep-sleep-delay is used with min-scale > 0.
Summary
Adds two new CLI flags to configure light sleep and deep sleep idle delays for services:
--light-sleep-delay— Duration after which an idle service enters light sleep (e.g.,--light-sleep-delay 5m)--deep-sleep-delay— Duration after which an idle service enters deep sleep (e.g.,--deep-sleep-delay 30m)Set either to
0to disable that sleep mode.Available on
koyeb service createkoyeb service updatekoyeb deployExamples
Implementation
DeploymentScalingTargetSleepIdleDelay.LightSleepValue/DeepSleepValuein the APIkoyeb-api-client-goto pick up the newDeepSleepValueandLightSleepValuefieldssetScalingsTargetsTests
go test ./...passes ✅Resolves ENG-4890