Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added `crashlytics:heapdumps:{enable,disable,status}` commands to manage Crashlytics Android heap dump collection. (#11225)
33 changes: 33 additions & 0 deletions src/commands/crashlytics-heapdumps-disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as clc from "colorette";

import { Command } from "../command";
import { logger } from "../logger";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { requireAuth } from "../requireAuth";
import { disableHeapDumpCollection, resolveAndroidAppId } from "../crashlytics/profilingManager";

interface CommandOptions extends Options {
app?: string;
}

export const command = new Command("crashlytics:heapdumps:disable")
.description("disable Crashlytics heap dump collection for an Android app")
.option("--app <appID>", "the app id of your Firebase Android app")
.before(requireAuth)
.action(async (options: CommandOptions) => {
const projectId = needProjectId(options);
const appId = await resolveAndroidAppId(projectId, options);

await disableHeapDumpCollection(appId);

logger.info("");
logger.info(clc.bold("Heap Dump Collection Details:"));
logger.info(` App ID: ${clc.cyan(appId)}`);
logger.info(` Status: ${clc.red("Disabled")}`);

return {
appId,
heapDumpCollectionEnabled: false,
};
});
84 changes: 84 additions & 0 deletions src/commands/crashlytics-heapdumps-enable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import * as clc from "colorette";

import { Command } from "../command";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { confirm } from "../prompt";
import { requireAuth } from "../requireAuth";
import { consoleUrl } from "../utils";
import * as cloudbilling from "../gcp/cloudbilling";
import {
createBucketName,
DEFAULT_BUCKET_LOCATION,
DEFAULT_FILE_TTL_DAYS,
enableHeapDumpCollection,
resolveAndroidAppId,
} from "../crashlytics/profilingManager";

interface CommandOptions extends Options {
app?: string;
location?: string;
}

export const command = new Command("crashlytics:heapdumps:enable")
.description("enable Crashlytics heap dump collection for an Android app")
.option("--app <appID>", "the app id of your Firebase Android app")
.option(
"--location <location>",
`the location for the Cloud Storage bucket (default: ${DEFAULT_BUCKET_LOCATION})`,
DEFAULT_BUCKET_LOCATION,
)
.withForce("automatically configure without prompting for confirmation")
.before(requireAuth)
.action(async (options: CommandOptions) => {
const projectId = needProjectId(options);
const appId = await resolveAndroidAppId(projectId, options);
const location = options.location || DEFAULT_BUCKET_LOCATION;

// 1. Verify project billing is enabled (required for GCS bucket creation and storage)
const isBillingEnabled = await cloudbilling.checkBillingEnabled(projectId);
if (!isBillingEnabled) {
throw new FirebaseError(
`Project '${projectId}' is not on the Blaze (pay-as-you-go) plan. Crashlytics heap dump collection requires the Blaze plan for Google Cloud Storage.\n` +
`To upgrade your project, visit: ${consoleUrl(projectId, "/usage/details")}`,
);
Comment thread
anitdas marked this conversation as resolved.
}

// 2. Derive deterministic bucket name
const bucketName = createBucketName(appId);

// 3. Confirm with user if running interactively without --force
const confirmed = await confirm({
message: `Enable Crashlytics heap dump collection for ${appId} using Cloud Storage bucket '${bucketName}' in ${location} (with ${DEFAULT_FILE_TTL_DAYS}-day file TTL)?`,
default: true,
force: options.force,
nonInteractive: options.nonInteractive,
});

if (!confirmed) {
logger.info("Heap dump collection enablement canceled.");
return;
}

// 4. Provision / configure GCS bucket, IAM roles, and Profiling Manager config
await enableHeapDumpCollection(projectId, appId, location);

logger.info("");
logger.info(clc.bold("Heap Dump Collection Details:"));
logger.info(` App ID: ${clc.cyan(appId)}`);
logger.info(` GCS Bucket: ${clc.cyan(bucketName)}`);
logger.info(` File TTL: ${clc.cyan(`${DEFAULT_FILE_TTL_DAYS} days`)}`);
logger.info(` Status: ${clc.green("Enabled")}`);
logger.info("");
logger.info(
`View collected heap dumps in the Firebase Console: ${consoleUrl(projectId, `/crashlytics/app/${appId}`)}`,
);

return {
appId,
bucketName,
heapDumpCollectionEnabled: true,
};
});
40 changes: 40 additions & 0 deletions src/commands/crashlytics-heapdumps-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as clc from "colorette";
import * as Table from "cli-table3";
Comment thread
anitdas marked this conversation as resolved.

import { Command } from "../command";
import { logger } from "../logger";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { requireAuth } from "../requireAuth";
import { getProfilingManagerConfig, resolveAndroidAppId } from "../crashlytics/profilingManager";

interface CommandOptions extends Options {
app?: string;
}

export const command = new Command("crashlytics:heapdumps:status")
.description("get Crashlytics heap dump collection status and configuration for an Android app")
.option("--app <appID>", "the app id of your Firebase Android app")
.before(requireAuth)
.action(async (options: CommandOptions) => {
const projectId = needProjectId(options);
const appId = await resolveAndroidAppId(projectId, options);

const config = await getProfilingManagerConfig(appId);

const tableHead = ["App ID", "Collection Status", "Cloud Storage Bucket"];
const table = new Table({ head: tableHead, style: { head: ["green"] } });
table.push([
appId,
config.heapDumpCollectionEnabled ? clc.green("Enabled") : clc.red("Disabled"),
config.gcsBucket || clc.yellow("(none)"),
]);

logger.info("");
logger.info(table.toString());

return {
appId,
...config,
};
});
Loading
Loading