From f9c2299fcf41122cb5f18e87e9d309f17a26ccbd Mon Sep 17 00:00:00 2001 From: Paul Maddern Date: Thu, 14 Dec 2023 18:45:15 +0000 Subject: [PATCH 1/2] Adds the ability to pass included/ excluded tags to Locust. --- bin/load_test.ts | 8 ++++++++ lib/constructs/locust_master_service.ts | 17 +++++++++++++++-- lib/load_test_stack.ts | 4 ++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bin/load_test.ts b/bin/load_test.ts index 861265f..36eb715 100644 --- a/bin/load_test.ts +++ b/bin/load_test.ts @@ -23,4 +23,12 @@ new LoadTestStack(app, 'LoadTestStack', { // You can enable basic auth for Locust web UI uncommenting lines below: // webUsername: 'admin', // webPassword: 'passw0rd', + + // List of tags to include in the test, so only tasks + // with any matching tags will be executed. + // includedTags: [], + + // List of tags to exclude from the test, so only tasks + // with no matching tags will be executed. + // excludedTags: [], }); diff --git a/lib/constructs/locust_master_service.ts b/lib/constructs/locust_master_service.ts index 8ee33ce..b363b2d 100644 --- a/lib/constructs/locust_master_service.ts +++ b/lib/constructs/locust_master_service.ts @@ -14,6 +14,8 @@ export interface LocustMasterServiceProps { readonly certificateArn?: string; readonly allowedCidrs: string[]; readonly logBucket: IBucket; + readonly includedTags?: string[]; + readonly excludedTags?: string[]; readonly webUsername?: string; readonly webPassword?: string; } @@ -25,7 +27,7 @@ export class LocustMasterService extends Construct { constructor(scope: Construct, id: string, props: LocustMasterServiceProps) { super(scope, id); - const { cluster, webUsername, webPassword } = props; + const { cluster, includedTags, excludedTags, webUsername, webPassword } = props; const configMapName = 'master'; const image = new ecs.AssetImage('app'); @@ -47,7 +49,18 @@ export class LocustMasterService extends Construct { command.push('--web-auth'); command.push(`${webUsername}:${webPassword}`); } - + if (includedTags != null) { + command.push('--tags'); + includedTags.forEach((tag) => + command.push(tag), + ); + } + if (excludedTags != null) { + command.push('--exclude-tags'); + excludedTags.forEach((tag) => + command.push(tag), + ); + } masterTaskDefinition.addContainer('locust', { image, command, diff --git a/lib/load_test_stack.ts b/lib/load_test_stack.ts index 8e49c6d..ba627bb 100644 --- a/lib/load_test_stack.ts +++ b/lib/load_test_stack.ts @@ -11,6 +11,8 @@ import { ServiceLinkedRole } from 'upsert-slr'; interface LoadTestStackProps extends StackProps { readonly allowedCidrs: string[]; readonly certificateArn?: string; + readonly includedTags?: string[]; + readonly excludedTags?: string[]; readonly webUsername?: string; readonly webPassword?: string; } @@ -57,6 +59,8 @@ export class LoadTestStack extends Stack { certificateArn: props.certificateArn, allowedCidrs: props.allowedCidrs, logBucket, + includedTags: props.includedTags, + excludedTags: props.excludedTags, webUsername: props.webUsername, webPassword: props.webPassword, }); From 29927b0c3688e6e99b5df073a4d5cdbb8a0d670f Mon Sep 17 00:00:00 2001 From: Paul Maddern Date: Fri, 15 Dec 2023 10:20:50 +0000 Subject: [PATCH 2/2] Update for PR comments; allow arbitrary CLI options to be passed rather than gatekeep them separately. --- bin/load_test.ts | 10 ++++------ lib/constructs/locust_master_service.ts | 18 ++++-------------- lib/load_test_stack.ts | 6 ++---- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/bin/load_test.ts b/bin/load_test.ts index 36eb715..693d237 100644 --- a/bin/load_test.ts +++ b/bin/load_test.ts @@ -24,11 +24,9 @@ new LoadTestStack(app, 'LoadTestStack', { // webUsername: 'admin', // webPassword: 'passw0rd', - // List of tags to include in the test, so only tasks - // with any matching tags will be executed. - // includedTags: [], - - // List of tags to exclude from the test, so only tasks + // Any arbitrary command line options to pass to Locust. + // An example would be: + // Exclude Tags - List of tags to exclude from the test, so only tasks // with no matching tags will be executed. - // excludedTags: [], + // additionalArguments: ['--exclude-tags', 'tag1', 'tag2'], }); diff --git a/lib/constructs/locust_master_service.ts b/lib/constructs/locust_master_service.ts index b363b2d..bcd039b 100644 --- a/lib/constructs/locust_master_service.ts +++ b/lib/constructs/locust_master_service.ts @@ -14,8 +14,7 @@ export interface LocustMasterServiceProps { readonly certificateArn?: string; readonly allowedCidrs: string[]; readonly logBucket: IBucket; - readonly includedTags?: string[]; - readonly excludedTags?: string[]; + readonly additionalArguments?: string[]; readonly webUsername?: string; readonly webPassword?: string; } @@ -27,7 +26,7 @@ export class LocustMasterService extends Construct { constructor(scope: Construct, id: string, props: LocustMasterServiceProps) { super(scope, id); - const { cluster, includedTags, excludedTags, webUsername, webPassword } = props; + const { cluster, additionalArguments, webUsername, webPassword } = props; const configMapName = 'master'; const image = new ecs.AssetImage('app'); @@ -49,17 +48,8 @@ export class LocustMasterService extends Construct { command.push('--web-auth'); command.push(`${webUsername}:${webPassword}`); } - if (includedTags != null) { - command.push('--tags'); - includedTags.forEach((tag) => - command.push(tag), - ); - } - if (excludedTags != null) { - command.push('--exclude-tags'); - excludedTags.forEach((tag) => - command.push(tag), - ); + if (additionalArguments != null) { + command.push(...additionalArguments); } masterTaskDefinition.addContainer('locust', { image, diff --git a/lib/load_test_stack.ts b/lib/load_test_stack.ts index ba627bb..c866e2c 100644 --- a/lib/load_test_stack.ts +++ b/lib/load_test_stack.ts @@ -11,8 +11,7 @@ import { ServiceLinkedRole } from 'upsert-slr'; interface LoadTestStackProps extends StackProps { readonly allowedCidrs: string[]; readonly certificateArn?: string; - readonly includedTags?: string[]; - readonly excludedTags?: string[]; + readonly additionalArguments?: string[]; readonly webUsername?: string; readonly webPassword?: string; } @@ -59,8 +58,7 @@ export class LoadTestStack extends Stack { certificateArn: props.certificateArn, allowedCidrs: props.allowedCidrs, logBucket, - includedTags: props.includedTags, - excludedTags: props.excludedTags, + additionalArguments: props.additionalArguments, webUsername: props.webUsername, webPassword: props.webPassword, });