Skip to content

Commit 0e13b69

Browse files
authored
chore(cts): report benchmark results (#3406)
1 parent d4cc760 commit 0e13b69

File tree

9 files changed

+61
-16
lines changed

9 files changed

+61
-16
lines changed

.github/workflows/check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ jobs:
254254
if: ${{ !github.event.pull_request.head.repo.fork && steps.cts-e2e.outcome == 'failure' }}
255255
run: yarn cli cts run javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }} --no-client --no-requests
256256

257+
- name: Run benchmarks
258+
run: yarn cli cts run javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }} --benchmark --no-client --no-requests --no-e2e
259+
257260
- name: Generate code snippets for documentation
258261
run: yarn cli snippets javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }}
259262

@@ -348,6 +351,9 @@ jobs:
348351
if: ${{ !github.event.pull_request.head.repo.fork && steps.cts-e2e.outcome == 'failure' }}
349352
run: yarn cli cts run ${{ matrix.client.language }} ${{ matrix.client.toRun }} --no-client --no-requests
350353

354+
- name: Run benchmarks
355+
run: yarn cli cts run ${{ matrix.client.language }} ${{ matrix.client.toRun }} --benchmark --no-client --no-requests --no-e2e
356+
351357
- name: Generate code snippets for documentation
352358
run: yarn cli snippets ${{ matrix.client.language }} ${{ matrix.client.toRun }}
353359

@@ -474,6 +480,26 @@ jobs:
474480
- name: Generate documentation specs with code snippets
475481
run: yarn cli build specs ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX).toRun }} --docs
476482

483+
- name: Read benchmark results
484+
id: benchmark
485+
run: |
486+
# merge all benchmark results into a single json, and remove the files
487+
results=$(jq -s 'add' -c tests/output/**/benchmarkResult.json)
488+
{
489+
echo 'BENCHMARK_SECTION<<EOF'
490+
echo "<details>"
491+
echo "<summary>📊 Benchmark results</summary>"
492+
echo "" # empty line is required to make the table work
493+
echo "Benchmarks performed on the `search` method using a mock server, the results might not reflect the real-world performance."
494+
# format the json to a markdown table with column "Language" and "rate"
495+
echo "| Language | Rate |"
496+
echo "| :------- | ---: |"
497+
echo "$results" | jq -r 'to_entries | map([.key, .value.rate]) | sort_by(.[1]) | reverse | .[] | @tsv' | awk -F'\t' '{printf "| %-10s | %10d |\n", $1, $2}'
498+
echo "</details>"
499+
echo 'EOF'
500+
} >> "$GITHUB_OUTPUT"
501+
rm -rf tests/output/**/benchmarkResult.json
502+
477503
- name: Push generated code
478504
id: pushGeneratedCode
479505
run: yarn workspace scripts pushGeneratedCode
@@ -491,6 +517,8 @@ jobs:
491517
492518
_If you believe code should've been generated, please, [report the issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=bug%2Ctriage&projects=&template=Bug_report.yml&title=%5Bbug%5D%3A+)._
493519
520+
${{ steps.benchmark.outputs.BENCHMARK_SECTION }}
521+
494522
- name: update generation comment
495523
uses: marocchino/sticky-pull-request-comment@v2
496524
if: ${{ steps.pushGeneratedCode.outputs.GENERATED_COMMIT != '' }}
@@ -505,6 +533,8 @@ jobs:
505533
| 🍃 Generated commit | [`${{ steps.pushGeneratedCode.outputs.GENERATED_COMMIT }}`](${{ github.event.pull_request.base.repo.html_url }}/commit/${{ steps.pushGeneratedCode.outputs.GENERATED_COMMIT }}) |
506534
| 🌲 Generated branch | [`generated/${{ github.head_ref }}`](${{ github.event.pull_request.base.repo.html_url }}/tree/generated/${{ github.head_ref }}) |
507535
536+
${{ steps.benchmark.outputs.BENCHMARK_SECTION }}
537+
508538
- name: Build website
509539
if: ${{ github.ref == 'refs/heads/main' || github.base_ref == 'main' }}
510540
run: yarn website:build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pom.xml
2525
dist
2626
.cache
2727

