Skip to content

Commit b98f8bd

Browse files
feat: Add workflow URL to EC2 instance tags
1 parent 9983655 commit b98f8bd

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ export interface RunnerInputParameters {
4343
amiIdSsmParameterName?: string;
4444
tracingEnabled?: boolean;
4545
onDemandFailoverOnError?: string[];
46+
workflowUrl?: string;
4647
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ async function createInstances(
244244
tags.push({ Key: 'ghr:trace_id', Value: traceId! });
245245
}
246246

247+
if (runnerParameters.workflowUrl) {
248+
tags.push({ Key: 'ghr:workflow_url', Value: runnerParameters.workflowUrl });
249+
}
250+
247251
let fleet: CreateFleetResult;
248252
try {
249253
// see for spec https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateFleet.html

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface ActionRequestMessage {
3131
installationId: number;
3232
repoOwnerType: string;
3333
retryCounter?: number;
34+
workflowUrl?: string;
3435
}
3536

3637
export interface ActionRequestMessageRetry extends ActionRequestMessage {
@@ -49,6 +50,7 @@ interface CreateGitHubRunnerConfig {
4950
disableAutoUpdate: boolean;
5051
ssmTokenPath: string;
5152
ssmConfigPath: string;
53+
jobId?: number;
5254
}
5355

5456
interface CreateEC2RunnerConfig {
@@ -60,6 +62,7 @@ interface CreateEC2RunnerConfig {
6062
amiIdSsmParameterName?: string;
6163
tracingEnabled?: boolean;
6264
onDemandFailoverOnError?: string[];
65+
workflowUrl?: string;
6366
}
6467

6568
function generateRunnerServiceConfig(githubRunnerConfig: CreateGitHubRunnerConfig, token: string) {
@@ -217,6 +220,7 @@ export async function createRunners(
217220
runnerType: githubRunnerConfig.runnerType,
218221
runnerOwner: githubRunnerConfig.runnerOwner,
219222
numberOfRunners: 1,
223+
githubJobId: githubRunnerConfig.jobId?.toString(),
220224
...ec2RunnerConfig,
221225
});
222226
if (instances.length !== 0) {
@@ -225,7 +229,7 @@ export async function createRunners(
225229
}
226230

227231
export async function scaleUp(eventSource: string, payload: ActionRequestMessage): Promise<void> {
228-
logger.info(`Received ${payload.eventType} from ${payload.repositoryOwner}/${payload.repositoryName}`);
232+
logger.info(`Received ${payload.eventType} from ${payload.repositoryOwner}/${payload.repositoryName} Workflow URL: ${payload.workflowUrl}`);
229233

230234
if (eventSource !== 'aws:sqs') throw Error('Cannot handle non-SQS events!');
231235
const enableOrgLevel = yn(process.env.ENABLE_ORGANIZATION_RUNNERS, { default: true });
@@ -321,6 +325,7 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
321325
disableAutoUpdate,
322326
ssmTokenPath,
323327
ssmConfigPath,
328+
jobId: payload.id,
324329
},
325330
{
326331
ec2instanceCriteria: {
@@ -335,6 +340,7 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
335340
amiIdSsmParameterName,
336341
tracingEnabled,
337342
onDemandFailoverOnError,
343+
workflowUrl: payload.workflowUrl,
338344
},
339345
githubInstallationClient,
340346
);

lambdas/functions/webhook/src/runners/dispatch.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ async function handleWorkflowJob(
3737
});
3838
for (const queue of matcherConfig) {
3939
if (canRunJob(body.workflow_job.labels, queue.matcherConfig.labelMatchers, queue.matcherConfig.exactMatch)) {
40-
await sendActionRequest({
40+
const actionRequest = {
4141
id: body.workflow_job.id,
4242
repositoryName: body.repository.name,
4343
repositoryOwner: body.repository.owner.login,
4444
eventType: githubEvent,
4545
installationId: body.installation?.id ?? 0,
4646
queueId: queue.id,
4747
repoOwnerType: body.repository.owner.type,
48-
});
48+
workflowUrl: body.workflow_job.run_url,
49+
}
50+
logger.info(`Action request: ${JSON.stringify(actionRequest)}`)
51+
await sendActionRequest(actionRequest);
52+
4953
logger.info(`Successfully dispatched job for ${body.repository.full_name} to the queue ${queue.id}`);
5054
return {
5155
statusCode: 201,

lambdas/functions/webhook/src/sqs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ActionRequestMessage {
1212
installationId: number;
1313
queueId: string;
1414
repoOwnerType: string;
15+
workflowUrl?: string;
1516
}
1617

1718
export interface MatcherConfig {

0 commit comments

Comments
 (0)