【问题标题】:How to create an alert policy for unknown custom metric in GCP如何在 GCP 中为未知的自定义指标创建警报策略
【发布时间】:2020-12-20 19:45:06
【问题描述】:

鉴于 GCP 中的以下警报策略(使用 terraform 创建)

resource "google_monitoring_alert_policy" "latency_alert_policy" {
  display_name = "Latency of 95th percentile more than 1 second"
  combiner     = "OR"
  conditions {
    display_name = "Latency of 95th percentile more than 1 second"
    condition_threshold {
      filter     = "metric.type=\"custom.googleapis.com/http/server/requests/p95\" resource.type=\"k8s_pod\""
      threshold_value = 1000
      duration   = "60s"
      comparison = "COMPARISON_GT"
      aggregations {
        alignment_period = "60s"
        per_series_aligner= "ALIGN_NEXT_OLDER"
        cross_series_reducer= "REDUCE_MAX"
        group_by_fields      = [
          "metric.label.\"uri\"",
          "metric.label.\"method\"",
          "metric.label.\"status\"",
          "metadata.user_labels.\"app.kubernetes.io/name\"",
          "metadata.user_labels.\"app.kubernetes.io/component\""
        ]
      }
      trigger {
        count = 1
        percent = 0
      }
    }
  }
}

我收到以下此错误(它是 terraform 项目的一部分,也在创建集群):

Error creating AlertPolicy: googleapi: Error 404: The metric referenced by the provided filter is unknown. Check the metric name and labels.

现在,这是一个自定义指标(由带有 Micrometer 的 Spring Boot 应用程序),因此在创建基础架构时该指标不存在。 GCP 在为它创建警报之前是否必须知道一个指标?这意味着必须在集群上部署 Spring Boot 应用程序并发送指标,然后才能创建此策略?

我是否遗漏了一些东西...(像这样不应该在 terraform、基础设施中完成)?

【问题讨论】:

    标签: google-cloud-platform terraform google-cloud-stackdriver


    【解决方案1】:

    有趣的问题,404 错误的原因是因为找不到资源,描述符似乎有一个预先存在的先决条件。我会先创建metric descriptor,您可以使用this 作为参考,然后继续创建警报策略。

    这是一种巧妙的方法,您可以避免它。如果它有意义,请发表评论,如果你让它像这样工作,请分享它。

    【讨论】:

    • 我觉得有道理,明天试试
    【解决方案2】:

    供参考(这个可以参考terraform doc的警报策略):

    resource "google_monitoring_metric_descriptor" "p95_latency" {
      description = ""
      display_name = ""
      type = "custom.googleapis.com/http/server/requests/p95"
      metric_kind = "GAUGE"
      value_type = "DOUBLE"
    
      labels {
        key = "status"
      }
      labels {
        key = "uri"
      }
      labels {
        key = "exception"
      }
      labels {
        key = "method"
      }
      labels {
        key = "outcome"
      }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 1970-01-01
      • 2018-08-05
      • 2022-08-19
      • 1970-01-01
      • 2022-12-22
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      相关资源
      最近更新 更多