-
Notifications
You must be signed in to change notification settings - Fork 3
/
alerts.tf
84 lines (78 loc) · 2.68 KB
/
alerts.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
resource "google_logging_metric" "pipeline_status_failed" {
name = var.random_suffix ? "crmint/pipeline_status_failed-${random_id.suffix.hex}" : "crmint/pipeline_status_failed"
description = "Managed by ${local.managed_by_desc}"
filter = "resource.type=cloud_run_revision AND jsonPayload.log_type=PIPELINE_STATUS AND jsonPayload.labels.pipeline_status=failed"
metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
unit = "1"
labels {
key = "pipeline_id"
value_type = "STRING"
description = "Pipeline ID"
}
labels {
key = "message"
value_type = "STRING"
description = "Error message"
}
display_name = "Pipeline Status Failed Metric"
}
label_extractors = {
"pipeline_id" = "EXTRACT(jsonPayload.labels.pipeline_id)"
"message" = "EXTRACT(jsonPayload.message)"
}
depends_on = [google_project_service.apis]
}
resource "google_monitoring_notification_channel" "email" {
display_name = "Email Notification Channel"
type = "email"
labels = {
email_address = var.notification_sender_email
}
force_delete = false
enabled = true
depends_on = [google_project_service.apis]
}
resource "google_monitoring_alert_policy" "notify_on_pipeline_status_failed" {
display_name = "Pipeline Status Failed Alert Policy"
enabled = true
combiner = "OR"
conditions {
display_name = "Monitor pipeline errors"
condition_threshold {
filter = "metric.type=\"logging.googleapis.com/user/${google_logging_metric.pipeline_status_failed.id}\" AND resource.type=cloud_run_revision"
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 0.001
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
cross_series_reducer = "REDUCE_NONE"
per_series_aligner = "ALIGN_COUNT"
}
}
}
notification_channels = [google_monitoring_notification_channel.email.id]
depends_on = [
google_project_service.apis,
google_logging_metric.pipeline_status_failed
]
}