GCP Alert Filters criteria for multiple resources

1k Views Asked by At

I want to be able to filter multiple subscriptions when setting up GCP Alert. Can someone explain?

I can add multiple filter entries. But they are all combined with AND. So all of them have to be met, and not I wanted.

Ex: Lets say I have subscription-1, ad-subscription-1, auto-subscription-2, my-subscription-dev.

I want to setup alerts for only auto-subscription-2 and my-subscription-dev How to specify that in the filter criteria?

1

There are 1 best solutions below

0
On BEST ANSWER

If you will be using your configuration form your previous question, click on Query Editor and it will show you the equivalent query of your current settings.

enter image description here

In the query, there is a line | filter (resource.subscription_id == 'auto-subscription-2). Simply add || and include your subscription you want to include in the filter. The whole line should look like this after applying the OR expression:

| filter (resource.subscription_id == 'auto-subscription-2' || resource.subscription_id == 'my-subscription-dev')

The whole query should look like this:

fetch pubsub_subscription
| metric 'pubsub.googleapis.com/subscription/num_undelivered_messages'
| filter (resource.subscription_id == 'auto-subscription-2' || resource.subscription_id == 'my-subscription-dev' )
| group_by 2m,
    [value_num_undelivered_messages_mean: mean(value.num_undelivered_messages)]
| every 2m
| condition val() > 5 '1'

NOTE:For testing purposes I originally have 3 subscriptions (test-sub,test-sub-2,test-sub-3) and I filtered test-sub and test-sub-3: enter image description here