Skip to content

Commit

Permalink
print startup time in version upload (#6392)
Browse files Browse the repository at this point in the history
* [wrangler] log startup time in version upload

Same as #6318 , but for
version upload

* [wrangler] remove bundle size warning

Bundle size was a proxy for startup time. Now that we have startup time
reported, focus on bundle size is less relevant.

Tracked internally as EW-8219
  • Loading branch information
taylorlee authored Aug 1, 2024
1 parent 5146775 commit c3e19b7
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-baboons-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

feat: log Worker startup time in the `version upload` command
8 changes: 8 additions & 0 deletions .changeset/witty-bats-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": patch
---

fix: remove bundle size warning from Worker deploy commands

Bundle size was a proxy for startup time. Now that we have startup time
reported, focus on bundle size is less relevant.
4 changes: 3 additions & 1 deletion packages/wrangler/e2e/helpers/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export function normalizeSlashes(str: string): string {
* Use this in snapshot tests to be resilient to slight changes in timing of processing.
*/
export function stripTimings(stdout: string): string {
return stdout.replace(/\(\d+\.\d+ sec\)/g, "(TIMINGS)");
return stdout
.replace(/\(\d+\.\d+ sec\)/g, "(TIMINGS)")
.replace(/\d+ ms/g, "(TIMINGS)");
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/e2e/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {

expect(normalize(upload.stdout)).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Worker Startup Time: (TIMINGS)
Worker Version ID: 00000000-0000-0000-0000-000000000000
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
To deploy this version to production traffic use the command wrangler versions deploy --experimental-versions
Expand Down Expand Up @@ -174,6 +175,7 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {

expect(normalize(upload.stdout)).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Worker Startup Time: (TIMINGS)
Worker Version ID: 00000000-0000-0000-0000-000000000000
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
To deploy this version to production traffic use the command wrangler versions deploy --experimental-versions
Expand Down
32 changes: 1 addition & 31 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9403,35 +9403,7 @@ export default{
// keeping these as unit tests to try and keep them snappy, as they often deal with
// big files that would take a while to deal with in a full wrangler test

test("should print the bundle size and warn about large scripts when > 1MiB", async () => {
const bigModule = Buffer.alloc(10_000_000);
randomFillSync(bigModule);
await printBundleSize({ name: "index.js", content: "" }, [
{
name: "index.js",
filePath: undefined,
content: bigModule,
type: "buffer",
},
]);

expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB",
"warn": "▲ [WARNING] We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding this can affect cold start time. Consider using Wrangler's \`--minify\` option to reduce your bundle size.
",
}
`);
});

test("should not warn about bundle sizes when NO_SCRIPT_SIZE_WARNING is set", async () => {
const previousValue = process.env.NO_SCRIPT_SIZE_WARNING;
process.env.NO_SCRIPT_SIZE_WARNING = "true";

test("should print the bundle size", async () => {
const bigModule = Buffer.alloc(10_000_000);
randomFillSync(bigModule);
await printBundleSize({ name: "index.js", content: "" }, [
Expand All @@ -9452,8 +9424,6 @@ export default{
"warn": "",
}
`);

process.env.NO_SCRIPT_SIZE_WARNING = previousValue;
});

test("should print the top biggest dependencies in the bundle when upload fails", () => {
Expand Down
6 changes: 0 additions & 6 deletions packages/wrangler/src/deployment-bundle/bundle-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ export async function printBundleSize(
: chalk.green(bundleReport);

logger.log(`Total Upload: ${colorizedReport}`);

if (gzipSize > ALLOWED_INITIAL_MAX && !process.env.NO_SCRIPT_SIZE_WARNING) {
logger.warn(
"We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding this can affect cold start time. Consider using Wrangler's `--minify` option to reduce your bundle size."
);
}
}

export function printOffendingDependencies(
Expand Down
13 changes: 12 additions & 1 deletion packages/wrangler/src/versions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,11 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m

printBindings({ ...withoutStaticAssets, vars: maskedVars });

if (!props.dryRun) {
if (props.dryRun) {
printBindings({ ...withoutStaticAssets, vars: maskedVars });
} else {
await ensureQueuesExistByConfig(config);
let bindingsPrinted = false;

// Upload the script so it has time to propagate.
// We can also now tell whether available_on_subdomain is set
Expand All @@ -431,6 +434,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
pipeline_hash: string | null;
mutable_pipeline_id: string | null;
deployment_id: string | null;
startup_time_ms: number;
}>(
workerUrl,
{
Expand All @@ -446,8 +450,15 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
})
);

logger.log("Worker Startup Time:", result.startup_time_ms, "ms");
bindingsPrinted = true;
printBindings({ ...withoutStaticAssets, vars: maskedVars });
logger.log("Worker Version ID:", result.id);
} catch (err) {
if (!bindingsPrinted) {
printBindings({ ...withoutStaticAssets, vars: maskedVars });
}

helpIfErrorIsSizeOrScriptStartup(err, dependencies);

// Apply source mapping to validation startup errors if possible
Expand Down
2 changes: 0 additions & 2 deletions packages/wrangler/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"SPARROW_SOURCE_KEY",
"ALGOLIA_APP_ID",
"ALGOLIA_PUBLIC_KEY",
"NO_SCRIPT_SIZE_WARNING",
"CLOUDFLARE_API_TOKEN",
"CLOUDFLARE_ACCOUNT_ID",
"WRANGLER_AUTH_DOMAIN",
Expand All @@ -39,7 +38,6 @@
"CF_PAGES",
"CI",
"CF_PAGES_UPLOAD_JWT",
"NO_SCRIPT_SIZE_WARNING",
"EXPERIMENTAL_MIDDLEWARE",
"NO_D1_WARNING",
"NO_HYPERDRIVE_WARNING",
Expand Down

0 comments on commit c3e19b7

Please sign in to comment.