Skip to content

Commit

Permalink
Merge pull request #2773 from artilleryio/bernardobridge/art-1834-use…
Browse files Browse the repository at this point in the history
…-new-arch-images

feat(cli): use correct architecture in worker images
  • Loading branch information
bernardobridge authored May 22, 2024
2 parents b0be6be + c090252 commit 9c43ff4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/artillery/lib/cmds/run-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ RunLambdaCommand.flags = {
}),
container: Flags.boolean({
description: 'Use a container image for Lambda (experimental)',
default: false,
exclusive: ['architecture']
default: false
}),
architecture: Flags.string({
description: 'Architecture of the Lambda function',
default: 'arm64'
default: 'arm64',
options: ['arm64', 'x86_64']
}),
'memory-size': Flags.string({
description: 'Memory size of the Lambda function',
Expand Down
7 changes: 5 additions & 2 deletions packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {
region: options.region,
taskName: `${TASK_NAME}_${
IS_FARGATE ? 'fargate' : ''
}_${clusterName}_${IMAGE_VERSION.replace(/\./g, '-')}_${Math.floor(Math.random() * 1e6)}`,
}_${clusterName}_${IMAGE_VERSION.replace(/\./g, '-')}_${Math.floor(
Math.random() * 1e6
)}`,
clusterName: clusterName,
logGroupName: LOGGROUP_NAME,
cliOptions: options,
Expand Down Expand Up @@ -1139,9 +1141,10 @@ async function ensureTaskExists(context) {
};
});

const defaultArchitecture = 'x86_64';
const imageUrl =
process.env.WORKER_IMAGE_URL ||
`public.ecr.aws/d8a4z9o5/artillery-worker:${IMAGE_VERSION}`;
`public.ecr.aws/d8a4z9o5/artillery-worker:${IMAGE_VERSION}-${defaultArchitecture}`;

const secrets = [
'NPM_TOKEN',
Expand Down
6 changes: 3 additions & 3 deletions packages/artillery/lib/platform/aws-lambda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class PlatformLambda {
this.functionName = `artilleryio-v${this.currentVersion.replace(
/\./g,
'-'
)}`;
)}-${this.architecture}`;
shouldCreateLambda = await this.checkIfNewLambdaIsNeeded({
memorySize: this.memorySize,
functionName: this.functionName
Expand Down Expand Up @@ -674,7 +674,7 @@ class PlatformLambda {
Code: {
ImageUri:
this.ecrImageUrl ||
`248481025674.dkr.ecr.${this.region}.amazonaws.com/artillery-worker:${this.currentVersion}`
`248481025674.dkr.ecr.${this.region}.amazonaws.com/artillery-worker:${this.currentVersion}-${this.architecture}`
},
ImageConfig: {
Command: ['a9-handler-index.handler'],
Expand All @@ -686,7 +686,7 @@ class PlatformLambda {
Timeout: 900,
Role: this.lambdaRoleArn,
//TODO: architecture influences the entrypoint. We should review which architecture to use in the end (may impact Playwright viability)
Architectures: ['x86_64'],
Architectures: [this.architecture],
Environment: {
Variables: {
S3_BUCKET_PATH: this.bucketName,
Expand Down
4 changes: 2 additions & 2 deletions packages/artillery/test/cloud-e2e/lambda/lambda-bom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tap.test('Run simple-bom', async (t) => {
const scenarioPath = `${__dirname}/../fargate/fixtures/simple-bom/simple-bom.yml`;

const output =
await $`artillery run-lambda ${scenarioPath} -e test --tags ${tags} --output ${reportFilePath} --count 51 --record --container`;
await $`artillery run-lambda ${scenarioPath} --architecture x86_64 -e test --tags ${tags} --output ${reportFilePath} --count 51 --record --container`;

t.equal(output.exitCode, 0, 'CLI Exit Code should be 0');

Expand All @@ -34,7 +34,7 @@ tap.test('Run mixed-hierarchy test in Lambda Container', async (t) => {
const configPath = `${__dirname}/../fargate/fixtures/mixed-hierarchy/config/config-no-file-uploads.yml`;

const output =
await $`artillery run-lambda ${scenarioPath} --config ${configPath} -e main --tags ${tags} --output ${reportFilePath} --record --container`;
await $`artillery run-lambda ${scenarioPath} --architecture x86_64 --config ${configPath} -e main --tags ${tags} --output ${reportFilePath} --record --container`;

const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tap.test('Run dotenv test in Lambda Container', async (t) => {
const dotenvPath = `${__dirname}/fixtures/dotenv/.env-test`;

const output =
await $`artillery run-lambda ${scenarioPath} --tags ${tags} --output ${reportFilePath} --count 5 --record --container --dotenv ${dotenvPath}`;
await $`artillery run-lambda ${scenarioPath} --architecture x86_64 --tags ${tags} --output ${reportFilePath} --count 5 --record --container --dotenv ${dotenvPath}`;

const report = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tap.beforeEach(async (t) => {

tap.test('Lambda Container run uses ensure', async (t) => {
try {
await $`artillery run-lambda ${__dirname}/../fargate/fixtures/uses-ensure/with-ensure.yaml --container --tags ${tags} --output ${reportFilePath} --count 15`;
await $`artillery run-lambda ${__dirname}/../fargate/fixtures/uses-ensure/with-ensure.yaml --architecture x86_64 --container --tags ${tags} --output ${reportFilePath} --count 15`;
t.fail(`Test "${t.name}" - Should have had non-zero exit code.`);
} catch (output) {
t.equal(output.exitCode, 1, 'CLI Exit Code should be 1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ const { generateTmpReportPath, getTestTags } = require('../../cli/_helpers.js');
const tags = getTestTags(['type:acceptance']);
let reportFilePath;
tap.beforeEach(async (t) => {
process.env.LAMBDA_IMAGE_VERSION = process.env.ECR_IMAGE_VERSION;
process.env.RETAIN_LAMBDA = 'false';
reportFilePath = generateTmpReportPath(t.name, 'json');
});

tap.test(
'CLI should exit with non-zero exit code when there are failed expectations in container workers',
async (t) => {
try {
await $`artillery run-lambda ${__dirname}/../fargate/fixtures/cli-exit-conditions/with-expect.yml --record --tags ${tags} --output ${reportFilePath} --container --count 2`;
await $`artillery run-lambda ${__dirname}/../fargate/fixtures/cli-exit-conditions/with-expect.yml --architecture x86_64 --record --tags ${tags} --output ${reportFilePath} --container --count 2`;
t.fail(`Test "${t.name}" - Should have had non-zero exit code.`);
} catch (output) {
t.equal(output.exitCode, 1, 'CLI Exit Code should be 1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tap.test('Run a test on AWS Lambda using containers', async (t) => {
const scenarioPath = `${__dirname}/fixtures/quick-loop-with-csv/blitz.yml`;

const output =
await $`artillery run-lambda --count 10 --region us-east-1 --container --config ${configPath} --record --tags ${tags} ${scenarioPath}`;
await $`artillery run-lambda --count 10 --region us-east-1 --architecture x86_64 --container --config ${configPath} --record --tags ${tags} ${scenarioPath}`;

t.equal(output.exitCode, 0, 'CLI should exit with code 0');

Expand Down Expand Up @@ -47,7 +47,7 @@ tap.test(
const scenarioPath = `${__dirname}/fixtures/ts-external-pkg/with-external-foreign-pkg.yml`;

const output =
await $`artillery run-lambda ${scenarioPath} --container --record --output ${reportFilePath} --tags ${tags},typescript:true`;
await $`artillery run-lambda ${scenarioPath} --architecture x86_64 --container --record --output ${reportFilePath} --tags ${tags},typescript:true`;

t.equal(output.exitCode, 0, 'CLI Exit Code should be 0');

Expand Down

0 comments on commit 9c43ff4

Please sign in to comment.