sort GCP billing data by metadata tags

498 views Asked by At

I'm a little confused in GCP with tags, labels and metadata and I do not find how to sort my billing informations by the metadata tags i set for every objects in the storage. I have added a metadata tagging process which gives the id of the account that uploads a file through signed url headers or through blobs uploads. Then I launch requests on the billing with big query. ...but I do not see my tags in the "labels" field of the exports How can I enable metadata tags sorting on billing exports ?

Thank you for your help

3

There are 3 answers

0
SANN3 On

Tags data is available in both the Standard usage cost export and the Detailed usage cost export

SELECT
  invoice.month AS invoice_month,
  tag.value AS cost_center,
  ROUND((SUM(CAST(cost AS NUMERIC))
    + SUM(IFNULL((SELECT SUM (CAST(c.amount AS NUMERIC))
                  FROM UNNEST(credits) AS c), 0))), 2)
    AS net_cost
FROM `ivory-vim-309221.billing_export_dataset.gcp_billing_export_resource_v1_018ADD_3CEBBB_A4DF22`, UNNEST(tags) AS tag
WHERE tag.key = "cost_center" AND tag.namespace = "821092389413"
GROUP BY invoice.month, tag.value
ORDER BY invoice.month, tag.value;

https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/standard-usage#tags

0
David Thornton On

GCP billing doesn't break down Bucket costs by object.

It simply tells you how much the whole bucket cost you.

If you want to calculate what portion of your Bucket bill can be attributed to an object you will need to know when the object was uploaded and how big it was, and then do math to calculate the portion of the cost it's responsible for.

You would need to turn on logging on the buck to get that data.