hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

google_monitoring_alert_policy: doesn't support timeWindow #4528

Open IRus opened 4 years ago

IRus commented 4 years ago

Community Note

Description

I'd like to specify Metric rate (percent) of change condition for alert policy with tf

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_monitoring_alert_policy" "my_endpoint_p2" {
  display_name = "My Endpoint"
  enabled = true
  combiner = "OR"

  conditions {
    display_name = "Fallback calls count"
    condition_threshold {
      aggregations {
        alignment_period = "60s"
        cross_series_reducer = "REDUCE_SUM"
        per_series_aligner = "ALIGN_PERCENT_CHANGE"
      }
      comparison = "COMPARISON_GT"
      time_window = "300s"
      filter = "metric.type=\"custom.googleapis.com/my/endpoint/http/fallback\" resource.type=\"global\""
      threshold_value = 5
      trigger {
        count = 1
      }
    }
  }

  notification_channels = [...]
}
IRus commented 4 years ago
image

Export of JSON from stackdriver policy details page

{
  "combiner": "OR",
  "conditions": [
    {
      "conditionRate": {
        "aggregations": [
          {
            "alignmentPeriod": "60s",
            "crossSeriesReducer": "REDUCE_SUM",
            "perSeriesAligner": "ALIGN_MEAN"
          }
        ],
        "comparison": "COMPARISON_GT",
        "filter": "metric.type=\"custom.googleapis.com/my/endpoint/http/fallback\" resource.type=\"global\"",
        "thresholdValue": 5,
        "timeWindow": "300s",
        "trigger": {
          "count": 1
        }
      },
      "displayName": "Fallback calls count"
    }
  ],
  "displayName": "My Endpoint",
  "enabled": true,
  "notificationChannels": [...]
}
namelessvoid commented 4 years ago

I did not look too much into detail but it seems that we also need a condition_rate here (see line 5 in the JSON posted in the previous comment)?

However, the official API documentation does neither cover timeWindow nor conditionRate at time of writing. Maybe this is because google flags the alert policy API as "beta" and does not support rate conditions officially at the moment?

AlfatahB commented 1 year ago

b/262484991

AlfatahB commented 1 year ago

I've looked into this issue and the following are the details that I have found out:

Hence, Adding the support for these fields in the terraform requires the API to support these fields as well.