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

Commit 9a84f7f

Browse files
authored
chore: improve logging in scale down lambda (#3954)
These changes make it easier to debug the scale down lambda to diagnose problems Signed-off-by: Brend Smits <[email protected]>
1 parent 5f9d9eb commit 9a84f7f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lambdas/functions/control-plane/src/aws/runners.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function getRunnerInfo(runningInstances: DescribeInstancesResult) {
9494
}
9595

9696
export async function terminateRunner(instanceId: string): Promise<void> {
97+
logger.info(`Runner '${instanceId}' will be terminated.`);
9798
const ec2 = getTracedAWSV3Client(new EC2Client({ region: process.env.AWS_REGION }));
9899
await ec2.send(new TerminateInstancesCommand({ InstanceIds: [instanceId] }));
99100
logger.info(`Runner ${instanceId} has been terminated.`);

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ async function listGitHubRunners(runner: RunnerInfo): Promise<GhRunners> {
8888
per_page: 100,
8989
});
9090
githubCache.runners.set(key, runners);
91-
91+
logger.debug(`[listGithubRunners] Cache set for ${key}`);
92+
logger.debug(`[listGithubRunners] Runners: ${JSON.stringify(runners)}`);
9293
return runners;
9394
}
9495

@@ -156,18 +157,25 @@ async function evaluateAndRemoveRunners(
156157
.filter((runner) => runner.owner === ownerTag)
157158
.sort(evictionStrategy === 'oldest_first' ? oldestFirstStrategy : newestFirstStrategy);
158159
logger.debug(`Found: '${ec2RunnersFiltered.length}' active GitHub runners with owner tag: '${ownerTag}'`);
160+
logger.debug(`Active GitHub runners with owner tag: '${ownerTag}': ${JSON.stringify(ec2RunnersFiltered)}`);
159161
for (const ec2Runner of ec2RunnersFiltered) {
160162
const ghRunners = await listGitHubRunners(ec2Runner);
161163
const ghRunnersFiltered = ghRunners.filter((runner: { name: string }) =>
162164
runner.name.endsWith(ec2Runner.instanceId),
163165
);
166+
logger.debug(
167+
`Found: '${ghRunnersFiltered.length}' GitHub runners for AWS runner instance: '${ec2Runner.instanceId}'`,
168+
);
169+
logger.debug(
170+
`GitHub runners for AWS runner instance: '${ec2Runner.instanceId}': ${JSON.stringify(ghRunnersFiltered)}`,
171+
);
164172
if (ghRunnersFiltered.length) {
165173
if (runnerMinimumTimeExceeded(ec2Runner)) {
166174
if (idleCounter > 0) {
167175
idleCounter--;
168176
logger.info(`Runner '${ec2Runner.instanceId}' will be kept idle.`);
169177
} else {
170-
logger.info(`Runner '${ec2Runner.instanceId}' will be terminated.`);
178+
logger.info(`Will try to terminate runners that are not busy`);
171179
await removeRunner(
172180
ec2Runner,
173181
ghRunnersFiltered.map((runner: { id: number }) => runner.id),
@@ -224,6 +232,7 @@ export async function scaleDown(): Promise<void> {
224232
const ec2Runners = await listRunners(environment);
225233
const activeEc2RunnersCount = ec2Runners.length;
226234
logger.info(`Found: '${activeEc2RunnersCount}' active GitHub EC2 runner instances before clean-up.`);
235+
logger.debug(`Active GitHub EC2 runner instances: ${JSON.stringify(ec2Runners)}`);
227236

228237
if (activeEc2RunnersCount === 0) {
229238
logger.debug(`No active runners found for environment: '${environment}'`);

0 commit comments

Comments
 (0)