|
| 1 | +resource "google_monitoring_notification_channel" "email" { |
| 2 | + |
| 3 | + for_each = nonsensitive(var.alert_email_map) |
| 4 | + display_name = "Pipeline Alert - ${each.value}" |
| 5 | + type = "email" |
| 6 | + labels = { email_address = each.value } |
| 7 | +} |
| 8 | + |
| 9 | +# All severity CRITICAL are open for 6 hours with 30mins interval repeat notification |
| 10 | +resource "google_monitoring_alert_policy" "pipeline_failure" { |
| 11 | + display_name = "Pipeline Failure Alert" |
| 12 | + combiner = "OR" |
| 13 | + severity = "CRITICAL" |
| 14 | + |
| 15 | + notification_channels = [for channel in google_monitoring_notification_channel.email : channel.name] |
| 16 | + |
| 17 | + conditions { |
| 18 | + display_name = "pipeline_crashed" |
| 19 | + |
| 20 | + condition_matched_log { |
| 21 | + filter = <<-EOT |
| 22 | + resource.type="cloud_run_job" |
| 23 | + resource.labels.job_name="operations-pipeline${var.environment}" |
| 24 | + textPayload:"[ERROR]" |
| 25 | + EOT |
| 26 | + } |
| 27 | + } |
| 28 | + alert_strategy { |
| 29 | + |
| 30 | + auto_close = "21600s" |
| 31 | + notification_prompts = ["OPENED"] |
| 32 | + |
| 33 | + notification_rate_limit { |
| 34 | + period = "1800s" |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + documentation { |
| 39 | + mime_type = "text/markdown" |
| 40 | + content = <<-EOT |
| 41 | + ## ALERT: Operations Pipeline Processing Failed! |
| 42 | +
|
| 43 | + **What Happened:** The `operations-pipeline-${var.environment}` Cloud Run Job crashed during data processing. |
| 44 | +
|
| 45 | + **Impact:** The raw data was extracted, but the final Parquet files were NOT updated. Dashboards will show yesterday's data. |
| 46 | +
|
| 47 | + **Next Steps for On-Call:** |
| 48 | +
|
| 49 | + 1. Check job logs: Did it run out of memory (OOM)? |
| 50 | + 2. Check runtime artifact logs: Was there any captured error logs? |
| 51 | + 4. Fix the underlying issue and manually execute the pipeline job. |
| 52 | + EOT |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +resource "google_monitoring_alert_policy" "extractor_failure" { |
| 57 | + |
| 58 | + display_name = "Drive Extractor Failure Alert" |
| 59 | + combiner = "OR" |
| 60 | + severity = "CRITICAL" |
| 61 | + |
| 62 | + notification_channels = [for channel in google_monitoring_notification_channel.email : channel.name] |
| 63 | + |
| 64 | + conditions { |
| 65 | + display_name = "extractor_crashed" |
| 66 | + |
| 67 | + condition_matched_log { |
| 68 | + filter = <<-EOT |
| 69 | + resource.type="cloud_run_job" |
| 70 | + resource.labels.job_name="drive-extractor-${var.environment}" |
| 71 | + severity="ERROR" |
| 72 | + EOT |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + alert_strategy { |
| 77 | + auto_close = "21600s" |
| 78 | + notification_prompts = ["OPENED"] |
| 79 | + |
| 80 | + notification_rate_limit { |
| 81 | + period = "1800s" |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + documentation { |
| 86 | + mime_type = "text/markdown" |
| 87 | + content = <<-EOT |
| 88 | + ## ALERT: Drive Extractor Job Crashed! |
| 89 | +
|
| 90 | + **What Happened:** The `drive-extractor-${var.environment}` Cloud Run Job threw a fatal error. The pipeline is halted. |
| 91 | +
|
| 92 | + **Impact:** |
| 93 | + - Raw CSVs were not successfully pulled from Drive. |
| 94 | + - The `metadata.json` was not written. |
| 95 | + - Or the `.success` flag was not planted. |
| 96 | +
|
| 97 | + **Next Steps for On-Call Responder:** |
| 98 | + 1. Check Cloud Run Job logs for Python tracebacks. |
| 99 | + 2. Verify that the Google Drive folder is shared with the Drive Extractor SA email. |
| 100 | + 3. Once fixed, manually execute the job. |
| 101 | + EOT |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | + |
| 106 | +resource "google_monitoring_alert_policy" "workflow_failure" { |
| 107 | + display_name = "Pipeline Dispatcher Failure Alert" |
| 108 | + combiner = "OR" |
| 109 | + severity = "CRITICAL" |
| 110 | + |
| 111 | + notification_channels = [for channel in google_monitoring_notification_channel.email : channel.name] |
| 112 | + |
| 113 | + conditions { |
| 114 | + display_name = "pipeline_dispatch_failed" |
| 115 | + |
| 116 | + condition_matched_log { |
| 117 | + filter = <<-EOT |
| 118 | + resource.type="workflows.googleapis.com/Workflow" |
| 119 | + resource.labels.workflow_id="pipeline-dispatcher-${var.environment}" |
| 120 | + severity>=ERROR |
| 121 | + EOT |
| 122 | + } |
| 123 | + } |
| 124 | + alert_strategy { |
| 125 | + auto_close = "21600s" |
| 126 | + notification_prompts = ["OPENED"] |
| 127 | + |
| 128 | + notification_rate_limit { |
| 129 | + period = "1800s" |
| 130 | + } |
| 131 | + } |
| 132 | + documentation { |
| 133 | + mime_type = "text/markdown" |
| 134 | + content = <<EOT |
| 135 | + ## ALERT: Running Operations Pipeline has failed! |
| 136 | +
|
| 137 | + **What Happened**: The Eventarc Workflow `pipeline-dispatcher-${var.environment}` encountered a fatal error. |
| 138 | +
|
| 139 | + **Impact**: Dashboard consumers will see stale data. |
| 140 | +
|
| 141 | + **Next Steps for On-Call Responder:** |
| 142 | +
|
| 143 | + 1. Click the "View Logs" button below to see the exact error. |
| 144 | + 2. Check if the `drive-extractor` successfully dropped the `.success` file. |
| 145 | + 3. Check if the `operations-pipeline` Cloud Run Job ran out of memory. |
| 146 | + EOT |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | + |
| 151 | +resource "google_monitoring_alert_policy" "scheduler_failure" { |
| 152 | + display_name = "Midnight Scheduler Failure Alert" |
| 153 | + combiner = "OR" |
| 154 | + severity = "CRITICAL" |
| 155 | + |
| 156 | + notification_channels = [for channel in google_monitoring_notification_channel.email : channel.name] |
| 157 | + |
| 158 | + conditions { |
| 159 | + display_name = "midnight_scheduler_failed" |
| 160 | + |
| 161 | + condition_matched_log { |
| 162 | + filter = <<EOT |
| 163 | + resource.type="cloud_scheduler_job" |
| 164 | + jsonPayload.debugInfo="URL_ERROR-ERROR_NOT_FOUND. Original HTTP response code number = 404" OR jsonPayload.debugInfo="URL_ERROR-ERROR_AUTHENTICATION. Original HTTP response code number = 401" |
| 165 | + resource.labels.job_id="midnight-trigger-${var.environment}" |
| 166 | + EOT |
| 167 | + } |
| 168 | + } |
| 169 | + alert_strategy { |
| 170 | + auto_close = "21600s" |
| 171 | + notification_prompts = ["OPENED"] |
| 172 | + |
| 173 | + notification_rate_limit { |
| 174 | + period = "1800s" |
| 175 | + } |
| 176 | + } |
| 177 | + documentation { |
| 178 | + mime_type = "text/markdown" |
| 179 | + content = <<EOT |
| 180 | + ## ALERT: Cloud Scheduler Failed to Run! |
| 181 | + |
| 182 | + **What Happened:** The `midnight-trigger-${var.environment}` job failed to execute. |
| 183 | + |
| 184 | + **Impact:** The entire data pipeline has not started today. |
| 185 | +
|
| 186 | + **Next Steps for On-Call Responder:** |
| 187 | +
|
| 188 | + 1. Check the Cloud Scheduler logs. Look for a 401 (Auth token expired) or 403 (IAM permission revoked). |
| 189 | + 2. Manually click "Force Run" in the Cloud Scheduler console to start today's extraction. |
| 190 | + EOT |
| 191 | + } |
| 192 | +} |
0 commit comments