28+
benchmarkResult.json
29+
2830
**.openapi-generator
2931
/openapitools.json
3032
**/.openapi-generator-ignore

generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private String languageCased() {
7171
private String injectVariables(String json) {
7272
long threeDays = 3 * 24 * 60 * 60 * 1000;
7373
json = json
74+
.replace("${{language}}", language)
7475
.replace("${{languageCased}}", languageCased())
7576
.replace("${{clientPascalCase}}", Helpers.capitalize(Helpers.camelize(client)))
7677
.replace("\"${{nowRounded}}\"", String.valueOf(Math.round(System.currentTimeMillis() / threeDays) * threeDays));

scripts/ci/githubActions/createMatrix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function createClientMatrix(baseBranch: string): Promise<void> {
7777
const clientName = createClientName(client, language);
7878
const extension = getTestExtension(language);
7979

80-
return `${testsOutputBase}/client/${clientName}${extension} ${testsOutputBase}/requests/${clientName}${extension} ${testsOutputBase}/e2e/${clientName}${extension} ${testsOutputBase}/benchmark/${clientName}${extension}`;
80+
return `${testsOutputBase}/client/${clientName}${extension} ${testsOutputBase}/requests/${clientName}${extension} ${testsOutputBase}/e2e/${clientName}${extension} ${testsOutputBase}/benchmark/${clientName}${extension} ${testsRootFolder}/benchmarkResult.json`;
8181
})
8282
.join(' ');
8383

scripts/cts/testServer/benchmark.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* eslint-disable no-console */
2+
import fs from 'fs';
23
import type { Server } from 'http';
34

45
import { expect } from 'chai';
56
import chalk from 'chalk';
67
import express from 'express';
78
import type { Express } from 'express';
89

10+
import { CI, toAbsolutePath } from '../../common';
11+
912
import { setupServer } from '.';
1013

1114
const benchmarkStatus: Record<
@@ -31,6 +34,15 @@ export function printBenchmarkReport(): void {
3134
// eslint-disable-next-line no-nested-ternary
3235
rate > 2000 ? 'bgGreenBright' : rate > 1000 ? 'bgGreen' : rate > 500 ? 'bgYellow' : 'bgRed';
3336
console.log(chalk.black[color](`${lang}: ${Math.floor(rate)} req/s`));
37+
38+
if (CI) {
39+
// save the result to a file, to be reported in the CI.
40+
// we can't use setOutput here, because it doesn't work with matrix strategies
41+
fs.writeFileSync(
42+
toAbsolutePath(`tests/output/${lang}/benchmarkResult.json`),
43+
JSON.stringify({ [lang]: { rate } }),
44+
);
45+
}
3446
}
3547
}
3648

