Skip to content

Commit

Permalink
feat!: Remove old scale down mechanism (< 0.19.0) (#2519)
Browse files Browse the repository at this point in the history
Migration:
Option 1, upgrade to 2.x could cause orphan instances which will not be terminated by the scale-down function, thoses instances needs to be removed manual.
Option 2, upgrade first to a verions 1.x and keep this version running till all instances before the upgrade are terminated. Next upgrade to 2.x.
  • Loading branch information
npalm committed Dec 28, 2022
1 parent b06e038 commit 86a5d28
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('scaleDown', () => {

expect(mockOctokit.apps.getRepoInstallation).toBeCalledTimes(2);
expect(mockOctokit.apps.getOrgInstallation).toBeCalledTimes(1);
expect(terminateRunner).toBeCalledTimes(8);
expect(terminateRunner).toBeCalledTimes(7);
for (const toTerminate of RUNNERS_ALL_REMOVED) {
expect(terminateRunner).toHaveBeenCalledWith(toTerminate.instanceId);
}
Expand Down Expand Up @@ -558,7 +558,7 @@ describe('scaleDown', () => {

expect(mockOctokit.apps.getRepoInstallation).toBeCalledTimes(2);
expect(mockOctokit.apps.getOrgInstallation).toBeCalledTimes(1);
expect(terminateRunner).toBeCalledTimes(8);
expect(terminateRunner).toBeCalledTimes(7);
for (const toTerminate of RUNNERS_ALL_REMOVED) {
expect(terminateRunner).toHaveBeenCalledWith(toTerminate.instanceId);
}
Expand Down
20 changes: 1 addition & 19 deletions modules/runners/lambdas/runners/src/scale-runners/scale-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,6 @@ async function listAndSortRunners(environment: string) {
});
}

/**
* We are moving to a new strategy to find and remove runners, this function will ensure
* during migration runners tagged in the old way are removed.
*/
function filterLegacyRunners(ec2runners: RunnerList[]): RunnerInfo[] {
return ec2runners
.filter((ec2Runner) => ec2Runner.repo || ec2Runner.org)
.map((ec2Runner) => ({
instanceId: ec2Runner.instanceId,
launchTime: ec2Runner.launchTime,
type: ec2Runner.org ? 'Org' : 'Repo',
owner: ec2Runner.org ? (ec2Runner.org as string) : (ec2Runner.repo as string),
}));
}

function filterRunners(ec2runners: RunnerList[]): RunnerInfo[] {
return ec2runners.filter((ec2Runner) => ec2Runner.type) as RunnerInfo[];
}
Expand All @@ -256,12 +241,9 @@ export async function scaleDown(): Promise<void> {
logger.debug(`No active runners found for environment: '${environment}'`, LogFields.print());
return;
}
const legacyRunners = filterLegacyRunners(ec2Runners);
logger.debug(JSON.stringify(legacyRunners), LogFields.print());
const runners = filterRunners(ec2Runners);

const runners = filterRunners(ec2Runners);
await evaluateAndRemoveRunners(runners, scaleDownConfigs);
await evaluateAndRemoveRunners(legacyRunners, scaleDownConfigs);

const activeEc2RunnersCountAfter = (await listAndSortRunners(environment)).length;
logger.info(
Expand Down

0 comments on commit 86a5d28

Please sign in to comment.