-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(monitoring): add terraform to generate k8s CronJob monitoring
This commit adds a new Terraform module definition and instance to generate a resource for every k8s CronJob definition, using the cronLastSuccessfulTimeMins label defined for the CronJob
- Loading branch information
1 parent
d6a9b4b
commit ff49e28
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
deployment/terraform/modules/k8s_cron_alert/k8s_cron_alert.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
variable "project_id" { | ||
type = string | ||
description = "The project to create the alert policy in." | ||
} | ||
|
||
variable "cronjob_name" { | ||
type = string | ||
description = "Name of the kubernetes cronjob to monitor." | ||
} | ||
|
||
variable "cronjob_expected_latency_minutes" { | ||
type = number | ||
description = "Expected amount of time since last successful run of the job expressed in minutes." | ||
} | ||
|
||
resource "google_monitoring_alert_policy" "cron_alert_policy" { | ||
project = var.project_id | ||
display_name = "Cronjob: ${var.cronjob_name} has not run recently." | ||
combiner = "OR" | ||
conditions { | ||
display_name = "Cronjob: ${var.cronjob_name} has not run recently." | ||
condition_prometheus_query_language { | ||
query = "((time() - kube_cronjob_status_last_successful_time{cronjob=\"${var.cronjob_name}\"})/60) > ${var.cronjob_expected_latency_minutes}" | ||
duration = "60s" | ||
evaluation_interval = "60s" | ||
alert_rule = "AlwaysOn" | ||
rule_group = "cronjob ${var.cronjob_name}" | ||
} | ||
} | ||
} |