Skip to content

Commit

Permalink
fix: add logging context to runner lambda (#1399)
Browse files Browse the repository at this point in the history
* fix(logging): Add context to scale logs

Signed-off-by: Nathaniel McAuliffe <nmcauliffe@expediagroup.com>

* Remove testing

Signed-off-by: Nathaniel McAuliffe <nmcauliffe@expediagroup.com>

* Remove unnecessary import

Signed-off-by: Nathaniel McAuliffe <nmcauliffe@expediagroup.com>

* Moving log fields to end, adjusting format
  • Loading branch information
npalm committed Dec 22, 2021
1 parent 5fb7237 commit b6b4fa3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions modules/runners/lambdas/runners/src/scale-runners/scale-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { listEC2Runners, createRunner, RunnerInputParameters } from './runners';
import { createOctoClient, createGithubAppAuth, createGithubInstallationAuth } from './gh-auth';
import yn from 'yn';
import { Octokit } from '@octokit/rest';
import { logger as rootLogger, LogFields } from './logger';
import { LogFields, logger as rootLogger } from './logger';
import ScaleError from './ScaleError';

const logger = rootLogger.getChildLogger({ name: 'scale-up' });
Expand All @@ -27,7 +27,6 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
const ghesBaseUrl = process.env.GHES_URL;
const ephemeralEnabled = yn(process.env.ENABLE_EPHEMERAL_RUNNERS, { default: false });

// TODO: handle case event is check_run and ephemeralEnabled = true
if (ephemeralEnabled && payload.eventType != 'workflow_job') {
logger.warn(`${payload.eventType} even is not supported in combination with ephemeral runners.`);
throw Error(
Expand All @@ -36,6 +35,16 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
);
}
const ephemeral = ephemeralEnabled && payload.eventType === 'workflow_job';
const runnerType = enableOrgLevel ? 'Org' : 'Repo';
const runnerOwner = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;

LogFields.fields = {};
LogFields.fields.runnerType = runnerType;
LogFields.fields.runnerOwner = runnerOwner;
LogFields.fields.event = payload.eventType;
LogFields.fields.id = payload.id.toString();

logger.info(`Received event`, LogFields.print());

const runnerType = enableOrgLevel ? 'Org' : 'Repo';
const runnerOwner = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;
Expand Down

0 comments on commit b6b4fa3

Please sign in to comment.