Skip to content

runners: Add tests for scale-cycle #6896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions terraform-aws-github-runner/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ module "runners" {

retry_scale_up_chron_hud_query_url = var.retry_scale_up_chron_hud_query_url

enable_scale_cycle = var.enable_scale_cycle
scale_cycle_schedule_expression = var.scale_cycle_schedule_expression
lambda_timeout_scale_cycle = var.lambda_timeout_scale_cycle

must_have_issues_labels = var.must_have_issues_labels
cant_have_issues_labels = var.cant_have_issues_labels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
ScaleUpChronMetrics,
sendMetricsAtTimeout,
sendMetricsTimeoutVars,
ScaleCycleMetrics,
} from './scale-runners/metrics';
import { getDelayWithJitterRetryCount, stochaticRunOvershoot } from './scale-runners/utils';
import { scaleDown as scaleDownR } from './scale-runners/scale-down';
import { scaleUpChron as scaleUpChronR } from './scale-runners/scale-up-chron';
import { sqsSendMessages, sqsDeleteMessageBatch } from './scale-runners/sqs';
import { scaleCycle as scaleCycleR } from './scale-runners/scale-cycle';

async function sendRetryEvents(evtFailed: Array<[SQSRecord, boolean, number]>, metrics: ScaleUpMetrics) {
console.error(`Detected ${evtFailed.length} errors when processing messages, will retry relevant messages.`);
Expand Down Expand Up @@ -202,3 +204,38 @@ export async function scaleUpChron(event: ScheduledEvent, context: Context, call
}
callback(callbackOutput);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function scaleCycle(event: ScheduledEvent, context: Context, callback: any) {
// we mantain open connections to redis, so the event pool is only cleaned when the SIGTERM is sent
context.callbackWaitsForEmptyEventLoop = false;

const metrics = new ScaleCycleMetrics();
const sndMetricsTimout: sendMetricsTimeoutVars = {
metrics: metrics,
};
sndMetricsTimout.setTimeout = setTimeout(
sendMetricsAtTimeout(sndMetricsTimout),
(Config.Instance.lambdaTimeout - 10) * 1000,
);

let callbackOutput: string | null = null;

try {
await scaleCycleR(metrics);
} catch (e) {
console.error(e);
callbackOutput = `Failed to scale cycle: ${e}`;
} finally {
try {
clearTimeout(sndMetricsTimout.setTimeout);
sndMetricsTimout.metrics = undefined;
sndMetricsTimout.setTimeout = undefined;
await metrics.sendMetrics();
} catch (e) {
callbackOutput = `Error sending metrics: ${e}`;
}
}

callback(callbackOutput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1813,3 +1813,30 @@ export function sendMetricsAtTimeout(metricsTimeouts: sendMetricsTimeoutVars) {
}
};
}

export class ScaleCycleMetrics extends ScaleUpMetrics {
constructor() {
super('scaleCycle');
}

scaleCycleRunnerReuseFound(runnerType: string) {
const dimensions = new Map([['RunnerType', runnerType]]);
this.countEntry('run.scaleCycle.runnerReuse.found', 1, dimensions);
}

scaleCycleRunnerReuseFoundOrg(org: string, runnerType: string) {
const dimensions = new Map([
['Org', org],
['RunnerType', runnerType],
]);
this.countEntry('run.scaleCycle.runnerReuse.found.org', 1, dimensions);
}

scaleCycleRunnerReuseFoundRepo(repo: string, runnerType: string) {
const dimensions = new Map([
['Repo', repo],
['RunnerType', runnerType],
]);
this.countEntry('run.scaleCycle.runnerReuse.found.repo', 1, dimensions);
}
}
Loading
Loading