Skip to content

Commit 9665a59

Browse files
authored
runners: Fix lint (#6859)
There was some outstanding lint issues from previous PRs. Fixes the lint and formatting. Signed-off-by: Eli Uriegas <[email protected]>
1 parent fd736eb commit 9665a59

File tree

4 files changed

+16
-101
lines changed

4 files changed

+16
-101
lines changed

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
RunnerInputParameters,
33
createRunner,
44
findAmiID,
5-
getParameterNameForRunner,
65
listRunners,
76
listSSMParameters,
87
resetRunnersCaches,
@@ -1346,13 +1345,15 @@ describe('createRunner', () => {
13461345
// Verify the Policies parameter contains the correct expiration policy structure
13471346
const putParameterCall = mockSSM.putParameter.mock.calls[0][0];
13481347
const policies = JSON.parse(putParameterCall.Policies);
1349-
expect(policies).toEqual([{
1350-
Type: 'Expiration',
1351-
Version: '1.0',
1352-
Attributes: {
1353-
Timestamp: expect.any(String),
1348+
expect(policies).toEqual([
1349+
{
1350+
Type: 'Expiration',
1351+
Version: '1.0',
1352+
Attributes: {
1353+
Timestamp: expect.any(String),
1354+
},
13541355
},
1355-
}]);
1356+
]);
13561357

13571358
// Verify the timestamp is approximately 30 minutes in the future
13581359
const expirationTime = new Date(policies[0].Attributes.Timestamp);

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.ts

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ export interface DescribeInstancesResultRegion {
6161
describeInstanceResult: PromiseResult<EC2.Types.DescribeInstancesResult, AWS.AWSError>;
6262
}
6363

64-
const SHOULD_NOT_TRY_LIST_SSM = 'SHOULD_NOT_TRY_LIST_SSM';
65-
6664
// Keep the cache as long as half of minimum time, this should reduce calls to AWS API
6765
const ssmParametersCache = new LRU({ maxAge: (Config.Instance.minimumRunningTimeInMinutes * 60 * 1000) / 2 });
6866

@@ -357,7 +355,6 @@ export async function terminateRunners(runners: RunnerInfo[], metrics: Metrics):
357355

358356
async function terminateRunnersInRegion(runners: RunnerInfo[], metrics: Metrics, region: string): Promise<void> {
359357
const ec2 = new EC2({ region });
360-
const ssm = new SSM({ region });
361358

362359
// Keep track of runners that were successfully terminated so we can clean up their SSM parameters even
363360
// if a later batch fails.
@@ -411,87 +408,6 @@ async function terminateRunnersInRegion(runners: RunnerInfo[], metrics: Metrics,
411408
}
412409
}
413410

414-
async function cleanupSSMParametersForRunners(
415-
runners: RunnerInfo[],
416-
metrics: Metrics,
417-
region: string,
418-
ssm: SSM,
419-
): Promise<void> {
420-
const paramNames = runners.map((runner) =>
421-
getParameterNameForRunner(runner.environment || Config.Instance.environment, runner.instanceId),
422-
);
423-
424-
const cacheName = `${SHOULD_NOT_TRY_LIST_SSM}_${region}`;
425-
426-
if (ssmParametersCache.has(cacheName)) {
427-
// If we've had recent failures listing parameters, just try to delete them directly
428-
await deleteSSMParametersInBatches(paramNames, metrics, region, ssm);
429-
} else {
430-
try {
431-
const existingParams = await listSSMParameters(metrics, region);
432-
const paramsToDelete = paramNames.filter((paramName) => existingParams.has(paramName));
433-
434-
if (paramsToDelete.length > 0) {
435-
await deleteSSMParametersInBatches(paramsToDelete, metrics, region, ssm);
436-
} else {
437-
console.info(`[${region}] No SSM parameters found to delete for ${paramNames.length} runners`);
438-
}
439-
} catch (e) {
440-
ssmParametersCache.set(cacheName, 1, 60 * 1000);
441-
console.error(
442-
`[terminateRunnersInRegion - listSSMParameters] [${region}] ` +
443-
`Failed to list parameters, attempting direct deletion: ${e}`,
444-
);
445-
await deleteSSMParametersInBatches(paramNames, metrics, region, ssm);
446-
}
447-
}
448-
}
449-
450-
async function deleteSSMParametersInBatches(
451-
paramNames: string[],
452-
metrics: Metrics,
453-
region: string,
454-
ssm: SSM,
455-
): Promise<void> {
456-
const batches = chunkArray(paramNames, 10);
457-
458-
console.info(`[${region}] Processing ${paramNames.length} SSM parameters in ${batches.length} batch(es)`);
459-
460-
for (const [batchIndex, batch] of batches.entries()) {
461-
console.info(
462-
`[${region}] Processing SSM batch ${batchIndex + 1}/${batches.length} with ${
463-
batch.length
464-
} parameters: ${batch.join(', ')}`,
465-
);
466-
467-
try {
468-
await Promise.all(
469-
batch.map((paramName) =>
470-
expBackOff(() => {
471-
return metrics.trackRequestRegion(
472-
region,
473-
metrics.ssmdeleteParameterAWSCallSuccess,
474-
metrics.ssmdeleteParameterAWSCallFailure,
475-
() => {
476-
return ssm.deleteParameter({ Name: paramName }).promise();
477-
},
478-
);
479-
}),
480-
),
481-
);
482-
483-
console.info(
484-
`[${region}] Successfully deleted SSM batch ${batchIndex + 1}/${batches.length}: ${batch.join(', ')}`,
485-
);
486-
} catch (e) {
487-
console.error(
488-
`[${region}] Failed to delete SSM batch ${batchIndex + 1}/${batches.length}: ${batch.join(', ')} - ${e}`,
489-
);
490-
// Continue with other batches even if one fails
491-
}
492-
}
493-
}
494-
495411
function chunkArray<T>(array: T[], chunkSize: number): T[][] {
496412
const chunks: T[][] = [];
497413
for (let i = 0; i < array.length; i += chunkSize) {
@@ -537,13 +453,15 @@ async function addSSMParameterRunnerConfig(
537453
// NOTE: This does need to be a string, check docs at:
538454
// https://docs.aws.amazon.com/systems-manager/latest/userguide/example_ssm_PutParameter_section.html
539455
// Policies must be an array, even for a single policy
540-
Policies: JSON.stringify([{
541-
Type: 'Expiration',
542-
Version: '1.0',
543-
Attributes: {
544-
Timestamp: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
456+
Policies: JSON.stringify([
457+
{
458+
Type: 'Expiration',
459+
Version: '1.0',
460+
Attributes: {
461+
Timestamp: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
462+
},
545463
},
546-
}]),
464+
]),
547465
})
548466
.promise();
549467
return parameterName;

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/scale-down.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { Config } from './config';
55
import { resetSecretCache } from './gh-auth';
66
import { RunnerInfo, Repo } from './utils';
77
import {
8-
getRunnerOrg,
9-
getRunnerRepo,
108
getRunnerTypes,
119
GhRunner,
1210
GhRunners,

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import moment from 'moment';
22
import { Config } from './config';
33
import { resetSecretCache } from './gh-auth';
44
import {
5-
getRunnerOrg,
6-
getRunnerRepo,
75
getRunnerTypes,
86
GhRunner,
97
listGithubRunnersOrg,

0 commit comments

Comments
 (0)