Adding billing labels to AlloyDB

I’d like to add a GCP label to an AlloyDB cluster - mostly for purposes of accounting. Is this possible?

I followed a guide which used the REST API to add a label, but these labels do not show up in the detailed billing export in BigQuery.

AlloyDB clusters in Google Cloud do not directly support labels for billing or organization. However, you can utilize tags, which are similar to labels, for cost allocation and reporting. Additionally, your BigQuery billing export includes resource-level labels associated with various services, which might be helpful for your accounting needs.

Here’s how you can use tags for AlloyDB clusters:

  1. Google Cloud Console:

    • Go to the “Resource Manager” section in the Google Cloud Console.
    • Select the project or organization where your AlloyDB cluster resides.
    • Navigate to the “Tags” tab.
    • Add your tags in the format key:value.
    • Ensure that the tags are propagated to your AlloyDB cluster.
  2. gcloud CLI:

    • Use the gcloud resource-manager tags create command to create tags.
    • Use the gcloud alpha alloydb clusters update command with the --add-tags flag to add tags to your cluster.
  3. REST API:

    • Refer to the Google Cloud documentation for instructions on how to manage tags using the Resource Manager API.

Ensuring Tags Appear in Billing Export:

  • Verify that your billing export to BigQuery is configured to include detailed usage cost data.
  • Check that the labels column in your BigQuery billing export dataset includes the relevant tags.
  • Use SQL queries in BigQuery to filter and analyze your billing data based on the applied tags.

Example Query:

SELECT
  resource.name,
  labels
FROM
  `your_project.your_dataset.gcp_billing_export_v1_your_billing_account_id`
WHERE
  service.description = 'AlloyDB for PostgreSQL'
  AND labels.key = 'your_tag_key'