Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use labels in big query queries to track cost?

Is it possible to track the cost of bigquery queries using the configuration.labels attribute on a query request? I have specified some labels and I do find it in the job definition as you can see here:

{
  "configuration": {
    "labels": {
      "label1": "tomas",
      "label2": "yolo"
    },
    "query": {
      "allowLargeResults": false,
      "createDisposition": "CREATE_IF_NEEDED",
      "destinationTable": {
        "datasetId": "dataset",
        "projectId": "project name",
        "tableId": "label "
      },
      "priority": "INTERACTIVE",
      "query": "a select query",
      "useLegacySql": false,
      "writeDisposition": "WRITE_TRUNCATE"
...
}

I have also enabled billing export under billing, but when I look at the exported data I can’t find my labels.

Labeling works fine when applied to dataset and tables, but I can't get it to work with queries. Are these labels for queries something else and doesn't show up in the billing?

like image 522
Tomas Jansson Avatar asked Nov 17 '22 08:11

Tomas Jansson


1 Answers

I have not been able to query or filter on specific labels, but can at least display them with this...

SELECT  service.description, cost, labels
FROM `PROJECTNAME.billing_report.gcp_billing_export_v1_016D47_E84908_9F5AB5` 
WHERE cost > 0
LIMIT 1000
like image 50
user12299611 Avatar answered Dec 10 '22 09:12

user12299611