Skip to content

Commit

Permalink
fix(logging): Adjusting scale logging messages and levels (philips-la…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaulifn authored Oct 21, 2021
1 parent 5a758b5 commit 665e1a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function terminateRunner(instanceId: string): Promise<void> {
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<void> {
Expand Down
12 changes: 6 additions & 6 deletions modules/runners/lambdas/runners/src/scale-runners/scale-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async function listGitHubRunners(runner: RunnerInfo): Promise<GhRunners> {
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, {
Expand Down Expand Up @@ -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.`);
}
}

Expand All @@ -117,23 +117,23 @@ 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);
if (ghRunner) {
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.`);
Expand Down
9 changes: 6 additions & 3 deletions modules/runners/lambdas/runners/src/scale-runners/scale-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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 })
Expand All @@ -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.');
}
}
};
Expand All @@ -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;
}

Expand All @@ -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);
}
}
Expand Down

0 comments on commit 665e1a6

Please sign in to comment.