Cloud Run alerting configuration with Terraform

62 views
Skip to first unread message

Thomas ZAEPFFEL

unread,
Nov 22, 2022, 12:42:51 PM11/22/22
to Google Stackdriver Discussion Forum
Hi All,

I'm trying to code a Cloud Run active  instance count alert with Terraform.

I've tried that, build with samples found on the web  :

 resource "google_monitoring_alert_policy" "cloud_run_instances_count" {
  display_name = "CR Instances count"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_threshold {
      filter     = "metric.type=\"run.googleapis.com/container/instance_count\" AND metric.labels.state=\"active\" AND resource.type=\"metric\""
      duration   = "60s"
      comparison = "COMPARISON_GT"
      aggregations {
        alignment_period   = "60s"
        per_series_aligner = "ALIGN_RATE"
      }
      trigger {
        count   = 4
      }
    }
   
  }

 notification_channels = "${google_monitoring_notification_channel.xxx.*.id}"
}

But I have the following errors :

Error: Error creating AlertPolicy: googleapi: Error 400: The supplied filter does not specify a valid combination of metric and monitored resource descriptors. The query will not return any time series.
with google_monitoring_alert_policy.cloud_run_instances_count
on _alerting.tf line 11, in resource "google_monitoring_alert_policy" "cloud_run_instances_count":resource "google_monitoring_alert_policy" "cloud_run_instances_count" {

I have no more ideas to make it working; any help would be appreciated !
thks
T.

Jeff Erbrecht

unread,
Nov 22, 2022, 1:13:24 PM11/22/22
to Google Stackdriver Discussion Forum
Hi Thomas,

Per https://cloud.google.com/monitoring/api/metrics_gcp, the resource for run.googleapis.com/container/instance_count should be cloud_run_revision instead of metric.

Hope this helps,
Jeff

Thomas ZAEPFFEL

unread,
Nov 22, 2022, 2:22:17 PM11/22/22
to Google Stackdriver Discussion Forum
Hi Jeff,

Thank you,

I've replaced the line 
  filter     = "metric.type=\"run.googleapis.com/container/instance_count\" AND metric.labels.state=\"active\" AND resource.type=\"metric\""
with 
filter     = "metric.type=\"run.googleapis.com/container/instance_count\" AND metric.label.state=\"active\" AND resource.type=\"cloud_run_revision\""

Seems better but an other error occured :

Error: Error creating AlertPolicy: googleapi: Error 400: Field aggregation.perSeriesAligner had an invalid value of "ALIGN_RATE": The aligner cannot be applied to metrics with kind GAUGE and value type INT64.
...

Igor Peshansky

unread,
Nov 22, 2022, 4:49:28 PM11/22/22
to Thomas ZAEPFFEL, Google Stackdriver Discussion Forum
The ALIGN_RATE aligner is only valid for CUMULATIVE or DELTA metrics [1]. You need to select an aligner that is valid for GAUGE metrics.

--
© 2021 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Stackdriver Discussion Google Group (google-stackdr...@googlegroups.com) to participate in discussions with other members of the GoogleStackdriver community.
---
You received this message because you are subscribed to the Google Groups "Google Stackdriver Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-stackdriver-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-stackdriver-discussion/61d59742-3144-4c93-ae74-dec3ff7ddebfn%40googlegroups.com.

Thomas ZAEPFFEL

unread,
Nov 23, 2022, 3:40:46 AM11/23/22
to Google Stackdriver Discussion Forum
Hi,

Works fine with :
 per_series_aligner = "ALIGN_MEAN"
instead of 
per_series_aligner = "ALIGN_RATE"

Thks !

Thomas ZAEPFFEL

unread,
Nov 23, 2022, 4:37:50 AM11/23/22
to Google Stackdriver Discussion Forum
Now I'm trying to monitor the Cloud Run requests count with this filter:
filter     = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\""

is there a way to add to the filter the service_name field? I did not find the correct prefix/syntax :
filter     = "metric.type=\"run.googleapis.com/request_count\" AND <prefix>.service_name=\"name\" AND resource.type=\"cloud_run_revision\""
thks,
T.

Thomas ZAEPFFEL

unread,
Nov 23, 2022, 11:08:24 AM11/23/22
to Google Stackdriver Discussion Forum
Found the solution:
filter     = "metric.type=\"run.googleapis.com/request_count\" AND resource.label.service_name=\"name\" AND resource.type=\"cloud_run_revision\""

Reply all
Reply to author
Forward
0 new messages