Commit 2bca1027 authored by Kishore Battula's avatar Kishore Battula
Browse files

Merge branch 'users/Vibhuti/addingMetricAlerts' into 'master'

Adding metric type Alerts in Terraform

See merge request osdu/platform/deployment-and-operations/infra-azure-provisioning!306
parents b6a8f225 8157b0db
......@@ -226,4 +226,37 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "alerts" {
}
}
}
}
\ No newline at end of file
}
#-------------------------------
# Metric Type Alerts
#-------------------------------
resource "azurerm_monitor_metric_alert" "example" {
for_each = var.metric-alerts
name = "${each.value.name}-${local.base_name}"
resource_group_name = azurerm_resource_group.main.name
# A set of strings of resource IDs at which the metric criteria should be applied
scopes = ["/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${local.central_group_prefix}-rg/providers/Microsoft.Insights/components/${local.central_group_prefix}-ai"]
description = each.value.description
enabled = each.value.enabled
severity = each.value.severity
frequency = each.value.frequency
window_size = each.value.window-size
auto_mitigate = each.value.auto-mitigate
criteria {
metric_namespace = each.value.criteria-metric-namespace
metric_name = each.value.criteria-metric-name
aggregation = each.value.criteria-aggregation
operator = each.value.criteria-operator
threshold = each.value.criteria-threshold
}
# Add multiple action blocks if multiple action groups are to be associated
dynamic "action" {
for_each = each.value.action-groups
content {
action_group_id = format("%s${local.base_name}-%s", local.action-group-id-prefix, action.value)
}
}
}
......@@ -100,3 +100,25 @@ log-alerts = {
metric-trigger-column = null
}
}
# Sample Metric Type Alert data
metric-alerts = {
osdu-airflow-collect-dags = {
name = "OSDU_AirflowCollectDags",
description = "Airflow Alert for average time taken to collect dags",
enabled = "true",
severity = 3,
frequency = "PT15M",
window-size = "PT15M",
action-groups = {
1 = "DevActionGroup",
2 = "ProdActionGroup"
},
auto-mitigate = true,
criteria-metric-namespace = "azure.applicationinsights",
criteria-metric-name = "osdu_airflow.collect_dags",
criteria-aggregation = "Average",
criteria-operator = "GreaterThan",
criteria-threshold = 50
}
}
\ No newline at end of file
......@@ -128,4 +128,32 @@ variable "log-alerts" {
# Metric trigger column: column name on which aggregation is done
metric-trigger-column = any
}))
}
variable "metric-alerts" {
type = map(object({
name = string,
description = string,
enabled = string,
# Severity: 0 - critical, 1 - Error, 2 - Warning, 3 - Informational, 4 - Verbose
severity = number,
# Frequency: The evaluation frequency of this Metric Alert, represented in ISO 8601 duration format
frequency = string,
# The period of time that is used to monitor alert activity, represented in ISO 8601 duration format
window-size = string,
# Action group names in the form of a map
action-groups = map(string),
# Resolve the alert when the condition is not met anymore. Defaults to true.
auto-mitigate = bool,
# One of the metric namespaces to be monitored
criteria-metric-namespace = string,
# One of the metric names to be monitored
criteria-metric-name = string,
# The statistic that runs over the metric values. Possible values are Average, Count, Minimum, Maximum and Total
criteria-aggregation = string,
# The criteria operator. Possible values are Equals, NotEquals, GreaterThan, GreaterThanOrEqual, LessThan and LessThanOrEqual
criteria-operator = string,
# The criteria threshold value that activates the alert
criteria-threshold = number
}))
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment