diff --git a/lambdas/functions/control-plane/src/pool/pool.test.ts b/lambdas/functions/control-plane/src/pool/pool.test.ts index ee41d77b41..a3e199d7c1 100644 --- a/lambdas/functions/control-plane/src/pool/pool.test.ts +++ b/lambdas/functions/control-plane/src/pool/pool.test.ts @@ -3,7 +3,7 @@ import moment from 'moment-timezone'; import * as nock from 'nock'; import { createRunners } from '@aws-github-runner/compute-providers/aws/ec2/control-plane/runner-config'; -import { listEC2Runners } from '@aws-github-runner/compute-providers/aws/ec2/control-plane/runners'; +import { listEC2Runners } from '@aws-github-runner/compute-providers/aws/ec2/runners'; import * as ghAuth from '../github/auth'; import { getGitHubEnterpriseApiUrl } from '../scale-runners/github-runner'; import { adjust } from './pool'; @@ -26,7 +26,7 @@ vi.mock('@octokit/rest', () => ({ }), })); -vi.mock('@aws-github-runner/compute-providers/aws/ec2/control-plane/runners', async () => ({ +vi.mock('@aws-github-runner/compute-providers/aws/ec2/runners', async () => ({ listEC2Runners: vi.fn(), // Include any other functions from the module that might be used bootTimeExceeded: vi.fn(), diff --git a/lambdas/functions/control-plane/src/scale-runners/types.ts b/lambdas/functions/control-plane/src/scale-runners/types.ts index 38e7063231..de81ba0bc7 100644 --- a/lambdas/functions/control-plane/src/scale-runners/types.ts +++ b/lambdas/functions/control-plane/src/scale-runners/types.ts @@ -3,7 +3,7 @@ export type { CreateRunnerResult, CreateScaleUpRunnersInput, CurrentRunnersInput, - LambdaRunnerSource, + RunnerSource, RunnerLabelResolution, RunnerInfo, RunnerType, diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/dynamic-labels.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/dynamic-labels.ts index d3e31a74f9..8de7882e24 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/dynamic-labels.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/dynamic-labels.ts @@ -32,7 +32,7 @@ import { } from '@aws-sdk/client-ec2'; import { getTracedAWSV3Client } from '@aws-github-runner/aws-powertools-util'; -import { Ec2OverrideConfig } from './runners.d'; +import { Ec2OverrideConfig } from '../runners.d'; const EC2_OVERRIDE_LIST_VALUE_SEPARATOR = ';'; diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.test.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.test.ts index 5cc7797b0c..148da04d93 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.test.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.test.ts @@ -1,9 +1,9 @@ import type { RunnerInfo } from '../../../../core'; -import { bootTimeExceeded } from './runners'; +import { bootTimeExceeded } from '../runners'; import { calculateEc2PoolSize } from './pool'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -vi.mock('./runners', () => ({ +vi.mock('../runners', () => ({ bootTimeExceeded: vi.fn(), })); diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.ts index 4e8e813a13..d1d243ca51 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/pool.ts @@ -8,7 +8,7 @@ import type { RunnerStatus, } from '../../../../core'; import { createRunners, loadEc2ProviderConfig } from './runner-config'; -import { bootTimeExceeded, listEC2Runners } from './runners'; +import { bootTimeExceeded, listEC2Runners } from '../runners'; const logger = createChildLogger('pool'); diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runner-config.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runner-config.ts index bdc46b8c44..34f95aaf97 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runner-config.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runner-config.ts @@ -4,15 +4,15 @@ import type { CreateRunnerResult, CreateStartRunnerConfig, GitHubRunnerMetadata, - LambdaRunnerSource, + RunnerSource, StartRunnerConfigOptions, } from '../../../../core'; import { Octokit } from '@octokit/rest'; import type { Tag } from '@aws-sdk/client-ec2'; import yn from 'yn'; -import { createRunner, tag, terminateRunner } from './runners'; -import type { RunnerInputParameters } from './runners.d'; +import { createRunner, tag, terminateRunner } from '../runners'; +import type { RunnerInputParameters } from '../runners.d'; const logger = createChildLogger('ec2-runners'); const RUNNER_LABELS_TAG_KEY = 'ghr:runner_labels'; @@ -66,7 +66,7 @@ export async function createRunners( numberOfRunners: number, ghClient: Octokit, createStartRunnerConfig: CreateStartRunnerConfig, - source: LambdaRunnerSource = 'scale-up-lambda', + source: RunnerSource, ): Promise { let result: CreateRunnerResult; try { diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.test.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.test.ts index 85ced04010..f122f3b3a0 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.test.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.test.ts @@ -2,10 +2,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import type { RunnerInfo, RunnerType } from '../../../../core'; import { createEc2ScaleDownProvider } from './scale-down'; -import { listEC2Runners, tag, terminateRunner, untag } from './runners'; +import { listEC2Runners, tag, terminateRunner, untag } from '../runners'; -vi.mock('./runners', async (importOriginal) => { - const actual = await importOriginal(); +vi.mock('../runners', async (importOriginal) => { + const actual = await importOriginal(); return { ...actual, listEC2Runners: vi.fn(), diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.ts index 55d52ac298..3084eebe21 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-down.ts @@ -1,5 +1,5 @@ import type { RunnerInfo, ScaleDownComputeProvider } from '../../../../core'; -import { bootTimeExceeded, listEC2Runners, tag, terminateRunner, untag } from './runners'; +import { bootTimeExceeded, listEC2Runners, tag, terminateRunner, untag } from '../runners'; async function listEc2ScaleDownRunners(environment: string, orphan?: boolean): Promise { return await listEC2Runners({ environment, orphan }); diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.test.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.test.ts index 0c6bac69f4..1a967fc4cc 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.test.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.test.ts @@ -7,11 +7,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { parseEc2OverrideConfig } from './dynamic-labels'; import { EC2_TAG_VALUE_MAX_LENGTH, RUNNER_LABELS_TAG_MAX_COUNT } from './runner-config'; -import { createRunner, listEC2Runners, tag, terminateRunner } from './runners'; -import type { RunnerInputParameters } from './runners.d'; +import { createRunner, listEC2Runners, tag, terminateRunner } from '../runners'; +import type { RunnerInputParameters } from '../runners.d'; import { createEc2ScaleUpProvider } from './scale-up'; -vi.mock('./runners', () => ({ +vi.mock('../runners', () => ({ createRunner: vi.fn(), listEC2Runners: vi.fn(), tag: vi.fn(), diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.ts b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.ts index d72edaf7a4..6bebaa31ba 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/control-plane/scale-up.ts @@ -9,8 +9,8 @@ import type { } from '../../../../core'; import yn from 'yn'; -import { listEC2Runners } from './runners'; -import type { Ec2OverrideConfig } from './runners.d'; +import { listEC2Runners } from '../runners'; +import type { Ec2OverrideConfig } from '../runners.d'; import { getDefaultBlockDeviceNameFromLaunchTemplate, parseEc2OverrideConfig, diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.d.ts b/lambdas/libs/compute-providers/aws/ec2/src/runners.d.ts similarity index 91% rename from lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.d.ts rename to lambdas/libs/compute-providers/aws/ec2/src/runners.d.ts index 82d5610bb6..dcec4b9b62 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.d.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/runners.d.ts @@ -7,7 +7,7 @@ import { Placement, FleetBlockDeviceMappingRequest, } from '@aws-sdk/client-ec2'; -import type { LambdaRunnerSource, ListRunnerFilters, RunnerType } from '../../../../core'; +import type { ListRunnerFilters, RunnerSource, RunnerType } from '../../../core'; export interface Ec2ListRunnerFilters extends ListRunnerFilters { statuses?: string[]; @@ -42,7 +42,7 @@ export interface RunnerInputParameters { }; ec2OverrideConfig?: Ec2OverrideConfig; numberOfRunners: number; - source: LambdaRunnerSource; + source: RunnerSource; amiIdSsmParameterName?: string; tracingEnabled?: boolean; onDemandFailoverOnError?: string[]; diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.test.ts b/lambdas/libs/compute-providers/aws/ec2/src/runners.test.ts similarity index 99% rename from lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.test.ts rename to lambdas/libs/compute-providers/aws/ec2/src/runners.test.ts index 738c6da13d..affd063c39 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.test.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/runners.test.ts @@ -21,7 +21,7 @@ import { mockClient } from 'aws-sdk-client-mock'; import 'aws-sdk-client-mock-jest/vitest'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import type { LambdaRunnerSource, RunnerInfo, RunnerType } from '../../../../core'; +import type { RunnerInfo, RunnerSource, RunnerType } from '../../../core'; import { createRunner, listEC2Runners, tag, terminateRunner, untag } from './runners'; import type { Ec2OverrideConfig, RunnerInputParameters } from './runners.d'; @@ -371,7 +371,7 @@ describe('create runner', () => { }); }); - it('calls create fleet of multiple instances with pool-lambda source when specified', async () => { + it('calls create fleet of multiple instances with pool source when specified', async () => { const instances = [{ InstanceIds: ['i-1234', 'i-5678', 'i-9012'] }]; mockEC2Client.on(CreateFleetCommand).resolves({ Instances: instances }); @@ -1170,7 +1170,7 @@ interface RunnerConfig { tracingEnabled?: boolean; onDemandFailoverOnError?: string[]; scaleErrors: string[]; - source: LambdaRunnerSource; + source: RunnerSource; useDedicatedHost?: boolean; ec2OverrideConfig?: Ec2OverrideConfig; } @@ -1209,7 +1209,7 @@ interface ExpectedFleetRequestValues { totalTargetCapacity: number; imageId?: string; tracingEnabled?: boolean; - source: LambdaRunnerSource; + source: RunnerSource; } function expectedCreateFleetRequest(expectedValues: ExpectedFleetRequestValues): CreateFleetCommandInput { @@ -1318,6 +1318,7 @@ describe('create runner with useDedicatedHost', () => { const dedicatedHostRunnerConfig: RunnerConfig = { allocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED, capacityType: 'on-demand', + source: 'scale-up-lambda', type: 'Org', scaleErrors: [], useDedicatedHost: true, @@ -1411,7 +1412,7 @@ describe('create runner with useDedicatedHost', () => { }); }); - it('creates multiple instances via RunInstances', async () => { + it('creates multiple instances via RunInstances and preserves the caller source', async () => { mockEC2Client.on(RunInstancesCommand).resolves({ Instances: [{ InstanceId: 'i-dedicated-1' }, { InstanceId: 'i-dedicated-2' }], }); @@ -1419,6 +1420,7 @@ describe('create runner with useDedicatedHost', () => { const result = await createRunner({ ...createRunnerConfig(dedicatedHostRunnerConfig), numberOfRunners: 2, + source: 'scale-up-lambda', }); expect(result).toEqual({ @@ -1440,7 +1442,7 @@ describe('create runner with useDedicatedHost', () => { ResourceType: 'instance', Tags: [ { Key: 'ghr:Application', Value: 'github-action-runner' }, - { Key: 'ghr:created_by', Value: 'pool-lambda' }, + { Key: 'ghr:created_by', Value: 'scale-up-lambda' }, { Key: 'ghr:Type', Value: 'Org' }, { Key: 'ghr:Owner', Value: REPO_NAME }, ], @@ -1449,7 +1451,7 @@ describe('create runner with useDedicatedHost', () => { ResourceType: 'volume', Tags: [ { Key: 'ghr:Application', Value: 'github-action-runner' }, - { Key: 'ghr:created_by', Value: 'pool-lambda' }, + { Key: 'ghr:created_by', Value: 'scale-up-lambda' }, { Key: 'ghr:Type', Value: 'Org' }, { Key: 'ghr:Owner', Value: REPO_NAME }, ], diff --git a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.ts b/lambdas/libs/compute-providers/aws/ec2/src/runners.ts similarity index 99% rename from lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.ts rename to lambdas/libs/compute-providers/aws/ec2/src/runners.ts index 050804cce1..4e187437ec 100644 --- a/lambdas/libs/compute-providers/aws/ec2/src/control-plane/runners.ts +++ b/lambdas/libs/compute-providers/aws/ec2/src/runners.ts @@ -22,7 +22,7 @@ import { getTracedAWSV3Client, tracer } from '@aws-github-runner/aws-powertools- import { getParameter } from '@aws-github-runner/aws-ssm-util'; import moment from 'moment'; -import type { CreateRunnerResult, RunnerInfo } from '../../../../core'; +import type { CreateRunnerResult, RunnerInfo } from '../../../core'; import type { Ec2ListRunnerFilters, Ec2OverrideConfig, RunnerInputParameters } from './runners.d'; const logger = createChildLogger('runners'); @@ -584,7 +584,7 @@ async function createInstancesWithRunInstances( ): Promise { const tags = [ { Key: 'ghr:Application', Value: 'github-action-runner' }, - { Key: 'ghr:created_by', Value: runnerParameters.numberOfRunners === 1 ? 'scale-up-lambda' : 'pool-lambda' }, + { Key: 'ghr:created_by', Value: runnerParameters.source }, { Key: 'ghr:Type', Value: runnerParameters.runnerType }, { Key: 'ghr:Owner', Value: runnerParameters.runnerOwner }, ]; diff --git a/lambdas/libs/compute-providers/core/index.ts b/lambdas/libs/compute-providers/core/index.ts index 2b5f937f36..c5560942fa 100644 --- a/lambdas/libs/compute-providers/core/index.ts +++ b/lambdas/libs/compute-providers/core/index.ts @@ -6,7 +6,7 @@ export interface ComputeProvider { type: ComputeProviderType; } -export type LambdaRunnerSource = 'scale-up-lambda' | 'pool-lambda'; +export type RunnerSource = 'scale-up-lambda' | 'pool-lambda'; export type RunnerType = 'Org' | 'Repo'; export interface CreateGitHubRunnerConfig { diff --git a/lambdas/libs/compute-providers/package.json b/lambdas/libs/compute-providers/package.json index 9d39fd294a..554b4abdbf 100644 --- a/lambdas/libs/compute-providers/package.json +++ b/lambdas/libs/compute-providers/package.json @@ -10,7 +10,7 @@ "./control-plane": "./control-plane.ts", "./aws/ec2/webhook": "./aws/ec2/webhook.ts", "./aws/ec2/control-plane": "./aws/ec2/control-plane.ts", - "./aws/ec2/control-plane/runners": "./aws/ec2/src/control-plane/runners.ts", + "./aws/ec2/runners": "./aws/ec2/src/runners.ts", "./aws/ec2/control-plane/runner-config": "./aws/ec2/src/control-plane/runner-config.ts" }, "type": "module",