Nacho Gallego
Nacho Gallego

Reputation: 19

How to get Bigquery table's name inside a Stackdriver alert documentation

I've created a Stackdriver Monitoring alert to send me an email when one of my BigQuery tables increases its size more than 5% during the day. The alert is working fine, but I would like to receive information on what is the table that is triggering the alert.

I have tried several combinations that I have found in the GCP docs but none of them work for me. Right now my documentation template looks like this:

resource.label.table: ${resource.label.table} --> Returns null

condition.name: ${condition.name}
condition.display_name: ${condition.display_name}
metric.type: ${metric.type}
metric.display_name: ${metric.display_name}
policy.name: ${policy.name}
policy.display_name: ${policy.display_name}
project: ${project}
resource.type: ${resource.type}

Does anyone know how to retrieve the table name?

Upvotes: 1

Views: 708

Answers (1)

Guillem Xercavins
Guillem Xercavins

Reputation: 7058

As you can see in the list of BigQuery metrics, the resource.type can be global, bigquery_project or bigquery_dataset. Metrics can include additional labels that can be accessed through metric.labels.[KEY]. For example, the storage/uploaded_row_count metric reports api and table:

enter image description here

To test this we create an alerting policy that checks whenever rows are uploaded to a table:

enter image description here

Using the following documentation template with ${metric.labels.table}:

## BigQuery uploaded rows alert

metric.labels.table: ${metric.labels.table}

---

condition.name: ${condition.name}

condition.display_name: ${condition.display_name}

metric.type: ${metric.type}

metric.display_name: ${metric.display_name}

policy.name: ${policy.name}

policy.display_name: ${policy.display_name}

project: REDACTED

resource.type: ${resource.type}

Then we load some rows to a BigQuery table and, when the metric data is available after ~6 hours, we should get the alert mail with the correct table name (cloudaudit_googleapis_com_data_access_20191223 in this case):

enter image description here


EDIT: it also works fine with the bigquery.googleapis.com/storage/stored_bytes metric:

enter image description here

Upvotes: 1

Related Questions