Skip to content

Commit

Permalink
EES-5687 - removed base alert templates for CPU, memory and response …
Browse files Browse the repository at this point in the history
…times in favour of reusable configuration and direct calls to rejigged dynamicMetricAlert.bicep template which reduces boilerplate from callsites.
  • Loading branch information
duncan-at-hiveit committed Dec 31, 2024
1 parent c3cf4b1 commit 7901822
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module postgreSqlServerModule '../../components/postgresqlDatabase.bicep' = {
diskBandwidth: true
diskIops: true
memoryPercentage: true
alertGroupName: resourceNames.existingResources.alertsGroup
alertsGroupName: resourceNames.existingResources.alertsGroup
} : null
tagValues: tagValues
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions infrastructure/templates/public-api/components/alerts/config.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var defaultDynamicAlertConfig = {
aggregation: 'Average'
operator: 'GreaterThan'
evaluationFrequency: 'PT5M'
windowSize: 'PT15M'
numberOfEvaluationPeriods: 5
minFailingPeriodsToAlert: 5
sensitivity: 'Low'
severity: 'Warning'
}

@export()
var cpuPercentageConfig = union(defaultDynamicAlertConfig, {
nameSuffix: 'cpu-percentage'
})

@export()
var memoryPercentageConfig = union(defaultDynamicAlertConfig, {
nameSuffix: 'memory-percentage'
})

@export()
var responseTimeConfig = union(defaultDynamicAlertConfig, {
nameSuffix: 'response-time'
})

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
EvaluationFrequency
MetricName
DynamicMetricOperator
DynamicAlertConfig
ResourceType
TimeAggregation
WindowSize
Severity
Sensitivity
severityMapping
} from 'types.bicep'

import { ResourceMetric } from 'resourceMetrics.bicep'

@description('Name of the resource that this alert is being applied to.')
param resourceName string

@description('''
Optional id of the resource that this alert is being applied to,
if it cannot be looked up by the combination of resourceName and resourceType.
''')
param id string?

@description('Resource type and metric name combination.')
param resourceMetric ResourceMetric

@description('Configuration for this dynamic alert.')
param config DynamicAlertConfig

@description('''
An optional date that prevents machine learning algorithms from using metric data prior to this date in order to
calculate its dynamic threshold.
''')
param ignoreDataBefore string?

@description('Name of the Alerts Group used to send alert messages.')
param alertsGroupName string

@description('Tags with which to tag the resource in Azure.')
param tagValues object

var severityLevel = severityMapping[config.severity]

var resourceIds = [id != null ? id! : resourceId(resourceMetric.resourceType, resourceName)]

resource alertsActionGroup 'Microsoft.Insights/actionGroups@2023-01-01' existing = {
name: alertsGroupName
}

resource metricAlertRule 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: '${resourceName}-${config.nameSuffix}'
location: 'Global'
properties: {
enabled: true
scopes: resourceIds
severity: severityLevel
evaluationFrequency: config.evaluationFrequency
windowSize: config.windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
criterionType: 'DynamicThresholdCriterion'
name: 'Metric1'
metricName: resourceMetric.metric
metricNamespace: resourceMetric.resourceType
timeAggregation: config.aggregation
operator: config.operator
alertSensitivity: config.sensitivity
skipMetricValidation: false
failingPeriods: {
minFailingPeriodsToAlert: config.minFailingPeriodsToAlert
numberOfEvaluationPeriods: config.numberOfEvaluationPeriods
}
ignoreDataBefore: ignoreDataBefore
}
]
}
actions: [
{
actionGroupId: alertsActionGroup.id
}
]
}
tags: tagValues
}

This file was deleted.

Loading

0 comments on commit 7901822

Please sign in to comment.