Kaustubh Ghole
Kaustubh Ghole

Reputation: 587

Can we have single metric for multiple GCP resources using advanced filter query in stackdriver logging?

The python code which I have written, it generates some global and BigQuery related logs on stackdriver logging window. Further I am trying to create a metric manually and then send some alerts. I wanted to know whether we can create a single metric for both global and bigquery logs on stackdriver?

In Advanced filter query I tried: resource.type="bigquery_resource" AND resource.type="global" severity=ERROR

but its give error: "Invalid request: Request contains an invalid argument"

Then I tried: resource.type="bigquery_resource", "global" AND severity=ERROR

again it gives error: "Invalid request: Unparseable filter: syntax error at line 1, column 33, token ','"

import logging
from google.cloud import logging as gcp_logging

client = gcp_logging.Client()
client.setup_logging()

try:
    if row_count_before.num_rows == row_count_after.num_rows:
        logging.error("Received empty query result")
    else:
        newly_added_rows = row_count_after.num_rows - row_count_before.num_rows
        logging.info("{} rows are found as query result".format(newly_added_rows))
except RuntimeError:
    logging.error("Exception occured {}".format(client1.report_exception()))

Looking for a approach where I can have single metric for multiple resource type. Thank you.

Upvotes: 1

Views: 684

Answers (1)

Yuri Grinshteyn
Yuri Grinshteyn

Reputation: 727

I think you want

resource.type="bigquery_resource" OR resource.type="global" severity=ERROR

Upvotes: 2

Related Questions