首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Terraform中配置GCP监控策略文档?

如何在Terraform中配置GCP监控策略文档?
EN

Stack Overflow用户
提问于 2020-10-12 14:51:07
回答 2查看 1.7K关注 0票数 1

我们在Terraform中配置的GCP中有一个监控警报策略。我们还想使用Terraform创建一个文档。

我们在GCP中使用以下命令创建文档。

代码语言:javascript
复制
gcloud alpha monitoring policies update projects/project_name/alertPolicies/5861347861929375791 \
--documentation-format="text/markdown" \
--documentation="API has exceeded its quota limit. The systems load has increased beyond capacity, consider increasing your Global and Regional quotas. If this is unexpected behaviour, validate that this is not a bug within your platform."

我们有没有办法在Terraform中创建同样的东西?

监控策略配置:

代码语言:javascript
复制
# Alerts when API seeing errors
resource "google_monitoring_alert_policy" "dlp_api_see_errors" {
  project      = PROJECT_NAME
  display_name = "API is seeing errors"
  combiner     = "OR"
  
  conditions {
    display_name = "API is seeing errors"

    condition_threshold {
      filter          = "metric.type=\"serviceruntime.googleapis.com/api/request_count\" resource.type=\"consumed_api\" metric.label.\"response_code\"!=\"200\" resource.label.\"service\"=\"dlp.googleapis.com\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      aggregations {
        alignment_period     = "60s"
        per_series_aligner   = "ALIGN_SUM"
        cross_series_reducer = "REDUCE_SUM"
      }

      trigger {
        count   = 1
      }
    }
  }

  notification_channels = "${concat(google_monitoring_notification_channel.ndw_alerting_email.*.id, google_monitoring_notification_channel.ndw_alerting_phone.*.id)}"
}
EN

回答 2

Stack Overflow用户

发布于 2020-10-12 18:42:23

google_monitoring_alert_policy resource具有documentation block parameter,可用于设置警报的Markdown文档。

然后,您的资源应如下所示:

代码语言:javascript
复制
# Alerts when API seeing errors
resource "google_monitoring_alert_policy" "dlp_api_see_errors" {
  project      = PROJECT_NAME
  display_name = "API is seeing errors"
  combiner     = "OR"
  
  conditions {
    display_name = "API is seeing errors"

    condition_threshold {
      filter          = "metric.type=\"serviceruntime.googleapis.com/api/request_count\" resource.type=\"consumed_api\" metric.label.\"response_code\"!=\"200\" resource.label.\"service\"=\"dlp.googleapis.com\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      aggregations {
        alignment_period     = "60s"
        per_series_aligner   = "ALIGN_SUM"
        cross_series_reducer = "REDUCE_SUM"
      }

      trigger {
        count   = 1
      }
    }
  }

  notification_channels = "${concat(google_monitoring_notification_channel.ndw_alerting_email.*.id, google_monitoring_notification_channel.ndw_alerting_phone.*.id)}"

  documentation {
    mime_type = "text/markdown"
    content   = "API has exceeded its quota limit. The systems load has increased beyond capacity, consider increasing your Global and Regional quotas. If this is unexpected behaviour, validate that this is not a bug within your platform."
  }
}
票数 2
EN

Stack Overflow用户

发布于 2020-10-12 19:10:16

您可以使用Terraform创建/更新 ,但有一些限制。

documentation block支持:

content -(可选)文档文本,根据mimeType解释。内容不能超过8,192个Unicode字符,以UTF-8格式编码时也不能超过10,240个字节,以较小者为准。

mime_type -(可选)内容字段的格式。目前仅支持"text/markdown“值。

但是,您可以使用"mime/text“格式,并直接包含所有信息。

此外,在此功能中查看一下GCP's official documentation regarding documentation block可能会很有用,但从外部文件加载内容也没有文档记录。

官方文档中只在Modyfying Policy's Documentation中提到了这一特性。

但是既然你可以用gcloud alpha来做这件事,那么我会尝试使用Terraform,也许你会找到一个解决方案,如何在文档块中放入“文件”类型……

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64312963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档