无法使用 Terraform 在 google_monitoring_alert_policy 中为 GCP 警报策略添加多个条件
Not able to add multiple conditions in google_monitoring_alert_policy for GCP alerting policy using Terraform
请告诉我如何通过 Terraform 在 GCP 警报策略中提及多个条件。我尝试了几种创建条件列表的方法,如文档中所述,但没有任何效果。
下面是代码片段:
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "Request count Policy"
combiner = "OR"
conditions = [
display_name = "Request count condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger = {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
},
display_name = "Request latencies condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger = {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
}
]
documentation {
content = "The cloud run based request count alerting policy."
}
notification_channels = [
google_monitoring_notification_channel.email0.id
]
user_labels = {
name = "offer-engine-alert-policy"
}
}
以下语法对我有用。我没有使用 [] 声明列表,而是重复了条件块并且它起作用了!!
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "Request count Policy"
combiner = "OR"
conditions {
display_name = "Request count condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
}
}
conditions {
display_name = "Request latencies condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
}
}
documentation {
content = "The cloud run based request count alerting policy."
}
notification_channels = [
google_monitoring_notification_channel.email0.id
]
user_labels = {
name = "alert-policy"
}
}
请告诉我如何通过 Terraform 在 GCP 警报策略中提及多个条件。我尝试了几种创建条件列表的方法,如文档中所述,但没有任何效果。
下面是代码片段:
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "Request count Policy"
combiner = "OR"
conditions = [
display_name = "Request count condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger = {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
},
display_name = "Request latencies condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger = {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
}
]
documentation {
content = "The cloud run based request count alerting policy."
}
notification_channels = [
google_monitoring_notification_channel.email0.id
]
user_labels = {
name = "offer-engine-alert-policy"
}
}
以下语法对我有用。我没有使用 [] 声明列表,而是重复了条件块并且它起作用了!!
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "Request count Policy"
combiner = "OR"
conditions {
display_name = "Request count condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
}
}
conditions {
display_name = "Request latencies condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
}
}
documentation {
content = "The cloud run based request count alerting policy."
}
notification_channels = [
google_monitoring_notification_channel.email0.id
]
user_labels = {
name = "alert-policy"
}
}