Skip to content

Commit 5260b7c

Browse files
authored
Update gateways to latest (#529)
* Update generate-report.ts * Update generate-report.ts * file upload * Apply suggestions from code review
1 parent 351dfad commit 5260b7c

File tree

2 files changed

+54
-25
lines changed

2 files changed

+54
-25
lines changed

federation/scenarios/constant-vus-over-time/generate-report.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@ const {
1414
GITHUB_RUN_ID = "local",
1515
} = process.env;
1616

17-
async function uploadImageToCloudflare(
18-
filename: string,
19-
filePath: string
20-
): Promise<string | null> {
21-
if (!CF_IMAGES_LINK || !CF_IMAGES_TOKEN) {
22-
return null;
23-
}
24-
17+
async function uploadImageToCloudflare(filename: string, filePath: string) {
18+
console.log("Uploading image to cloudflare");
2519
const buffer = readFileSync(filePath);
2620
const blob = new Blob([buffer], { type: "image/png" });
2721
const form = new FormData();
2822

2923
form.append("file", blob, filename);
3024

31-
return fetch(CF_IMAGES_LINK!, {
25+
const res = await fetch(CF_IMAGES_LINK!, {
3226
method: "POST",
3327
body: form,
3428
headers: {
3529
Authorization: `Bearer ${CF_IMAGES_TOKEN}`,
3630
},
37-
})
38-
.then((res) => res.json())
39-
.then((r) => r.result.variants[0]);
31+
});
32+
33+
console.log(`Got a response from cloudflare (status=${res.status})`);
34+
35+
if (!res.ok) {
36+
throw new Error(`Failed to upload image to Cloudflare: ${res.statusText}`);
37+
}
38+
39+
const data = await res.json();
40+
return data.result.variants[0];
4041
}
4142

4243
function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
@@ -57,7 +58,10 @@ async function generateReport(artifactsRootPath: string) {
5758
withFileTypes: true,
5859
})
5960
.filter((r) => r.isDirectory() && !IGNORED_DIRS.includes(r.name))
60-
.filter((r) => r.name.startsWith(process.env.SCENARIO_ARTIFACTS_PREFIX!))
61+
.filter(
62+
(r) =>
63+
r.name.startsWith(process.env.SCENARIO_ARTIFACTS_PREFIX!)
64+
)
6165
.map((r) => r.name);
6266

6367
console.info(
@@ -73,6 +77,7 @@ async function generateReport(artifactsRootPath: string) {
7377
const reportsData = await Promise.all(
7478
foundDirectories.map(async (dirName) => {
7579
const fullPath = join(artifactsRootPath, dirName);
80+
console.log(`Processing directory: ${fullPath}`);
7681
const jsonSummaryFilePath = join(fullPath, "./k6_summary.json");
7782

7883
if (!existsSync(jsonSummaryFilePath)) {
@@ -135,6 +140,8 @@ async function generateReport(artifactsRootPath: string) {
135140
.filter(notEmpty)
136141
.sort((a, b) => b.rps - a.rps);
137142

143+
console.log(`Found ${validReportsData.length} valid reports`);
144+
138145
const vega: vl.TopLevelSpec = {
139146
width: 600,
140147
height: 400,
@@ -196,7 +203,10 @@ async function generateReport(artifactsRootPath: string) {
196203
);
197204
}
198205

199-
const checks = v.jsonSummary.root_group.checks;
206+
const checks: Array<{
207+
fails: number;
208+
name: string;
209+
}> = v.jsonSummary.root_group.checks;
200210
const http200Check = checks.find(
201211
(c) => c.name === "response code was 200"
202212
);
@@ -207,6 +217,7 @@ async function generateReport(artifactsRootPath: string) {
207217
(c) => c.name === "valid response structure"
208218
);
209219

220+
210221
if (http200Check.fails > 0) {
211222
notes.push(`${http200Check.fails} non-200 responses`);
212223
}

federation/scenarios/ramping-vus/generate-report.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,29 @@ const {
1515
} = process.env;
1616

1717
async function uploadImageToCloudflare(filename: string, filePath: string) {
18+
console.log("Uploading image to cloudflare");
1819
const buffer = readFileSync(filePath);
1920
const blob = new Blob([buffer], { type: "image/png" });
2021
const form = new FormData();
2122

2223
form.append("file", blob, filename);
2324

24-
return fetch(CF_IMAGES_LINK!, {
25+
const res = await fetch(CF_IMAGES_LINK!, {
2526
method: "POST",
2627
body: form,
2728
headers: {
2829
Authorization: `Bearer ${CF_IMAGES_TOKEN}`,
2930
},
30-
})
31-
.then((res) => res.json())
32-
.then((r) => r.result.variants[0]);
31+
});
32+
33+
console.log(`Got a response from cloudflare (status=${res.status})`);
34+
35+
if (!res.ok) {
36+
throw new Error(`Failed to upload image to Cloudflare: ${res.statusText}`);
37+
}
38+
39+
const data = await res.json();
40+
return data.result.variants[0];
3341
}
3442

3543
function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
@@ -186,13 +194,21 @@ async function generateReport(artifactsRootPath: string) {
186194
const notes: string[] = [];
187195

188196
if (v.jsonSummary.metrics.http_req_failed.values.passes > 0) {
189-
notes.push(`${v.jsonSummary.metrics.http_req_failed.values.passes} failed requests`);
197+
notes.push(
198+
`${v.jsonSummary.metrics.http_req_failed.values.passes} failed requests`
199+
);
190200
}
191201

192202
const checks = v.jsonSummary.root_group.checks;
193-
const http200Check = checks.find(c => c.name === 'response code was 200');
194-
const graphqlErrors = checks.find(c => c.name === 'no graphql errors');
195-
const responseStructure = checks.find(c => c.name === 'valid response structure');
203+
const http200Check = checks.find(
204+
(c) => c.name === "response code was 200"
205+
);
206+
const graphqlErrors = checks.find(
207+
(c) => c.name === "no graphql errors"
208+
);
209+
const responseStructure = checks.find(
210+
(c) => c.name === "valid response structure"
211+
);
196212

197213
if (http200Check.fails > 0) {
198214
notes.push(`${http200Check.fails} non-200 responses`);
@@ -203,7 +219,9 @@ async function generateReport(artifactsRootPath: string) {
203219
}
204220

205221
if (responseStructure.fails > 0) {
206-
notes.push(`non-compatible response structure (${responseStructure.fails})`);
222+
notes.push(
223+
`non-compatible response structure (${responseStructure.fails})`
224+
);
207225
}
208226

209227
return {
@@ -220,8 +238,8 @@ async function generateReport(artifactsRootPath: string) {
220238
)}ms, med: ${Math.round(
221239
v.jsonSummary.metrics.http_req_duration.values.med
222240
)}ms`,
223-
notes: notes.length === 0 ? '✅' : '❌ ' + notes.join(', '),
224-
}
241+
notes: notes.length === 0 ? "✅" : "❌ " + notes.join(", "),
242+
};
225243
}),
226244
{
227245
columns: [

0 commit comments

Comments
 (0)