Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 9aa7456

Browse files
authored
fix: added more detailed logging for scaling up and down (#1222)
Only log number of runners after cleanup, removed diff calculaton
1 parent 3c3ef19 commit 9aa7456

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Diff for: modules/runners/lambdas/runners/src/scale-runners/gh-auth.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createOctoClient, createGithubAppAuth, createGithubInstallationAuth } from './gh-auth';
1+
import { createOctoClient, createGithubAppAuth } from './gh-auth';
22
import nock from 'nock';
33
import { createAppAuth } from '@octokit/auth-app';
44

Diff for: modules/runners/lambdas/runners/src/scale-runners/scale-down.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async function evaluateAndRemoveRunners(
117117

118118
for (const ownerTag of ownerTags) {
119119
const ec2RunnersFiltered = ec2Runners.filter((runner) => runner.owner === ownerTag);
120+
console.debug(`Found: '${ec2RunnersFiltered.length}' active GitHub runners with owner tag: '${ownerTag}'`);
120121
for (const ec2Runner of ec2RunnersFiltered) {
121122
const ghRunners = await listGitHubRunners(ec2Runner);
122123
const ghRunner = ghRunners.find((runner) => runner.name === ec2Runner.instanceId);
@@ -190,15 +191,20 @@ export async function scaleDown(): Promise<void> {
190191

191192
// list and sort runners, newest first. This ensure we keep the newest runners longer.
192193
const ec2Runners = await listAndSortRunners(environment);
194+
const activeEc2RunnersCount = ec2Runners.length;
195+
console.info(`Found: '${activeEc2RunnersCount}' active GitHub EC2 runner instances before clean-up.`);
193196

194-
if (ec2Runners.length === 0) {
197+
if (activeEc2RunnersCount === 0) {
195198
console.debug(`No active runners found for environment: '${environment}'`);
196199
return;
197200
}
198201
const legacyRunners = filterLegacyRunners(ec2Runners);
199-
console.log(JSON.stringify(legacyRunners));
202+
console.debug(JSON.stringify(legacyRunners));
200203
const runners = filterRunners(ec2Runners);
201204

202205
await evaluateAndRemoveRunners(runners, scaleDownConfigs);
203206
await evaluateAndRemoveRunners(legacyRunners, scaleDownConfigs);
207+
208+
const activeEc2RunnersCountAfter = (await listAndSortRunners(environment)).length;
209+
console.info(`Found: '${activeEc2RunnersCountAfter}' active GitHub EC2 runners instances after clean-up.`);
204210
}

Diff for: modules/runners/lambdas/runners/src/scale-runners/scale-up.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ async function getJobStatus(githubInstallationClient: Octokit, payload: ActionRe
112112
export async function createRunnerLoop(runnerParameters: RunnerInputParameters): Promise<void> {
113113
const launchTemplateNames = process.env.LAUNCH_TEMPLATE_NAME?.split(',') as string[];
114114
let launched = false;
115-
for (const launchTemplateName of launchTemplateNames) {
116-
console.info(`Attempting to launch instance using ${launchTemplateName}.`);
115+
for (let i = 0; i < launchTemplateNames.length; i++) {
116+
console.info(`Attempt '${i}' to launch instance using ${launchTemplateNames[i]}.`);
117117
try {
118-
await createRunner(runnerParameters, launchTemplateName);
118+
await createRunner(runnerParameters, launchTemplateNames[i]);
119119
launched = true;
120120
break;
121121
} catch (error) {
122+
console.debug(`Attempt '${i}' to launch instance using ${launchTemplateNames[i]} FAILED.`);
122123
console.error(error);
123124
}
124125
}

0 commit comments

Comments
 (0)