Skip to content

Commit f5a0388

Browse files
committed
fix: update logging messages for orphan runner tagging and state checks
1 parent e4a4bfa commit f5a0388

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ async function evaluateAndRemoveRunners(
206206
async function markOrphan(instanceId: string): Promise<void> {
207207
try {
208208
await tag(instanceId, [{ Key: 'ghr:orphan', Value: 'true' }]);
209-
logger.info(`Runner '${instanceId}' marked as orphan.`);
209+
logger.info(`Runner '${instanceId}' tagged as orphan.`);
210210
} catch (e) {
211-
logger.error(`Failed to mark runner '${instanceId}' as orphan.`, { error: e });
211+
logger.error(`Failed to tag runner '${instanceId}' as orphan.`, { error: e });
212212
}
213213
}
214214

215215
async function unmarkOrphan(instanceId: string): Promise<void> {
216216
try {
217217
await untag(instanceId, [{ Key: 'ghr:orphan', Value: 'true' }]);
218-
logger.info(`Runner '${instanceId}' unmarked as orphan.`);
218+
logger.info(`Runner '${instanceId}' untagged as orphan.`);
219219
} catch (e) {
220-
logger.error(`Failed to unmark runner '${instanceId}' as orphan.`, { error: e });
220+
logger.error(`Failed to un-tag runner '${instanceId}' as orphan.`, { error: e });
221221
}
222222
}
223223

@@ -227,11 +227,15 @@ async function lastChanceCheckOrphanRunner(runner: RunnerList): Promise<boolean>
227227
const ec2Instance = runner as RunnerInfo;
228228
const state = await getGitHubSelfHostedRunnerState(client, ec2Instance, runnerId);
229229
var isOrphan = false;
230-
logger.debug(`Runner is currently '${runner.instanceId}' state: ${JSON.stringify(state)}`);
231-
if (state.status === 'offline') {
230+
logger.debug(
231+
`Runner '${runner.instanceId}' is '${state.status}' and is currently '${state.busy ? 'busy' : 'idle'}'.`,
232+
);
233+
const isOfflineAndBusy = state.status === 'offline' && state.busy;
234+
if (isOfflineAndBusy) {
232235
isOrphan = true;
233236
}
234-
return isOrphan
237+
logger.info(`Runner '${runner.instanceId}' ${isOrphan ? 'is judged to be' : 'is judged to not be'} orphaned.`);
238+
return isOrphan;
235239
}
236240

237241
async function terminateOrphan(environment: string): Promise<void> {
@@ -240,7 +244,9 @@ async function terminateOrphan(environment: string): Promise<void> {
240244

241245
for (const runner of orphanRunners) {
242246
if (runner.runnerId) {
243-
await lastChanceCheckOrphanRunner(runner) ? terminateRunner(runner.instanceId) : unmarkOrphan(runner.instanceId);
247+
(await lastChanceCheckOrphanRunner(runner))
248+
? terminateRunner(runner.instanceId)
249+
: unmarkOrphan(runner.instanceId);
244250
} else {
245251
logger.info(`Terminating orphan runner '${runner.instanceId}'`);
246252
await terminateRunner(runner.instanceId).catch((e) => {

0 commit comments

Comments
 (0)