Skip to content

Commit

Permalink
Merge pull request #2464 from artilleryio/hassy-art-1611-add-support-…
Browse files Browse the repository at this point in the history
…for-running-on-fargate-spot-capacity-providers
  • Loading branch information
hassy committed Feb 3, 2024
2 parents 5e061cf + bd46bfa commit 35f0e1c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/artillery/lib/cmds/run-fargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ RunCommand.flags = {
description: 'The launch type to use for the test. Defaults to Fargate.',
options: ['ecs:fargate', 'ecs:ec2']
}),
spot: Flags.boolean({
description:
'Use Fargate Spot (https://docs.art/fargate-spot) Ignored when --launch-type is set to ecs:ec2'
}),
'launch-config': Flags.string({
description:
'JSON to customize launch configuration of ECS/Fargate tasks (see https://www.artillery.io/docs/reference/cli/run-fargate#using---launch-config)'
Expand Down
34 changes: 28 additions & 6 deletions packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {
logGroupName: LOGGROUP_NAME,
cliOptions: options,
isFargate: IS_FARGATE,
isCapacitySpot: typeof options.spot !== 'undefined',
configTableName: '',
status: TEST_RUN_STATUS.INITIALIZING,
packageJsonPath,
Expand Down Expand Up @@ -631,7 +632,9 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {
Region: ${context.region}
Count: ${context.count}
Cluster: ${context.clusterName}
Launch type: ${context.cliOptions.launchType}
Launch type: ${context.cliOptions.launchType} ${
context.isFargate && context.isCapacitySpot ? '(Spot)' : '(On-demand)'
}
`,
{ showTimestamp: false }
);
Expand Down Expand Up @@ -778,9 +781,7 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {
.indexOf('no container instances were found') !== -1
) {
artillery.log(
chalk.yellow(
'The cluster has no active instances. We need some instances.'
)
chalk.yellow('The ECS cluster has no active EC2 instances')
);
} else {
artillery.log(err);
Expand Down Expand Up @@ -900,7 +901,7 @@ async function createArtilleryCluster(context) {
await ecs
.createCluster({
clusterName: ARTILLERY_CLUSTER_NAME,
capacityProviders: ['FARGATE']
capacityProviders: ['FARGATE_SPOT']
})
.promise();

Expand Down Expand Up @@ -1145,8 +1146,15 @@ async function ensureTaskExists(context) {
],
executionRoleArn: context.taskRoleArn
};

context.taskDefinition = taskDefinition;

if (!context.isFargate) {
// Limits for sidecar have to be set explicitly on ECS EC2
taskDefinition.containerDefinitions[1].memory = 1024;
taskDefinition.containerDefinitions[1].cpu = 1024;
}

if (context.isFargate) {
taskDefinition.networkMode = 'awsvpc';
taskDefinition.requiresCompatibilities = ['FARGATE'];
Expand Down Expand Up @@ -1466,9 +1474,20 @@ async function setupDefaultECSParams(context) {
};

if (context.isFargate) {
if (context.isCapacitySpot) {
defaultParams.capacityProviderStrategy = [
{
capacityProvider: 'FARGATE_SPOT',
weight: 1,
base: 0
}
];
} else {
// On-demand capacity
defaultParams.launchType = 'FARGATE';
}
// Networking config: private subnets of the VPC that the ECS cluster
// is in. Don't need public subnets.
defaultParams.launchType = 'FARGATE';
defaultParams.networkConfiguration = {
awsvpcConfiguration: {
// https://github.com/aws/amazon-ecs-agent/issues/1128
Expand All @@ -1477,6 +1496,8 @@ async function setupDefaultECSParams(context) {
subnets: context.fargatePublicSubnetIds
}
};
} else {
defaultParams.launchType = 'EC2';
}

context.defaultECSParams = defaultParams;
Expand All @@ -1490,6 +1511,7 @@ async function launchLeadTask(context) {
cluster: context.clusterName,
region: context.region,
launchType: context.cliOptions.launchType,
isFargateSpot: context.isCapacitySpot,
count: context.count,
sqsQueueUrl: context.sqsQueueUrl,
tags: context.tags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test('Kitchen Sink Test - multiple features together', async (t) => {
};

const output =
await $`${A9} run-fargate ${scenarioPath} --output ${reportFilePath} --dotenv ${dotEnvPath} --record --tags ${baseTags} --count 2 --launch-config ${JSON.stringify(
await $`${A9} run-fargate ${scenarioPath} --output ${reportFilePath} --dotenv ${dotEnvPath} --record --tags ${baseTags} --count 2 --region us-east-2 --spot --launch-config ${JSON.stringify(
launchConfig
)}`;

Expand Down

0 comments on commit 35f0e1c

Please sign in to comment.