From 665e1a6aa30610584b863c99bb5dc4509c0f11df Mon Sep 17 00:00:00 2001 From: Nathaniel McAuliffe Date: Thu, 21 Oct 2021 16:41:58 -0400 Subject: [PATCH] fix(logging): Adjusting scale logging messages and levels (#1286) --- .../lambdas/runners/src/scale-runners/gh-auth.ts | 1 - .../lambdas/runners/src/scale-runners/runners.ts | 2 +- .../lambdas/runners/src/scale-runners/scale-down.ts | 12 ++++++------ .../lambdas/runners/src/scale-runners/scale-up.ts | 9 ++++++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts b/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts index 18f040468b..297edd0b27 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts @@ -52,7 +52,6 @@ async function createAuth(installationId: number | undefined, ghesApiUrl: string }; if (installationId) authOptions = { ...authOptions, installationId }; - console.debug(ghesApiUrl); if (ghesApiUrl) { authOptions.request = request.defaults({ baseUrl: ghesApiUrl, diff --git a/modules/runners/lambdas/runners/src/scale-runners/runners.ts b/modules/runners/lambdas/runners/src/scale-runners/runners.ts index e3892c1dab..cef470dc76 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/runners.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/runners.ts @@ -72,7 +72,7 @@ export async function terminateRunner(instanceId: string): Promise { InstanceIds: [instanceId], }) .promise(); - console.debug(`Runner ${instanceId} has been terminated.`); + console.info(`Runner ${instanceId} has been terminated.`); } export async function createRunner(runnerParameters: RunnerInputParameters, launchTemplateName: string): Promise { diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts index d949791d30..3bafa35182 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts @@ -51,8 +51,8 @@ async function listGitHubRunners(runner: RunnerInfo): Promise { return cachedRunners; } - const client = await getOrCreateOctokit(runner); console.debug(`[listGithubRunners] Cache miss for ${key}`); + const client = await getOrCreateOctokit(runner); const runners = runner.type === 'Org' ? await client.paginate(client.actions.listSelfHostedRunnersForOrg, { @@ -104,7 +104,7 @@ async function removeRunner(ec2runner: RunnerInfo, ghRunnerId: number): Promise< console.error(`Failed to de-register GitHub runner: ${result.status}`); } } catch (e) { - console.debug(`Runner '${ec2runner.instanceId}' cannot be de-registered, most likely the runner is active.`); + console.info(`Runner '${ec2runner.instanceId}' cannot be de-registered, most likely the runner is active.`); } } @@ -117,7 +117,7 @@ async function evaluateAndRemoveRunners( for (const ownerTag of ownerTags) { const ec2RunnersFiltered = ec2Runners.filter((runner) => runner.owner === ownerTag); - console.debug(`Found: '${ec2RunnersFiltered.length}' active GitHub runners with owner tag: '${ownerTag}'`); + console.info(`Found: '${ec2RunnersFiltered.length}' active GitHub runners with owner tag: '${ownerTag}'`); for (const ec2Runner of ec2RunnersFiltered) { const ghRunners = await listGitHubRunners(ec2Runner); const ghRunner = ghRunners.find((runner) => runner.name === ec2Runner.instanceId); @@ -125,15 +125,15 @@ async function evaluateAndRemoveRunners( if (runnerMinimumTimeExceeded(ec2Runner)) { if (idleCounter > 0) { idleCounter--; - console.debug(`Runner '${ec2Runner.instanceId}' will kept idle.`); + console.info(`Runner '${ec2Runner.instanceId}' will kept idle.`); } else { - console.debug(`Runner '${ec2Runner.instanceId}' will be terminated.`); + console.info(`Runner '${ec2Runner.instanceId}' will be terminated.`); await removeRunner(ec2Runner, ghRunner.id); } } } else { if (bootTimeExceeded(ec2Runner)) { - console.debug(`Runner '${ec2Runner.instanceId}' is orphaned and will be removed.`); + console.info(`Runner '${ec2Runner.instanceId}' is orphaned and will be removed.`); terminateOrphan(ec2Runner.instanceId); } else { console.debug(`Runner ${ec2Runner.instanceId} has not yet booted.`); diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts index 62e1f8a09e..33c7a81a68 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts @@ -20,6 +20,8 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage const environment = process.env.ENVIRONMENT; const ghesBaseUrl = process.env.GHES_URL; + console.info(`Received ${payload.eventType} from ${payload.repositoryOwner}/${payload.repositoryName}`); + let ghesApiUrl = ''; if (ghesBaseUrl) { ghesApiUrl = `${ghesBaseUrl}/api/v3`; @@ -58,6 +60,7 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage console.info(`${runnerType} ${runnerOwner} has ${currentRunners.length}/${maximumRunners} runners`); if (currentRunners.length < maximumRunners) { + console.info(`Attempting to launch a new runner`); // create token const registrationToken = enableOrgLevel ? await githubInstallationClient.actions.createRegistrationTokenForOrg({ org: payload.repositoryOwner }) @@ -81,7 +84,7 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage runnerType, }); } else { - console.info('No runner will be created, maximum number of runners reached.'); + console.warn('No runner created: maximum number of runners reached.'); } } }; @@ -105,7 +108,7 @@ async function getJobStatus(githubInstallationClient: Octokit, payload: ActionRe } else { throw Error(`Event ${payload.eventType} is not supported`); } - console.debug(`Job ${payload.id} is ${isQueued ? 'queued' : 'not queued'}`); + console.info(`Job ${payload.id} is ${isQueued ? 'queued' : 'not queued'}`); return isQueued; } @@ -119,7 +122,7 @@ export async function createRunnerLoop(runnerParameters: RunnerInputParameters): launched = true; break; } catch (error) { - console.debug(`Attempt '${i}' to launch instance using ${launchTemplateNames[i]} FAILED.`); + console.warn(`Attempt '${i}' to launch instance using ${launchTemplateNames[i]} FAILED.`); console.error(error); } }