Как настроить документацию по политике мониторинга GCP в Terraform?

У нас есть политика оповещения о мониторинге в GCP, которую мы настроили в Terraform. Мы также хотим создать документацию с помощью Terraform.

Мы создаем документацию, используя следующую команду в GCP.

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?

Конфигурация для политики мониторинга:

# 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)}"
}

person Lonely Planeteer    schedule 12.10.2020    source источник


Ответы (2)


Ресурс google_monitoring_alert_policy имеет _ 2_ параметр блокировки, который позволяет настроить документацию Markdown для предупреждения.

Тогда ваш ресурс должен выглядеть следующим образом:

# 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."
  }
}
person ydaetskcoR    schedule 12.10.2020

Вы можете использовать Terraform для создания / обновления блока документации с некоторыми ограничениями.

Блок documentation поддерживает:

content - (Необязательно) Текст документации, интерпретируемый в соответствии с mimeType. Содержимое не может превышать 8192 символа Unicode и не может превышать более 10240 байт при кодировании в формате UTF-8, в зависимости от того, что меньше.

mime_type - (Необязательно) Формат поля содержимого. В настоящее время поддерживается только значение text / markdown.

Однако вы можете использовать формат mime / text и напрямую включать всю информацию.

Также может быть полезно взглянуть на официальный документ GCP документация по documentation блоку в этой функции, но загрузка содержимого из внешнего файла также не документируется.

Упоминание об этой функции в официальных документах находится в Modyfying. Документация по политике.

Но поскольку вы можете сделать это с gcloud alpha, я бы поигрался с Terraform, и, возможно, вы найдете решение, как поместить тип файла в блок документации ...

person Wojtek_B    schedule 12.10.2020