From ad116c238f19765cb825de8bbe569751f8815cd8 Mon Sep 17 00:00:00 2001 From: Ludek Novy <13610612+ludeknovy@users.noreply.github.com> Date: Sat, 1 Jun 2024 12:30:53 +0200 Subject: [PATCH] Add additional percentile metrics to server queries and update templates (#325) --- src/server/data-stats/prepare-data.spec.ts | 6 +++++- src/server/data-stats/prepare-data.ts | 8 ++++++-- src/server/queries/items.ts | 2 ++ src/server/schema-validator/project-schema.ts | 4 +++- src/server/utils/notifications/send-notification.spec.ts | 4 +++- .../notifications/templates/report/gchat-template.spec.ts | 4 +++- .../notifications/templates/report/gchat-template.ts | 2 +- .../templates/report/ms-teams-template.spec.ts | 4 +++- .../notifications/templates/report/ms-teams-template.ts | 2 +- .../notifications/templates/report/slack-template.spec.ts | 4 +++- .../notifications/templates/report/slack-template.ts | 2 +- 11 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/server/data-stats/prepare-data.spec.ts b/src/server/data-stats/prepare-data.spec.ts index 658cf9e8..908ebbc1 100644 --- a/src/server/data-stats/prepare-data.spec.ts +++ b/src/server/data-stats/prepare-data.spec.ts @@ -224,6 +224,8 @@ describe("prepare data", () => { bytes_sent_total: 69848465, total: 46596, n90: 271, + n95: 272, + n99: 273, number_of_failed: 3, } const labelsData = [ @@ -303,7 +305,9 @@ describe("prepare data", () => { const { overview, labelStats } = prepareDataForSavingToDb(overviewData, labelsData, [], statusCodes, responseFailures, apdex, groupedErrors, labelErrors) expect(overview).toEqual({ - percentil: 271, + percentile90: 271, + percentile95: 272, + percentile99: 273, maxVu: undefined, avgResponseTime: 106, errorRate: 0.01, diff --git a/src/server/data-stats/prepare-data.ts b/src/server/data-stats/prepare-data.ts index bf83d73a..d9cd7692 100644 --- a/src/server/data-stats/prepare-data.ts +++ b/src/server/data-stats/prepare-data.ts @@ -19,7 +19,9 @@ export const prepareDataForSavingToDb = (overviewData, labelData, sutStats, stat const endDate = new Date(overviewData.end) return { overview: { - percentil: roundNumberTwoDecimals(overviewData.n90), + percentile90: roundNumberTwoDecimals(overviewData.n90), + percentile95: roundNumberTwoDecimals(overviewData.n95), + percentile99: roundNumberTwoDecimals(overviewData.n99), maxVu: undefined, avgResponseTime: Math.round(overviewData.avg_response), errorRate: roundNumberTwoDecimals((overviewData.number_of_failed / overviewData.total) * 100), @@ -441,7 +443,9 @@ interface ChartLabelData { } export interface Overview { - percentil: number + percentile90: number + percentile95: number + percentile99: number errorRate: number errorCount: number throughput: number diff --git a/src/server/queries/items.ts b/src/server/queries/items.ts index b28cf983..b0e1d014 100644 --- a/src/server/queries/items.ts +++ b/src/server/queries/items.ts @@ -241,6 +241,8 @@ export const aggOverviewQuery = (itemId) => { text: ` SELECT percentile_cont(0.90) within group (order by (samples.elapsed))::real as n90, + percentile_cont(0.95) within group (order by (samples.elapsed))::real as n95, + percentile_cont(0.99) within group (order by (samples.elapsed))::real as n99, COUNT(DISTINCT samples.hostname)::int number_of_hostnames, COUNT(DISTINCT samples.sut_hostname)::int number_of_sut_hostnames, MAX(samples.timestamp) as end, diff --git a/src/server/schema-validator/project-schema.ts b/src/server/schema-validator/project-schema.ts index 3efc0f21..27be71e3 100644 --- a/src/server/schema-validator/project-schema.ts +++ b/src/server/schema-validator/project-schema.ts @@ -14,7 +14,9 @@ export const updateProjectSchema = { topMetricsSettings: Joi.object({ virtualUsers: Joi.boolean().required(), errorRate: Joi.boolean().required(), - percentile: Joi.boolean().required(), + percentile90: Joi.boolean().required(), + percentile95: Joi.boolean().required(), + percentile99: Joi.boolean().required(), throughput: Joi.boolean().required(), network: Joi.boolean().required(), avgLatency: Joi.boolean().required(), diff --git a/src/server/utils/notifications/send-notification.spec.ts b/src/server/utils/notifications/send-notification.spec.ts index 294cf885..396ed1f3 100644 --- a/src/server/utils/notifications/send-notification.spec.ts +++ b/src/server/utils/notifications/send-notification.spec.ts @@ -11,7 +11,9 @@ jest.mock("./templates/report/ms-teams-template") jest.mock("../../../db/db") const OVERVIEW = { - percentil: 10, + percentile90: 10, + percentile95: 14, + percentile99: 18, avgConnect: 1, avgLatency: 1, avgResponseTime: 1, diff --git a/src/server/utils/notifications/templates/report/gchat-template.spec.ts b/src/server/utils/notifications/templates/report/gchat-template.spec.ts index 8974db20..371d4613 100644 --- a/src/server/utils/notifications/templates/report/gchat-template.spec.ts +++ b/src/server/utils/notifications/templates/report/gchat-template.spec.ts @@ -2,7 +2,9 @@ import { gchatTemplate } from "./gchat-template" describe("GChat template", () => { const OVERVIEW = { - percentil: 10, + percentile90: 10, + percentile95: 14, + percentile99: 18, avgConnect: 1, avgLatency: 1, avgResponseTime: 1, diff --git a/src/server/utils/notifications/templates/report/gchat-template.ts b/src/server/utils/notifications/templates/report/gchat-template.ts index 42993d57..5b953a44 100644 --- a/src/server/utils/notifications/templates/report/gchat-template.ts +++ b/src/server/utils/notifications/templates/report/gchat-template.ts @@ -14,7 +14,7 @@ export const gchatTemplate = (scenarioName: string, url, overview: Overview) => { keyValue: { topLabel: "90% percentile", - content: `${overview.percentil} ms`, + content: `${overview.percentile90} ms`, }, }, { keyValue: { topLabel: "Throughput", content: `${overview.throughput} reqs/s` } }, diff --git a/src/server/utils/notifications/templates/report/ms-teams-template.spec.ts b/src/server/utils/notifications/templates/report/ms-teams-template.spec.ts index fb8b3f3f..3a9d4a82 100644 --- a/src/server/utils/notifications/templates/report/ms-teams-template.spec.ts +++ b/src/server/utils/notifications/templates/report/ms-teams-template.spec.ts @@ -2,7 +2,9 @@ import { msTeamsTemplate } from "./ms-teams-template" describe("MS Teams template", () => { const OVERVIEW = { - percentil: 10, + percentile90: 10, + percentile95: 14, + percentile99: 18, avgConnect: 1, avgLatency: 1, avgResponseTime: 1, diff --git a/src/server/utils/notifications/templates/report/ms-teams-template.ts b/src/server/utils/notifications/templates/report/ms-teams-template.ts index 380d83da..289173c5 100644 --- a/src/server/utils/notifications/templates/report/ms-teams-template.ts +++ b/src/server/utils/notifications/templates/report/ms-teams-template.ts @@ -25,7 +25,7 @@ export const msTeamsTemplate = (scenarioName: string, url, overview: Overview) = }, { title: "90% percentile", - value: overview.percentil + " ms", + value: overview.percentile90 + " ms", }, { title: "Throughput", diff --git a/src/server/utils/notifications/templates/report/slack-template.spec.ts b/src/server/utils/notifications/templates/report/slack-template.spec.ts index 6658bc1a..82d2d66a 100644 --- a/src/server/utils/notifications/templates/report/slack-template.spec.ts +++ b/src/server/utils/notifications/templates/report/slack-template.spec.ts @@ -2,7 +2,9 @@ import { slackTemplate } from "./slack-template" describe("Slack template", () => { const OVERVIEW = { - percentil: 10, + percentile90: 10, + percentile95: 14, + percentile99: 18, avgConnect: 1, avgLatency: 1, avgResponseTime: 1, diff --git a/src/server/utils/notifications/templates/report/slack-template.ts b/src/server/utils/notifications/templates/report/slack-template.ts index 5f24d25a..52767b3b 100644 --- a/src/server/utils/notifications/templates/report/slack-template.ts +++ b/src/server/utils/notifications/templates/report/slack-template.ts @@ -8,7 +8,7 @@ export const slackTemplate = (scenarioName: string, url, overview: Overview) => }, { type: "divider" }, { type: "section", fields: [{ type: "mrkdwn", text: `*Error Rate*\n${overview.errorRate}%` }], - }, { type: "section", fields: [{ type: "mrkdwn", text: `*90% percentile*\n${overview.percentil} ms` }] }, { + }, { type: "section", fields: [{ type: "mrkdwn", text: `*90% percentile*\n${overview.percentile90} ms` }] }, { type: "section", fields: [{ type: "mrkdwn", text: `*Throughput*\n${overview.throughput} reqs/s` }], }, { type: "section", fields: [{ type: "mrkdwn", text: `*Duration*\n${overview.duration} min` }] }],