Skip to content

Commit

Permalink
feat: refactor stress-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dskart committed May 31, 2024
1 parent f6aad1d commit 82f897c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
4 changes: 2 additions & 2 deletions load_tests/src/get-original-stress-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { check } from 'k6';
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.1.0/index.js';
import { getStressTestOptions } from './options';
import { SignedRequest } from './signed-request';
import { getStressTestCsv } from './stress-test-csv';
import { getCSVStressMetrics } from './stress-metrics';

// this test calls s3 directly
const signedRequest = SignedRequest({
Expand All @@ -24,7 +24,7 @@ export default async function () {
}

export function handleSummary(data: any) {
const csv = getStressTestCsv(data);
const csv = getCSVStressMetrics(data['metrics']);
return {
stdout: textSummary(data, { indent: ' ', enableColors: true }),
'get-original-load-test-summary.json': JSON.stringify(data, null, 2),
Expand Down
4 changes: 2 additions & 2 deletions load_tests/src/get-sidekick-stress-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { tagWithCurrentStageIndex } from 'https://jslib.k6.io/k6-utils/1.3.0/ind
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.1.0/index.js';
import { getStressTestOptions } from './options';
import { SignedRequest } from './signed-request';
import { getStressTestCsv } from './stress-test-csv';
import { getCSVStressMetrics } from './stress-metrics';

// This test will get the original file through sidekick
const signedRequest = SignedRequest({
Expand All @@ -26,7 +26,7 @@ export default async function () {
}

export function handleSummary(data: any) {
const csv = getStressTestCsv(data);
const csv = getCSVStressMetrics(data['metrics']);

return {
stdout: textSummary(data, { indent: ' ', enableColors: true }),
Expand Down
47 changes: 47 additions & 0 deletions load_tests/src/stress-metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
type MetricData = {
type: string;
contains: string;
values: {
avg: number;
min: number;
med: number;
max: number;
'p(90)': number;
'p(95)': number;
};
};

type Data = {
[key: string]: MetricData;
};

export function getCSVStressMetrics(data: Data) {
let rows: string[][] = [];

for (const metric in data) {
if (metric.startsWith('http_req_duration') && metric.includes('scenario')) {
const scenarioTag = metric.split('{')[1].split('}')[0];
const name = scenarioTag.split(':')[1];
const values = data[metric].values;

rows.push([
name,
values['avg'].toString(),
values['min'].toString(),
values['med'].toString(),
values['max'].toString(),
values['p(90)'].toString(),
values['p(95)'].toString(),
]);
}
}

rows.sort((a, b) => {
const numA = Number(a[0].substring(2));
const numB = Number(b[0].substring(2));
return numA - numB;
});
rows.unshift(['scenario', 'avg', 'min', 'med', 'max', 'p(90)', 'p(95)']);

return rows.map((row) => row.join(',')).join('\n');
}
25 changes: 0 additions & 25 deletions load_tests/src/stress-test-csv.ts

This file was deleted.

0 comments on commit 82f897c

Please sign in to comment.