Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Measure each commit once, stamp stats with its timestamp, record total kb, and test different locales too (#82323)

Romeo Van Snick2ab5bdad2836
diff --git a/.github/scripts/bundle-size-stats-prepare.ts b/.github/scripts/bundle-size-stats-prepare.ts
index 8d28b6f1419..5c5de209870 100644
--- a/.github/scripts/bundle-size-stats-prepare.ts
+++ b/.github/scripts/bundle-size-stats-prepare.ts
@@ -200,7 +200,9 @@ export function main() {
// The last plotted point, as slim rows: [{ bundle, kind, rawBytes, gzipBytes, brotliBytes }].
previous: readJson<CacheRow[]>(env.LAST) || [],
threshold: Number(env.MIN_DELTA_PERCENT ?? 1),
- date: new Date().toISOString().slice(0, 10), // YYYY-MM-DD
+ // The commit's own time rather than the day it was measured, so the merges
+ // of one day keep their order on the chart.
+ date: new Date(env.COMMIT_TIMESTAMP || Date.now()).toISOString(),
commit: (env.HEAD_SHA || "").slice(0, 12),
commitMessage: (env.COMMIT_MESSAGE || "").split("\n")[0], // subject line only
version: readVersion(env.VERSION_PROPS),
diff --git a/.github/scripts/upload-bundle-load-stats.ts b/.github/scripts/upload-bundle-load-stats.ts
index 24ddea72fa5..4d5ff2966bc 100644
--- a/.github/scripts/upload-bundle-load-stats.ts
+++ b/.github/scripts/upload-bundle-load-stats.ts
@@ -23,24 +23,30 @@ interface Condition {
coldLargestPaintMs: number;
coldPageReadyMs: number;
warmPageReadyMs: number;
+ locale: string;
scripts: number;
scriptKb: number;
+ totalKb: number;
runs: number;
}
interface CommitStamp {
sha: string;
subject: string;
+ /** ISO 8601, in UTC. */
+ timestamp: string;
}
type LoadTimeRow = Record<string, string | number>;
function buildRows(
conditions: Condition[],
- { sha, subject }: CommitStamp,
+ { sha, subject, timestamp }: CommitStamp,
): LoadTimeRow[] {
return conditions.map((condition) => ({
- Date: new Date().toISOString().slice(0, 10),
+ // The commit's own time rather than the day it was measured, so the merges
+ // of one day keep their order and a backfilled row lands on its commit.
+ Date: timestamp,
// Truncated the same way the bundle-size table does, so the two join.
Commit: sha.slice(0, 12),
// The stats table carries a free-text Description column. Populate it with
@@ -63,8 +69,10 @@ function buildRows(
"Cold largest paint ms": condition.coldLargestPaintMs,
"Cold page ready ms": condition.coldPageReadyMs,
"Warm page ready ms": condition.warmPageReadyMs,
+ Locale: condition.locale,
Scripts: condition.scripts,
"Script kb": condition.scriptKb,
+ "Total kb": condition.totalKb,
Runs: condition.runs,
}));
}
@@ -77,6 +85,7 @@ async function main() {
const rows = buildRows(conditions, {
sha: process.env.HEAD_SHA || "",
subject: process.env.COMMIT_MESSAGE || "",
+ timestamp: new Date(process.env.COMMIT_TIMESTAMP || Date.now()).toISOString(),
});
console.table(rows);
diff --git a/.github/workflows/bundle-size-stats.yml b/.github/workflows/bundle-size-stats.yml
index e57b1a9f652..8aae430b4bb 100644
--- a/.github/workflows/bundle-size-stats.yml
+++ b/.github/workflows/bundle-size-stats.yml
@@ -21,17 +21,23 @@ on:
required: false
default: ""
+# A later attempt must not cancel the first one: the concurrency group applies
+# before any job `if`, so a run that goes on to skip every job still cancels.
concurrency:
group: bundle-size-stats-${{ inputs.commit || github.event.workflow_run.head_sha }}
- cancel-in-progress: true
+ cancel-in-progress: false
jobs:
# "Run tests" concludes `failure` on master more often than `success`, from
# jobs that have nothing to do with the jar, so its conclusion is not a usable
# gate. The artifact is one: the uberjar job publishes it, and a docs-only
# merge that skipped that job publishes none.
+ #
+ # Only the first attempt counts. `rerun-workflows.yml` re-runs a failed "Run
+ # tests", and every attempt that completes fires this again for the same
+ # commit, which would measure it again and write its rows twice.
uberjar-built:
- if: ${{ github.repository == 'metabase/metabase' }}
+ if: ${{ github.repository == 'metabase/metabase' && (inputs.commit != '' || github.event.workflow_run.run_attempt == 1) }}
runs-on: ${{ vars.SLIM_RUNNER_KEY }}
timeout-minutes: 5
outputs:
@@ -134,6 +140,7 @@ jobs:
# Passed via env (not interpolated into the shell) so the commit
# message can't inject commands; the script keeps only the subject.
COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
+ COMMIT_TIMESTAMP: ${{ github.event.workflow_run.head_commit.timestamp }}
run: bun ./.github/scripts/bundle-size-stats-prepare.ts
- name: Import sizes (with deltas) into Stats
id: upload
diff --git a/.github/workflows/test.bundle-load-stats.yml b/.github/workflows/test.bundle-load-stats.yml
index 9f297ee3293..60c9b3772ab 100644
--- a/.github/workflows/test.bundle-load-stats.yml
+++ b/.github/workflows/test.bundle-load-stats.yml
@@ -25,17 +25,23 @@ on:
required: false
default: ""
+# A later attempt must not cancel the first one: the concurrency group applies
+# before any job `if`, so a run that goes on to skip every job still cancels.
concurrency:
group: bundle-load-stats-${{ inputs.commit || github.event.workflow_run.head_sha }}
- cancel-in-progress: true
+ cancel-in-progress: false
jobs:
# "Run tests" concludes `failure` on master more often than `success`, from
# jobs that have nothing to do with the jar, so its conclusion is not a usable
# gate. The artifact is one: the uberjar job publishes it, and a docs-only
# merge that skipped that job publishes none.
+ #
+ # Only the first attempt counts. `rerun-workflows.yml` re-runs a failed "Run
+ # tests", and every attempt that completes fires this again for the same
+ # commit, which would measure it again and write its rows twice.
uberjar-built:
- if: ${{ github.repository == 'metabase/metabase' }}
+ if: ${{ github.repository == 'metabase/metabase' && (inputs.commit != '' || github.event.workflow_run.run_attempt == 1) }}
runs-on: ${{ vars.SLIM_RUNNER_KEY }}
timeout-minutes: 5
outputs:
@@ -120,6 +126,7 @@ jobs:
# Passed via env (not interpolated into the shell) so the commit
# message can't inject commands; the script keeps only the subject.
COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
+ COMMIT_TIMESTAMP: ${{ github.event.workflow_run.head_commit.timestamp }}
ENG_STATS_URL: ${{ secrets.ENG_STATS_URL }}
API_KEY: ${{ secrets.ENG_STATS_API_KEY }}
run: bun .github/scripts/upload-bundle-load-stats.ts
diff --git a/frontend/test/bench/README.md b/frontend/test/bench/README.md
index d5ff05d6912..347186b1284 100644
--- a/frontend/test/bench/README.md
+++ b/frontend/test/bench/README.md
@@ -88,6 +88,12 @@ SESSION_COOKIE=$(bun frontend/test/bench/sign-in.ts http://localhost:4000) \
a later run, so it is safe to run again while the backend is up. It seeds no
content, because `index.html` is built from settings and the user alone.
+It sets the site locale to German, so the document carries a translation
+catalogue. The user sets no locale of their own and falls back to the site's,
+so `index.html` inlines the catalogue twice: once for the user and once for the
+site. A change to how locales load shows up in the numbers, where an English
+site would hide it.
+
## Running it against a built tree
Use this to compare two chunk layouts without booting a backend. It understates
diff --git a/frontend/test/bench/matrix.ts b/frontend/test/bench/matrix.ts
index d7ec1916b54..5fa4f71cd84 100644
--- a/frontend/test/bench/matrix.ts
+++ b/frontend/test/bench/matrix.ts
@@ -34,8 +34,10 @@ interface Timings {
/** What one `measure.ts` series prints. */
interface Series {
runs: number;
+ locale: string;
scripts: number;
scriptKb: number;
+ totalKb: number;
median: Timings;
secondLoad: Timings | null;
steady: Timings | null;
@@ -187,8 +189,10 @@ function spreadPercent(values: number[]) {
coldLargestPaintMs: cold.median.largestContentfulPaintMs,
coldPageReadyMs: cold.median.pageReadyMs,
warmPageReadyMs: required(warm.secondLoad, "secondLoad").pageReadyMs,
+ locale: cold.locale,
scripts: cold.scripts,
scriptKb: cold.scriptKb,
+ totalKb: cold.totalKb,
runs: cold.runs,
});
diff --git a/frontend/test/bench/measure.ts b/frontend/test/bench/measure.ts
index 7641ca120f3..6227d485241 100644
--- a/frontend/test/bench/measure.ts
+++ b/frontend/test/bench/measure.ts
@@ -43,6 +43,7 @@ if (!url) {
/** What READ_METRICS evaluates to in the page. */
interface Run {
href: string;
+ language: string;
ttfb: number;
domContentLoaded: number;
load: number;
@@ -54,6 +55,7 @@ interface Run {
lastScriptEnd: number;
scriptCount: number;
scriptBytes: number;
+ totalBytes: number;
}
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -124,6 +126,8 @@ const READ_METRICS = `JSON.stringify((() => {
};
return {
href: location.href,
+ // What the server actually served, so a row says which locale it measured.
+ language: document.documentElement.lang,
ttfb: nav ? nav.responseStart : 0,
domContentLoaded: nav ? nav.domContentLoadedEventEnd : 0,
load: nav ? nav.loadEventEnd : 0,
@@ -135,6 +139,11 @@ const READ_METRICS = `JSON.stringify((() => {
lastScriptEnd: Math.max(0, ...scripts.map((entry) => entry.responseEnd)),
scriptCount: scripts.length,
scriptBytes: scripts.reduce((total, entry) => total + entry.encodedBodySize, 0),
+ // Every byte the page fetched so far, compressed as it arrived: the document
+ // itself, then each script, stylesheet, font, image and API response.
+ totalBytes: (nav ? nav.encodedBodySize : 0) + performance
+ .getEntriesByType("resource")
+ .reduce((total, entry) => total + entry.encodedBodySize, 0),
};
})())`;
@@ -330,8 +339,12 @@ function timings(run: Run) {
cpuThrottle,
network: mbps > 0 ? `${mbps} Mbps` : "unthrottled",
cache: keepCache ? "kept between runs" : "disabled",
+ locale: results[0].language,
scripts: results[0].scriptCount,
scriptKb: Number((results[0].scriptBytes / 1024).toFixed(1)),
+ // Read at the same moment as `scriptKb`, so the difference between the
+ // two is everything the page loaded that is not script.
+ totalKb: Number((results[0].totalBytes / 1024).toFixed(1)),
// Each of the three is one load. A zero in a reading means the browser
// or the route never reported that one.
median: timings(representative(results)),
diff --git a/frontend/test/bench/sign-in.ts b/frontend/test/bench/sign-in.ts
index b9f2cf74292..fe5a2650039 100644
--- a/frontend/test/bench/sign-in.ts
+++ b/frontend/test/bench/sign-in.ts
@@ -17,6 +17,10 @@ const url = process.argv[2] || "http://localhost:4000";
const EMAIL = "[email protected]";
// The setup endpoint rejects a password that is short or common.
const PASSWORD = "Benchmark-Passw0rd!";
+// A translated site, so the document carries a translation catalogue and a
+// change to how locales load shows up in the numbers. The user sets no locale
+// of their own, so it falls back to this one.
+const SITE_LOCALE = "de";
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -69,7 +73,7 @@ async function post(path: string, body: unknown) {
first_name: "Bench",
last_name: "Mark",
},
- prefs: { site_name: "Bench" },
+ prefs: { site_name: "Bench", site_locale: SITE_LOCALE },
})
: await post("/api/session", { username: EMAIL, password: PASSWORD });