How does it work?
A dive into how the extension technically works.
Last updated
A dive into how the extension technically works.
Last updated
At a high-level, the Auto Stop Services extension monitors a Budget you define and will take action when the project cost has met the defined budget.
All Firebase services are usage based and, beyond their free tier limit, will generate cost to the project. The cost is monitored through a Billing Account where a project Budget is defined (in dollar terms).
A Budget can produce an Alert when specific thresholds (in percentage terms) are met - for example a $100 budget will default to a 50%, 90%, and 100% threshold. At each threshold the Budget will generate an Alert - though the indicates there may be several Alerts generated and not always when the threshold is met, but let's not worry about that.
There is a separate threshold defined in the Auto Stop Services extension, which we will call the Extension Threshold. This is the percentage threshold of your budget that must be met for the Auto Stop Services to actually kick into gear and stop your project services. This defaults to 100%, so if your project cost meets or exceeds your budget, your project services will stop.
The general process is that a Budget raises an Alert which is fed into a Firebase Function (via a Pub/Sub topic). The Function will check that the threshold is met and will stop services if the threshold is met, otherwise nothing.
Case 1 - Alert raised, below Extension Threshold
Given we have a budget of $100 and our Extension Threshold is 100% When our project cost is $50 (i.e. 50% of budget) Then we do nothing
Case 2 - Alert raised at Extension Threshold
Given we have a budget of $100 and our Extension Threshold is 100% When our project cost is $100 (i.e. 100% of budget) Then we trigger a stop action, based on your strategy.
Case 3 - Alert raised above Extension Threshold
Given we have a budget of $100 and our Extension Threshold is 100% When our project cost is $110 (i.e. 110% of budget) Then we trigger a stop action, based on your strategy.
When a budget threshold is met, a stop action is required which tells the extension what to do if you have a cost blowout. Currently, this extension provides two strategies to choose from:
Strategy 1: Remove the billing account from your project, thereby freezing your project.
Strategy 2: Disables pre-defined Google Cloud Platform services in your project, thereby disabling specific parts of your project.
Recommended: Strategy 1 is highly recommended due for simplicity and ease of recovery.
Warning: Strategy 2 is dangerous and involves removal of project resources. Only experienced GCP and Firebase users should use this strategy.
This strategy involves the extension disconnecting the Billing Account from your project. Conceptually, Google Cloud Platform will only allow you to use services if a Billing Account is connected to your project. So, if we remove this connection - voila!
What does this mean for your project?
All paid services within the project are immediately suspended. This includes compute instances, databases, and other cloud services that incur costs.
You can still access and view resources in the Google Cloud Console, but you cannot create new resources or use services that require billing.
Data stored in services like Cloud Storage, Firestore, and databases is preserved but may become inaccessible until billing is re-enabled.
Essential Google Cloud services remain available for managing projects and restoring billing, this includes IAM and Google Cloud Console access.
Any pending charges will still be billed. This includes those accrued before the billing account was removed, though no new charges will be generated until billing is re-established.
How do you recover from this approach?
This strategy involves disabling specific Google Cloud Platform services. Firebase is inherently dependent on GCP services to deliver it's functional capabilities - thus if we disable a GCP service, naturally the Firebase service is disabled. This approach is dangerous as resources can be entirely removed and recovery complicated - hence this is only recommended for the advanced users.
What does this mean for your project?
The disabled service immediately stops all operations. For example, when disabling cloud functions, Firebase functions will no longer function and resources removed.
You cannot create new resources or view resources for disabled services. Attempts to do so will result in errors.
Existing resources for the disabled service may be removed. We should always assume complete deletion, this includes data (e.g. Firestore and Storage) and compute (Firebase Functions).
Essential Google Cloud services remain available unless explicitly disabled, this includes IAM and Google Cloud Console access.
Any pending charges will still be billed. This includes those accrued before the billing account was removed, though no new charges will be generated until billing is re-established.
How do you recover from this approach?
Auto Stop Services will receive the Alert via a Pub/Sub topic, and if it meets or exceeds the user defined threshold it will trigger a stop action based on your defined strategy (see below).
Recovery is incredibly simple. You manually reconnect your Billing Account to the project. A full guide on recovery for this strategy can be found in the section.
Recovery approach is highly dependent on which APIs you disable and your project setup. Broadly speaking, you will have to re-enable the APIs and potentially re-deploy part (or all) of your project. A full guide on recovery for this strategy can be found in the section.