scripts/cts/testServer/timeout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export function assertValidTimeouts(expectedCount: number): void {
2222

2323
// languages are not consistent yet for the delay between requests
2424
switch (lang) {
25-
case 'JavaScript':
25+
case 'javascript':
2626
expect(state.duration[0] * 4).to.be.closeTo(state.duration[1], 200);
2727
break;
28-
case 'PHP':
28+
case 'php':
2929
expect(state.duration[0] * 2).to.be.closeTo(state.duration[1], 200);
3030
break;
31-
case 'Swift':
31+
case 'swift':
3232
expect(state.duration[0]).to.be.closeTo(state.duration[1], 800);
3333
break;
3434
default:

tests/CTS/benchmark/search/benchmark.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"parameters": {
2424
"requests": [
2525
{
26-
"indexName": "cts_e2e_benchmark_search_${{languageCased}}",
26+
"indexName": "cts_e2e_benchmark_search_${{language}}",
2727
"query": "iphone 15 pro max 512gb",
2828
"hitsPerPage": 50
2929
}

tests/CTS/client/search/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"type": "method",
7777
"method": "customGet",
7878
"parameters": {
79-
"path": "1/test/retry/${{languageCased}}"
79+
"path": "1/test/retry/${{language}}"
8080
},
8181
"expected": {
8282
"type": "response",

tests/CTS/client/search/helpers.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"type": "method",
8080
"method": "replaceAllObjects",
8181
"parameters": {
82-
"indexName": "cts_e2e_replace_all_objects_${{languageCased}}",
82+
"indexName": "cts_e2e_replace_all_objects_${{language}}",
8383
"objects": [
8484
{
8585
"objectID": "1",
@@ -193,7 +193,7 @@
193193
"type": "method",
194194
"method": "saveObjects",
195195
"parameters": {
196-
"indexName": "cts_e2e_saveObjects_${{languageCased}}",
196+
"indexName": "cts_e2e_saveObjects_${{language}}",
197197
"objects": [
198198
{
199199
"objectID": "1",
@@ -241,7 +241,7 @@
241241
"type": "method",
242242
"method": "partialUpdateObjects",
243243
"parameters": {
244-
"indexName": "cts_e2e_partialUpdateObjects_${{languageCased}}",
244+
"indexName": "cts_e2e_partialUpdateObjects_${{language}}",
245245
"objects": [
246246
{
247247
"objectID": "1",
@@ -290,7 +290,7 @@
290290
"type": "method",
291291
"method": "partialUpdateObjects",
292292
"parameters": {
293-
"indexName": "cts_e2e_partialUpdateObjects_${{languageCased}}",
293+
"indexName": "cts_e2e_partialUpdateObjects_${{language}}",
294294
"objects": [
295295
{
296296
"objectID": "3",
@@ -339,7 +339,7 @@
339339
"type": "method",
340340
"method": "deleteObjects",
341341
"parameters": {
342-
"indexName": "cts_e2e_deleteObjects_${{languageCased}}",
342+
"indexName": "cts_e2e_deleteObjects_${{language}}",
343343
"objectIDs": [
344344
"1",
345345
"2"
@@ -381,13 +381,13 @@
381381
"type": "method",
382382
"method": "waitForApiKey",
383383
"parameters": {
384-
"key": "api-key-add-operation-test-${{languageCased}}",
384+
"key": "api-key-add-operation-test-${{language}}",
385385
"operation": "add"
386386
},
387387
"expected": {
388388
"type": "response",
389389
"match": {
390-
"value": "api-key-add-operation-test-${{languageCased}}",
390+
"value": "api-key-add-operation-test-${{language}}",
391391
"description": "my new api key",
392392
"acl": [
393393
"search",
@@ -423,7 +423,7 @@
423423
"type": "method",
424424
"method": "waitForApiKey",
425425
"parameters": {
426-
"key": "api-key-update-operation-test-${{languageCased}}",
426+
"key": "api-key-update-operation-test-${{language}}",
427427
"operation": "update",
428428
"apiKey": {
429429
"description": "my updated api key",
@@ -448,7 +448,7 @@
448448
"expected": {
449449
"type": "response",
450450
"match": {
451-
"value": "api-key-update-operation-test-${{languageCased}}",
451+
"value": "api-key-update-operation-test-${{language}}",
452452
"description": "my updated api key",
453453
"acl": [
454454
"search",
@@ -493,7 +493,7 @@
493493
"type": "method",
494494
"method": "waitForApiKey",
495495
"parameters": {
496-
"key": "api-key-delete-operation-test-${{languageCased}}",
496+
"key": "api-key-delete-operation-test-${{language}}",
497497
"operation": "delete"
498498
},
499499
"expected": {

0 commit comments

Comments
 (0)