Skip to content

Commit

Permalink
fix: reduce payload size by removing aggregated report from json webh…
Browse files Browse the repository at this point in the history
…ooks
  • Loading branch information
NivLipetz committed Sep 16, 2020
1 parent bedc452 commit 4ba6a20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/reports/models/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ async function handleFirstIntermediate(report, job) {
if (!reportUtil.isAllRunnersInExpectedPhase(report, constants.SUBSCRIBER_FIRST_INTERMEDIATE_STAGE)) {
return;
}
let aggregatedReport = await aggregateReportGenerator.createAggregateReport(report.test_id, report.report_id);
await webhooksManager.fireWebhookByEvent(job, WEBHOOK_EVENT_TYPE_IN_PROGRESS, report, { aggregatedReport });
await webhooksManager.fireWebhookByEvent(job, WEBHOOK_EVENT_TYPE_IN_PROGRESS, report);
}

async function handleDone(report, job, reportBenchmark) {
Expand All @@ -98,9 +97,9 @@ async function handleDone(report, job, reportBenchmark) {
const lastReports = await reportsManager.getReports(aggregatedReport.test_id);
const lastScores = lastReports.slice(0, 3).filter(report => report.score).map(report => report.score.toFixed(1));
const { event, icon } = reportBenchmark.score < benchmarkThreshold ? { event: WEBHOOK_EVENT_TYPE_BENCHMARK_FAILED, icon: ':cry:' } : { event: WEBHOOK_EVENT_TYPE_BENCHMARK_PASSED, icon: ':grin:' };
await webhooksManager.fireWebhookByEvent(job, event, report, { aggregatedReport, score: reportBenchmark.score, lastScores, benchmarkThreshold }, { icon });
await webhooksManager.fireWebhookByEvent(job, event, report, { aggregatedReport: aggregatedReport.aggregate, score: reportBenchmark.score, lastScores, benchmarkThreshold }, { icon });
}
await webhooksManager.fireWebhookByEvent(job, WEBHOOK_EVENT_TYPE_FINISHED, report, { aggregatedReport, score: reportBenchmark.score }, { icon: ':rocket:' });
await webhooksManager.fireWebhookByEvent(job, WEBHOOK_EVENT_TYPE_FINISHED, report, { aggregatedReport: aggregatedReport.aggregate, score: reportBenchmark.score }, { icon: ':rocket:' });
}

async function handleAbort(report, job) {
Expand Down
20 changes: 12 additions & 8 deletions src/webhooks/models/webhooksFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getThresholdSlackMessage(state, { testName, benchmarkThreshold, lastSco
}
return `${icon} *Test ${testName} got a score of ${score.toFixed(1)}` +
` this is ${resultText} the threshold of ${benchmarkThreshold}. ${lastScores.length > 0 ? `last 3 scores are: ${lastScores.join()}` : 'no last score to show'}` +
`.*\n${statsFormatter.getStatsFormatted('aggregate', aggregatedReport.aggregate, { score })}\n`;
`.*\n${statsFormatter.getStatsFormatted('aggregate', aggregatedReport, { score })}\n`;
}

function slackWebhookFormat(message, options) {
Expand Down Expand Up @@ -61,19 +61,26 @@ function slack(event, testId, jobId, report, additionalInfo, options) {
parallelism = 1,
ramp_to: rampTo,
arrival_rate: arrivalRate,
arrival_count: arrivalCount,
test_name: testName,
grafana_report: grafanaReport
} = report;
const { score, aggregatedReport, reportBenchmark, benchmarkThreshold, lastScores, stats } = additionalInfo;
switch (event) {
case WEBHOOK_EVENT_TYPE_STARTED: {
let rampToMessage = rampTo ? `ramp to: ${rampTo} scenarios per second` : '';
const rampToMessage = `, ramp to: ${rampTo} scenarios per second`;
let requestRateMessage = arrivalRate ? `arrival rate: ${arrivalRate}` : `arrival count: ${arrivalCount}`;
requestRateMessage = rampTo ? requestRateMessage + rampToMessage : requestRateMessage;

message = `🤓 *Test ${testName} with id: ${testId} has started*.\n
*test configuration:* environment: ${environment} duration: ${duration} seconds, arrival rate: ${arrivalRate} scenarios per second, number of runners: ${parallelism}, ${rampToMessage}`;
*test configuration:* environment: ${environment} duration: ${duration} seconds, ${requestRateMessage}, number of runners: ${parallelism}`;
break;
}
case WEBHOOK_EVENT_TYPE_FINISHED: {
message = `😎 *Test ${testName} with id: ${testId} is finished.*\n ${statsFormatter.getStatsFormatted('aggregate', aggregatedReport.aggregate, reportBenchmark)}\n`;
message = `😎 *Test ${testName} with id: ${testId} is finished.*\n ${statsFormatter.getStatsFormatted('aggregate', aggregatedReport, reportBenchmark)}\n`;
if (grafanaReport) {
message += `<${grafanaReport} | View final grafana dashboard report>`;
}
break;
}
case WEBHOOK_EVENT_TYPE_FAILED: {
Expand All @@ -97,16 +104,13 @@ function slack(event, testId, jobId, report, additionalInfo, options) {
break;
}
case WEBHOOK_EVENT_TYPE_API_FAILURE: {
message = `::boom:: *Test ${testName} with id: ${testId} has encountered an API failure!* :skull:`;
message = `:boom: *Test ${testName} with id: ${testId} has encountered an API failure!* :skull:`;
break;
}
default: {
throw unknownWebhookEventTypeError();
}
}
if (grafanaReport) {
message += `<${grafanaReport} | View final grafana dashboard report>`;
}
return slackWebhookFormat(message, options);
}

Expand Down

0 comments on commit 4ba6a20

Please sign in to comment.