You need to enable JavaScript to run this app. Terraform配置Google Cloud Composer监控:实现未处置事件每30分钟重复告警
优惠活动
大模型
产品
解决方案
定价
更多

Terraform配置Google Cloud Composer监控:实现未处置事件每30分钟重复告警

告警事件未自动解决的核心原因
  • 现有配置匹配的composer.googleapis.com/workflow/task/run_count是累计型计数器指标,值只会随着任务失败次数增加单向上涨,永远不会主动回落。
  • 当前配置使用的ALIGN_COUNT对齐器,会直接统计匹配到的指标样本总数量,不会计算周期内的新增失败增量。这就导致哪怕已经没有新的任务失败,历史累计的失败计数始终大于阈值,系统永远不会触发"告警条件不满足"的恢复判定。
持续重复通知的实现逻辑

Google Cloud Monitoring 原生支持告警事件未处置状态下的重复通知能力,不需要额外搭建循环任务或自定义逻辑,只需要在告警策略中配置对应的重复通知间隔参数即可:当告警事件处于"待处置"状态时,系统会按设定的间隔持续向绑定的通知渠道推送提醒,直到事件被手动标记为已解决,或满足自动恢复条件触发告警闭环。

修正后的可落地Terraform配置
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = ">= 3.5.0"
    }
  }
}

provider "google" {
  credentials = "some_credentials"
  project     = "some_project"
  region      = "some_region"
  zone        = "some_zone"
}

resource "google_monitoring_notification_channel" "basic" {
  display_name = "Test name"
  type         = "email"
  labels = {
    email_address = "some@email.com"
  }
}

resource "google_monitoring_alert_policy" "cloud_composer_job_fail_monitor" {
  combiner              = "OR"
  display_name          = "Fails testing on cloud composer tasks"
  notification_channels = [google_monitoring_notification_channel.basic.id]

  # 配置30分钟重复通知间隔
  notification_strategy {
    notification_channel_strategy {
      channel_name     = google_monitoring_notification_channel.basic.id
      renotify_interval = "1800s"
    }
  }

  conditions {
    display_name = "Failures count"
    condition_threshold {
      filter          = "resource.type=\"cloud_composer_workflow\" AND metric.type=\"composer.googleapis.com/workflow/task/run_count\" AND metric.label.\"state\"=\"failed\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      threshold_value = 0
      aggregations {
        alignment_period   = "3600s"
        # 对累计计数器使用RATE对齐,计算周期内的失败增量
        per_series_aligner = "ALIGN_RATE"
      }
    }
  }

  documentation {
    content = "Please checkout current incident"
  }
}
配置生效后的行为说明
  • 首次检测到1分钟内存在大于0的任务失败增量时,立刻触发首次告警通知
  • 在告警事件未被手动标记为已解决的前提下,系统每隔30分钟重复发送一次告警提醒
  • 当连续一个1小时对齐窗口内没有新增的任务失败,计算得出的失败增量为0,自动触发告警恢复通知,完成事件闭环

内容的提问来源于stack exchange,提问作者Roma D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.29 06:45:05