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`: support `documentation.subject` #16419

Open tgeoghegan opened 10 months ago

tgeoghegan commented 10 months ago

Community Note

Description

An alerting policy can have a "documentation" block which allows interpolating labels from resources and metrics into alert notifications. The API object has fields for subject and content (1). I can't set the subject in Terraform, though, because google_monitoring_alert_policy.documentation only has content and mime_type fields.

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_monitoring_alert_policy" "kubernetes_pod_waiting" {
  display_name = "Pod waiting a long time"
  combiner     = "OR"
  documentation {
    content = <<-DESC
    Container $${metric.label.container} has been waiting for fifteen minutes, in
    pod $${metric.label.pod}, in namespace $${resource.label.namespace} due to $${metric.label.reason}.
    DESC
    # The line below is not currently allowed
    subject = "Pod $${resource.label.namespace}/$${resource.label.pod} stuck waiting"
  }
  conditions {
    display_name = "condition 1"
    condition_prometheus_query_language {
      alert_rule = "kubernetes_pod_waiting"
      rule_group = "default"
      query      = <<-QUERY
      sum by (namespace, pod, container, reason) (
            min_over_time(kube_pod_container_status_waiting_reason[15m]) * kube_pod_container_status_waiting_reason
          *
            (kube_pod_container_status_waiting_reason offset 15m)
        >
          0
      )
      QUERY
    }
  }
}

References

b/310896720

lhenn commented 10 months ago

Thanks for creating this issue. ~I'm noticing that the documentation now indicates that a subject field is available, but it doesn't seem to be implemented yet, causing some confusion.~ I see this has been fixed in v5.5.0 despite this issue still being open.