Skip to content

Commit e05a043

Browse files
feat: Allow to disable runner max scaling check (#3849)
## Description Allow to disable to maximum runner check when max runners is set to -1 ## Background The maximum check is calling the AWS API describeInstances. When having a huge fleet of runners this call is expensive. Currently we have an issue with this API, this option allows to avoid calling the describeInstance API. Drawback is there will be nox safegouard for scaling. --------- Co-authored-by: forest-pr|bot <forest-pr[bot]@users.noreply.github.com>
1 parent 0c32047 commit e05a043

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

lambdas/functions/control-plane/src/scale-runners/scale-up.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ describe('scaleUp with GHES', () => {
241241
expect(mockOctokit.actions.createRegistrationTokenForRepo).not.toBeCalled();
242242
});
243243

244+
it('does create a runner if maximum is set to -1', async () => {
245+
process.env.RUNNERS_MAXIMUM_COUNT = '-1';
246+
process.env.ENABLE_EPHEMERAL_RUNNERS = 'false';
247+
await scaleUpModule.scaleUp('aws:sqs', TEST_DATA);
248+
expect(listEC2Runners).not.toHaveBeenCalled();
249+
expect(createRunner).toHaveBeenCalled();
250+
});
251+
244252
it('creates a token when maximum runners has not been reached', async () => {
245253
process.env.ENABLE_EPHEMERAL_RUNNERS = 'false';
246254
await scaleUpModule.scaleUp('aws:sqs', TEST_DATA);

lambdas/functions/control-plane/src/scale-runners/scale-up.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,18 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
277277
const ghAuth = await createGithubInstallationAuth(installationId, ghesApiUrl);
278278
const githubInstallationClient = await createOctoClient(ghAuth.token, ghesApiUrl);
279279
if (!enableJobQueuedCheck || (await isJobQueued(githubInstallationClient, payload))) {
280-
const currentRunners = await listEC2Runners({
281-
environment,
282-
runnerType,
283-
runnerOwner,
284-
});
285-
logger.info(`Current runners: ${currentRunners.length} of ${maximumRunners}`);
280+
let scaleUp = true;
281+
if (maximumRunners !== -1) {
282+
const currentRunners = await listEC2Runners({
283+
environment,
284+
runnerType,
285+
runnerOwner,
286+
});
287+
logger.info(`Current runners: ${currentRunners.length} of ${maximumRunners}`);
288+
scaleUp = currentRunners.length < maximumRunners;
289+
}
286290

287-
if (currentRunners.length < maximumRunners) {
291+
if (scaleUp) {
288292
logger.info(`Attempting to launch a new runner`);
289293

290294
await createRunners(

modules/multi-runner/README.md

+1-1
Large diffs are not rendered by default.

modules/multi-runner/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ variable "multi_runner_config" {
160160
runner_group_name: "Name of the runner group."
161161
runner_name_prefix: "Prefix for the GitHub runner name."
162162
runner_run_as: "Run the GitHub actions agent as user."
163-
runners_maximum_count: "The maximum number of runners that will be created."
163+
runners_maximum_count: "The maximum number of runners that will be created. Setting the variable to `-1` desiables the maximum check."
164164
scale_down_schedule_expression: "Scheduler expression to check every x for scale down."
165165
scale_up_reserved_concurrent_executions: "Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations."
166166
userdata_template: "Alternative user-data template, replacing the default template. By providing your own user_data you have to take care of installing all required software, including the action runner. Variables userdata_pre/post_install are ignored."

modules/runners/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ yarn run dist
204204
| <a name="input_runner_run_as"></a> [runner\_run\_as](#input\_runner\_run\_as) | Run the GitHub actions agent as user. | `string` | `"ec2-user"` | no |
205205
| <a name="input_runners_lambda_s3_key"></a> [runners\_lambda\_s3\_key](#input\_runners\_lambda\_s3\_key) | S3 key for runners lambda function. Required if using S3 bucket to specify lambdas. | `string` | `null` | no |
206206
| <a name="input_runners_lambda_s3_object_version"></a> [runners\_lambda\_s3\_object\_version](#input\_runners\_lambda\_s3\_object\_version) | S3 object version for runners lambda function. Useful if S3 versioning is enabled on source bucket. | `string` | `null` | no |
207-
| <a name="input_runners_maximum_count"></a> [runners\_maximum\_count](#input\_runners\_maximum\_count) | The maximum number of runners that will be created. | `number` | `3` | no |
207+
| <a name="input_runners_maximum_count"></a> [runners\_maximum\_count](#input\_runners\_maximum\_count) | The maximum number of runners that will be created. Setting the variable to `-1` desiables the maximum check. | `number` | `3` | no |
208208
| <a name="input_s3_runner_binaries"></a> [s3\_runner\_binaries](#input\_s3\_runner\_binaries) | Bucket details for cached GitHub binary. | <pre>object({<br> arn = string<br> id = string<br> key = string<br> })</pre> | n/a | yes |
209209
| <a name="input_scale_down_schedule_expression"></a> [scale\_down\_schedule\_expression](#input\_scale\_down\_schedule\_expression) | Scheduler expression to check every x for scale down. | `string` | `"cron(*/5 * * * ? *)"` | no |
210210
| <a name="input_scale_up_reserved_concurrent_executions"></a> [scale\_up\_reserved\_concurrent\_executions](#input\_scale\_up\_reserved\_concurrent\_executions) | Amount of reserved concurrent executions for the scale-up lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `number` | `1` | no |

modules/runners/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ variable "runner_run_as" {
288288
}
289289

290290
variable "runners_maximum_count" {
291-
description = "The maximum number of runners that will be created."
291+
description = "The maximum number of runners that will be created. Setting the variable to `-1` desiables the maximum check."
292292
type = number
293293
default = 3
294294
}

0 commit comments

Comments
 (0)