Skip to content

Commit

Permalink
fix: use artillery v2 report format
Browse files Browse the repository at this point in the history
  • Loading branch information
InesNi committed Jul 12, 2023
1 parent 3309d93 commit 05bb8d5
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions packages/artillery-plugin-publish-metrics/lib/mixpanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MixPanelReporter {
);
}
if (!this.mixPanelOpts.projectToken) {
console.error(`mix panel project token not specified`);
console.error('mix panel project token not specified');
}
this.mixpanel = Mixpanel.init(this.mixPanelOpts.projectToken);
this.sendToMixPanel(config, events, script);
Expand All @@ -25,17 +25,45 @@ class MixPanelReporter {

sendToMixPanel(config, events, script) {
events.on('stats', (stats) => {
const report = stats.report();
const report = this.formatProperties(stats);
let env = script._environment
? script._environment.toUpperCase()
: script.config.target;

this.mixpanel.track(`${env}-${script.scenarios[0].name}`, {
...report
});
this.mixpanel.track(
`${env}-${script.scenarios[0]['name'] || 'Artillery.io'}`,
report
);
});
}

formatProperties(stats) {
const properties = {};

for (const [name, value] of Object.entries(stats)) {
if (name === 'histograms') {
continue;
}
if (typeof value !== 'object') {
properties[name] = value;
}
}

for (const [name, value] of Object.entries(
{ ...stats.counters, ...stats.rates } || {}
)) {
properties[name] = value;
}

for (const [name, values] of Object.entries(stats.summaries || {})) {
for (const [aggregation, value] of Object.entries(values)) {
properties[`${name}.${aggregation}`] = value;
}
}

return properties;
}

cleanup(done) {
debug('cleaning up');
return done();
Expand Down

0 comments on commit 05bb8d5

Please sign in to comment.