This extension is intended to support development, or early stage production environments from accruing significant costs by stopping services. This is a challenge as cloud platforms are usage based, and many methods provided by cloud providers are intended to support service uptime; and will not make any effort to mitigate unintended service overuse. Billing alerts are out of the box only intended to alert administrators that a budget threshold has been reached, but not take any action.
This Firebase extension monitors the associated budget and implements one of two strategies when a specified budget threshold is reached:
When a billing account is removed from a project:
This strategy prevents additional costs from accruing but has an immediate impact on service availability.
When specific services are disabled (e.g., compute.googleapis.com
, cloudfunctions.googleapis.com
):
compute.googleapis.com
halts all running VM instances, and disabling cloudfunctions.googleapis.com
stops all Cloud Functions executions.This strategy offers granular control over cost management by allowing selective service suspension while preserving critical operational functionality.
During the extension installation, you will be asked to configure it with the following parameters:
TOPIC_NAME
defines the name of the pub/sub topic. A billing alert is published here, which will trigger the auto-stop (if the threshold is reached).BUDGET_STOP_THRESHOLD_PERCENT
defines the percentage (0.0-1.0) of the budget that will trigger the stop strategy, default is 1.0 (100%)DISABLE_BILLING
enables strategy 1 - to remove the billing account (requires project billing manager
role), defaults to falseDISABLE_API_LIST
enables strategy 2 - to disable services (requires service usage admin
role), defaults to none (empty)LOCATION
defines the deployment location for the cloud function, defaults to use-central1After installing the extension, you must:
Set Up a Budget
Connect the Budget to a Predefined Topic
{TOPIC_NAME}
.Update the Service Account Permissions
{EXTENSION_NAME}@{PROJECT_ID}.iam.gserviceaccount.com
:
roles/billing.projectManager
) to manage project billing settings.roles/serviceusage.serviceUsageAdmin
) for enabling/disabling service APIs.Note: Disabling the Cloud Functions service API (cloudfunctions.googleapis.com
) will remove the extension's functions, effectively uninstalling the extension. This will always be disabled last.
When a budget alert fires, the message content will look like the below:
{
"budgetDisplayName": "Your Budget Name",
"alertThresholdExceeded": 0.5,
"costAmount": 500.0,
"costIntervalStart": "2021-01-01T00:00:00Z",
"budgetAmount": 1000.0,
"budgetAmountType": "SPECIFIED_AMOUNT",
"currencyCode": "USD",
"schemaVersion": "1.0",
"notificationType": "ACTUAL",
"projectId": "your-project-id",
"billingAccountId": "012345-6789AB-CDEF01"
}
The key element of this message is the alertThresholdExceeded
, all other information is effectively discarded.
Once you have followed the steps, you can submit a message through the pub/sub topic. Any results will be published as logs, which you can monitor.
This example message will not execute any strategy.
{
"extensionTest": true
}