Skip to content

Commit 4320575

Browse files
authored
Merge pull request #1575 from buildkite/SUP-3626-configurable-scheduled-scaling
Allow scheduled scale up/down actions for MinSize
2 parents bd07f94 + 7052bd1 commit 4320575

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,60 @@ To enable resource limits with custom values, include these parameters in your C
9292
- Resource limits are disabled by default
9393
- Values can be specified as percentages or absolute values (for memory-related parameters)
9494

95+
## Scheduled Scaling
96+
97+
The Elastic CI Stack supports time-based scaling to automatically adjust the minimum number of instances based on your team's working hours. This feature helps optimize costs by scaling down during off-hours while allowing users the ability to proactively scale up capacity ahead of expected increasing capacity requirements.
98+
99+
### Configuration Parameters
100+
101+
| Parameter | Description | Default |
102+
|--------------------------|------------------------------------------------------|----------------------|
103+
| `EnableScheduledScaling` | Enable scheduled scaling actions | `false` |
104+
| `ScheduleTimezone` | Timezone for scheduled actions | `UTC` |
105+
| `ScaleUpSchedule` | Cron expression for scaling up | `0 8 * * MON-FRI` |
106+
| `ScaleUpMinSize` | MinSize when scaling up | `1` |
107+
| `ScaleDownSchedule` | Cron expression for scaling down | `0 18 * * MON-FRI` |
108+
| `ScaleDownMinSize` | MinSize when scaling down | `0` |
109+
110+
### Example Configuration
111+
112+
To enable scheduled scaling that maintains a minimum of 10 ASG instances during business hours (8 AM - 6 PM, Eastern Time) and 2 ASG instances during off-hours:
113+
114+
```json
115+
{
116+
"Parameters": {
117+
"EnableScheduledScaling": "true",
118+
"ScheduleTimezone": "America/New_York",
119+
"ScaleUpSchedule": "0 8 * * MON-FRI",
120+
"ScaleUpMinSize": "10",
121+
"ScaleDownSchedule": "0 18 * * MON-FRI",
122+
"ScaleDownMinSize": "2"
123+
}
124+
}
125+
```
126+
127+
### Schedule Format
128+
129+
Scheduled scaling uses [AWS Auto Scaling cron expressions](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-cron) with the format:
130+
```
131+
minute hour day-of-month month day-of-week
132+
```
133+
134+
Common examples:
135+
- `0 8 * * MON-FRI` - 8:00 AM on weekdays
136+
- `0 18 * * MON-FRI` - 6:00 PM on weekdays
137+
- `0 9 * * SAT` - 9:00 AM on Saturdays
138+
- `30 7 * * 1-5` - 7:30 AM Monday through Friday (using numbers)
139+
140+
### Timezone Support
141+
142+
The `ScheduleTimezone` parameter supports [IANA timezone names](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-timezone) such as:
143+
- `America/New_York` (Eastern Time)
144+
- `America/Los_Angeles` (Pacific Time)
145+
- `Europe/London` (Greenwich Mean Time)
146+
- `Asia/Tokyo` (Japan Standard Time)
147+
- `UTC` (Coordinated Universal Time)
148+
95149
## Development
96150

97151
To get started with customizing your own stack, or contributing fixes and features:

templates/aws-stack.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ Metadata:
129129
- ScalerEventSchedulePeriod
130130
- ScalerMinPollInterval
131131
- ScalerEnableExperimentalElasticCIMode
132+
- EnableScheduledScaling
133+
- ScheduleTimezone
134+
- ScaleUpSchedule
135+
- ScaleUpMinSize
136+
- ScaleDownSchedule
137+
- ScaleDownMinSize
132138

133139
- Label:
134140
default: Cost Allocation Configuration
@@ -230,6 +236,45 @@ Parameters:
230236
- "false"
231237
Default: "false"
232238

