Skip to content

Commit

Permalink
Merge pull request #2754 from artilleryio/slack-fargate-fix
Browse files Browse the repository at this point in the history
fix(slack): make slack work with distributed tests
  • Loading branch information
hassy authored May 27, 2024
2 parents 1f744d7 + 9a213d2 commit 8ae17dd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/artillery-plugin-slack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SlackPlugin {
this.script = script;
this.events = events;

if (process.env.LOCAL_WORKER_ID) {
if (process.env.LOCAL_WORKER_ID || process.env.WORKER_ID) {
debug('Running in a worker, exiting');
return;
}
Expand All @@ -22,6 +22,7 @@ class SlackPlugin {
}

if (global.artillery && global.artillery.cloudEnabled) {
debug('Artillery Cloud enabled, configuring Run URL');
this.cloudEnabled = true;
const baseUrl =
process.env.ARTILLERY_CLOUD_ENDPOINT || 'https://app.artillery.io';
Expand All @@ -41,7 +42,7 @@ class SlackPlugin {
passed: 0,
checkList: []
};

debug('Sorting and formatting ensure checks');
checkTests
.sort((a, b) => (a.result < b.result ? 1 : -1))
.forEach((check) => {
Expand All @@ -65,6 +66,7 @@ class SlackPlugin {
// When ensure is enabled, whether the beforeExit or the checks event will be triggered first will depend on the order of plugins in the test script
// Since we need data from both events, first event triggered will store the data and the second event will send the report
if (this.exitCode !== undefined && this.report && !this.reportSent) {
debug('Sending report from checks event');
await this.sendReport(this.report, this.ensureChecks);
this.reportSent = true;
}
Expand All @@ -78,6 +80,7 @@ class SlackPlugin {
if (this.ensureEnabled && !this.ensureChecks && !this.reportSent) {
this.report = opts.report;
} else {
debug('Sending report from beforeExit event');
await this.sendReport(opts.report, this.ensureChecks);
this.reportSent = true;
}
Expand Down Expand Up @@ -217,10 +220,14 @@ class SlackPlugin {
if (durationInMs < 1000) {
return `${durationInMs} miliseconds`;
}
const miliseconds = duration.get('millisecond');
const timeComponents = ['day', 'hour', 'minute', 'second'];
const formatedTimeComponents = timeComponents
.map((component) => {
const value = duration.get(component);
let value = duration.get(component);
if (component === 'second' && miliseconds) {
value += 1;
}
return value
? `${value} ${value === 1 ? component : component + 's'}`
: '';
Expand Down
1 change: 1 addition & 0 deletions packages/artillery/lib/cmds/run-fargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RunCommand extends Command {
global.artillery.testRunId = testRunId;

const cloud = new CloudPlugin(null, null, { flags });
global.artillery.cloudEnabled = cloud.enabled;
if (cloud.enabled) {
try {
await cloud.init();
Expand Down
3 changes: 2 additions & 1 deletion packages/artillery/lib/create-bom/built-in-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = [
'ensure',
'publish-metrics',
'expect',
'apdex'
'apdex',
'slack'
];
3 changes: 2 additions & 1 deletion packages/artillery/lib/platform/aws-ecs/legacy/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports.getOfficialPlugins = function () {
'expect',
'metrics-by-endpoint',
'publish-metrics',
'apdex'
'apdex',
'slack'
];
};

Expand Down
7 changes: 7 additions & 0 deletions packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const defaultOptions = require('rc')('artillery');
const moment = require('moment');

const EnsurePlugin = require('artillery-plugin-ensure');
const SlackPlugin = require('artillery-plugin-slack');

const {
getADOTRelevantReporterConfigs,
Expand Down Expand Up @@ -750,6 +751,12 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {
new EnsurePlugin.Plugin({ config: { ensure: context.ensureSpec } });
}

if (context.fullyResolvedConfig?.plugins?.slack) {
new SlackPlugin.Plugin({
config: context.fullyResolvedConfig
});
}

if (context.cliOptions.output) {
let logfile = getLogFilename(
context.cliOptions.output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ async function execArtillery(options) {
SQS_QUEUE_URL: SQS_QUEUE_URL,
SQS_REGION: SQS_REGION,
ARTILLERY_DISABLE_ENSURE: 'true',
WORKER_ID: WORKER_ID,
// Set test run ID for this Artillery process explicitly. This makes sure that $testId
// template variable is set to the same value for all Lambda workers as the one user
// sees on their terminal
Expand Down

0 comments on commit 8ae17dd

Please sign in to comment.