Skip to content

Commit

Permalink
chore: add upload duration and sourcemap size to metrics
Browse files Browse the repository at this point in the history
Adds `durationMs` and `sourceMapSize` properties to the `deploy worker script`
metrics event as well as sending the event after the deploy request.
  • Loading branch information
zebp committed Jul 5, 2024
1 parent c6c083f commit 9c48ac3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-actors-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Add duration and sourcemap size to upload metrics event
23 changes: 17 additions & 6 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ Update them to point to this script instead?`;
return domains.map((domain) => renderRoute(domain));
}

export default async function deploy(props: Props): Promise<void> {
export default async function deploy(
props: Props
): Promise<{ sourceMapSize?: number }> {
// TODO: warn if git/hg has uncommitted changes
const { config, accountId, name } = props;
if (!props.dispatchNamespace && accountId && name) {
Expand All @@ -324,14 +326,14 @@ export default async function deploy(props: Props): Promise<void> {
`You are about to publish a Workers Service that was last published via the Cloudflare Dashboard.\nEdits that have been made via the dashboard will be overridden by your local code and config.`
);
if (!(await confirm("Would you like to continue?"))) {
return;
return {};
}
} else if (default_environment.script.last_deployed_from === "api") {
logger.warn(
`You are about to publish a Workers Service that was last updated via the script API.\nEdits that have been made via the script API will be overridden by your local code and config.`
);
if (!(await confirm("Would you like to continue?"))) {
return;
return {};
}
}
} catch (e) {
Expand Down Expand Up @@ -441,7 +443,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
const yes = await confirmLatestDeploymentOverwrite(accountId, scriptName);
if (!yes) {
cancel("Aborting deploy...");
return;
return {};
}
}

Expand Down Expand Up @@ -473,6 +475,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
);
}

let sourceMapSize;

try {
if (props.noBundle) {
// if we're not building, let's just copy the entry to the destination directory
Expand Down Expand Up @@ -676,6 +680,11 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
limits: config.limits,
};

sourceMapSize = worker.sourceMaps?.reduce(
(acc, m) => acc + m.content.length,
0
);

await printBundleSize(
{ name: path.basename(resolvedEntryPointPath), content: content },
modules
Expand Down Expand Up @@ -810,7 +819,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m

if (props.dryRun) {
logger.log(`--dry-run: exiting now.`);
return;
return {};
}
assert(accountId, "Missing accountId");

Expand All @@ -821,7 +830,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
// Early exit for WfP since it doesn't need the below code
if (props.dispatchNamespace !== undefined) {
deployWfpUserWorker(props.dispatchNamespace, deploymentId);
return;
return {};
}

// deploy triggers
Expand All @@ -831,6 +840,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
logger.log("Current Version ID:", deploymentId);

logVersionIdChange();

return { sourceMapSize };
}

function deployWfpUserWorker(
Expand Down
24 changes: 14 additions & 10 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export function deployOptions(yargs: CommonYargsArgv) {
export async function deployHandler(
args: StrictYargsOptionsToInterface<typeof deployOptions>
) {
const beforeUpload = Date.now();
await printWranglerBanner();

// Check for deprecated `wrangler publish` command
Expand All @@ -231,15 +232,6 @@ export async function deployHandler(
const projectRoot = configPath && path.dirname(configPath);
const config = readConfig(configPath, args);
const entry = await getEntry(args, config, "deploy");
await metrics.sendMetricsEvent(
"deploy worker script",
{
usesTypeScript: /\.tsx?$/.test(entry.file),
},
{
sendMetrics: config.send_metrics,
}
);

if (args.public) {
throw new UserError("The --public field has been renamed to --assets");
Expand Down Expand Up @@ -287,7 +279,7 @@ export async function deployHandler(
await standardPricingWarning(config);
}

await deploy({
const { sourceMapSize } = await deploy({
config,
accountId,
name: getScriptName(args, config),
Expand Down Expand Up @@ -322,4 +314,16 @@ export async function deployHandler(
dispatchNamespace: args.dispatchNamespace,
experimentalVersions: args.experimentalVersions,
});

await metrics.sendMetricsEvent(
"deploy worker script",
{
usesTypeScript: /\.tsx?$/.test(entry.file),
durationMs: Date.now() - beforeUpload,
sourceMapSize,
},
{
sendMetrics: config.send_metrics,
}
);
}

0 comments on commit 9c48ac3

Please sign in to comment.