239+
EnableScheduledScaling:
240+
Description: Enable scheduled scaling to automatically adjust MinSize based on time-based schedules
241+
Type: String
242+
AllowedValues:
243+
- "true"
244+
- "false"
245+
Default: "false"
246+
247+
ScheduleTimezone:
248+
Description: "Timezone for scheduled scaling actions (only used when EnableScheduledScaling is true). See AWS documentation for supported formats: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-timezone (America/New_York, UTC, Europe/London, etc.)"
249+
Type: String
250+
Default: "UTC"
251+
252+
ScaleUpSchedule:
253+
Description: "Cron expression for when to scale up (only used when EnableScheduledScaling is true). See AWS documentation for format details: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-cron (\"0 8 * * MON-FRI\" for 8 AM weekdays)"
254+
Type: String
255+
Default: "0 8 * * MON-FRI"
256+
AllowedPattern: '^[0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9A-Za-z*,-/]+$'
257+
ConstraintDescription: "Must be a valid cron expression (5 fields: minute hour day-of-month month day-of-week)"
258+
259+
ScaleUpMinSize:
260+
Description: MinSize to set when the ScaleUpSchedule is triggered (applied at the time specified in ScaleUpSchedule, only used when EnableScheduledScaling is true). Cannot exceed MaxSize.
261+
Type: Number
262+
Default: 1
263+
MinValue: 0
264+
265+
ScaleDownSchedule:
266+
Description: "Cron expression for when to scale down (only used when EnableScheduledScaling is true). See AWS documentation for format details: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-cron (\"0 18 * * MON-FRI\" for 6 PM weekdays)"
267+
Type: String
268+
Default: "0 18 * * MON-FRI"
269+
AllowedPattern: '^[0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9A-Za-z*,-/]+$'
270+
ConstraintDescription: "Must be a valid cron expression (5 fields: minute hour day-of-month month day-of-week)"
271+
272+
ScaleDownMinSize:
273+
Description: MinSize to set when the ScaleDownSchedule is triggered (applied at the time specified in ScaleDownSchedule, only used when EnableScheduledScaling is true)
274+
Type: Number
275+
Default: 0
276+
MinValue: 0
277+
233278
ScaleOutCooldownPeriod:
234279
Description: Cooldown period in seconds before allowing another scale-out event
235280
Type: Number
@@ -1130,6 +1175,9 @@ Conditions:
11301175
- !Equals [ !Ref RootVolumeType, "io2" ]
11311176
- !Equals [ !Ref RootVolumeType, "gp3" ]
11321177

1178+
EnableScheduledScaling:
1179+
!Equals [ !Ref EnableScheduledScaling, "true" ]
1180+
11331181
Mappings:
11341182
ECRManagedPolicy:
11351183
none : { Policy: '' }
@@ -1992,6 +2040,26 @@ Resources:
19922040
AutoScalingReplacingUpdate:
19932041
WillReplace: true
19942042

2043+
ScheduledScaleUpAction:
2044+
Condition: EnableScheduledScaling
2045+
Type: AWS::AutoScaling::ScheduledAction
2046+
Properties:
2047+
AutoScalingGroupName: !Ref AgentAutoScaleGroup
2048+
ScheduledActionName: !Sub "${AWS::StackName}-ScaleUp"
2049+
Recurrence: !Ref ScaleUpSchedule
2050+
MinSize: !Ref ScaleUpMinSize
2051+
TimeZone: !Ref ScheduleTimezone
2052+
2053+
ScheduledScaleDownAction:
2054+
Condition: EnableScheduledScaling
2055+
Type: AWS::AutoScaling::ScheduledAction
2056+
Properties:
2057+
AutoScalingGroupName: !Ref AgentAutoScaleGroup
2058+
ScheduledActionName: !Sub "${AWS::StackName}-ScaleDown"
2059+
Recurrence: !Ref ScaleDownSchedule
2060+
MinSize: !Ref ScaleDownMinSize
2061+
TimeZone: !Ref ScheduleTimezone
2062+
19952063
AsgProcessSuspenderRole:
19962064
Type: AWS::IAM::Role
19972065
Properties:

0 commit comments

Comments
 (0)