Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dynamic alerts #101

Merged
merged 17 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions ingredient/ingredient-metric-alert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,19 @@ The Metric Alert ingredient is a plugin for Bake. When included in a recipe, th

### Recipe
```yaml
#Provide name
name: Event Hub Namespace for diagnostics with a custom metric alert
shortName: diagnostics
version: 0.0.1
#Specify the names of the ingredients to use in the recipe. This is the name of the ingredient in package.json.
#Specify the local path to the module during development.
ingredients:
- "@azbake/ingredient-metric-alert@~0"
- "@azbake/ingredient-arm@~0"
- "@azbake/ingredient-event-hub-namespace@~0"
#Deploys to regions in parallel. Typically true unless the sequence of deploying to regions is important.
parallelRegions: true
#
#rgOverride:
#rgOverride:
resourceGroup: true
variables:
recipe:
ehndiag-deploy:
properties:
#Specify the Bake ingredient above
type: "@azbake/ingredient-event-hub-namespace"
source: ""
parameters:
Expand All @@ -37,10 +30,8 @@ recipe:
skuCapacity: "1"
isAutoInflateEnabled: "true"
maximumThroughputUnits: "10"
#Name the deployment. This shows up in the log window and is the name of the deployment within Azure.
alert-deploy:
properties:
#Specify the Bake ingredient above
type: "@azbake/ingredient-metric-alert"
source: "[eventhubnamespace.get_resource_profile()]"
parameters:
Expand All @@ -54,33 +45,60 @@ recipe:
threshold: "0"
timeAggregation: "Maximum"
windowSize: "PT5M"
evaluationFrequency: "PT1M"
evaluationFrequency: "PT5M"
actionGroupName: "[coreutils.create_resource_name('act','emailops', false)]"
actionGroupResourceGroup: "[coreutils.create_resource_name('','actiongroups', false)]"
actionGroupResourceGroup: "[coreutils.create_resource_name('','actiongroups', true)]"
#Uncomment below and comment above if using rgOverride
#actionGroupResourceGroup: "[coreutils.resource_group()]"
#alertType: "Static"
alertType: "Dynamic"
#Dynamic alert params have defaults. Uncomment and specify below to override defaults.
# dynamicAlertParameters:
# alertSensitivity: "Low"
# failingPeriods:
# numberOfEvaluationPeriods: "4"
# minFailingPeriodsToAlert: "3"
dependsOn:
- ehndiag-deploy
```

| property|required|description|
|---------|--------|-----------|
| source | yes | Name of the target resource for the metric that the alert is monitoring |
| alertName | yes | Name of the Alert resource |
| alertSeverity | no | The severity level of the alert. Defaults to 3. |
| isEnabled | no | Specifies whether the alert is enabled. Defaults to true. |
| source | yes | Name of the target resource for the metric that the alert is monitoring. |
| alertName | yes | Name of the Alert resource. |
| alertSeverity | no (default `3`) | The severity level of the alert. |
| isEnabled | no (default `true`) | Specifies whether the alert is enabled.|
| source-type | yes | The [metric namespace](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported) of the alert. An example is Microsoft.KeyVault/vaults. |
| metricName | yes | The name of the metric that the alert is monitoring |
| operator | no | The comparison operator for the alert. Defaults to "GreaterThan". |
| metricName | yes | The name of the metric that the alert is monitoring. |
| operator | yes | The comparison operator for the alert. |
| threshold | yes | The threshold value to trigger the alert. |
| timeAggregation | yes | The aggregation function used for comparing against the threshold. Defaults to "Average".|
| windowSize | no | Period of time used to monitor alert activity based on the threshold. Defaults to PT5M. Must be between five minutes and one day. ISO 8601 duration format. |
| evaluationFrequency| no | How often the metric alert is evaluated represented in ISO 8601 duration format. Defaults to PT1M. |
| timeAggregation | no (default `Average`) | The aggregation function used for comparing against the threshold.
| windowSize | no (default `PT5M`) | Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one day. ISO 8601 duration format. |
| evaluationFrequency| no (default `PT5M`) | How often the metric alert is evaluated represented in ISO 8601 duration format.|
| actionGroupName | yes | The name of the action group to trigger when the alert is fired.|
| actionGroupResourceGroup | yes | The action group's resource group.|
| alertType | yes | Static or Dynamic (AIOps) |
| dynamicAlertProperties | no (default below) | Object for specifying dynamic alert properties. |

**dynamicAlertProperties object**
| property|required|description|
|---------|--------|-----------|
| alertSensitivity | no (default `Low`) | Low, Medium, and High sensitivities (in order of least to most noisy alerts.)
| failingPeriods | no (default below) | Object for specifying dynamic alert failing periods properties. |

**failingPeriods object** - this advanced criteria defaults to fire the alert if 3 of of the last 4 evaluation periods failed
| property|required|description|
|---------|--------|-----------|
| numberOfEvaluationPeriods | no (default `4`) | The total number of periods for evaluating against the failing periods. |
| minFailingPeriodsToAlert | no (default `3`)| The minimum number of failing periods to fire the alert. |


**See Azure Monitor documentation for additional details**

[Platform metric alert rules - Using Resource Manager template](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-create-templates)

[Azure Monitor REST API - Metric Alerts - Create or Update](https://docs.microsoft.com/en-us/rest/api/monitor/metricalerts/createorupdate)

See [Event Hub SDK documentation for additional details](https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.eventhub.models.eventhub?view=azure-dotnet#properties)

## Utilities
Utility classes can be used inside of the bake.yaml file for parameter and source values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@
},
"operator": {
"type": "string",
"defaultValue": "GreaterThan",
"allowedValues": [
"Equals",
"NotEquals",
"GreaterThan",
"GreaterThanOrEqual",
"LessThan",
"LessThanOrEqual"
"LessThanOrEqual",
"GreaterOrLessThan"
],
"metadata": {
"description": "Operator comparing the current value with the threshold value."
"description": "Operator comparing the current value with the threshold. GreaterOrLessThan, GreaterThan, and LessThan are applicable to dynamic. All applicable to static except GreaterOrLessThan."
}
},
"threshold": {
"type": "string",
"defaultValue": "0",
"defaultValue": "",
"metadata": {
"description": "The threshold value at which the alert is activated."
}
Expand All @@ -97,7 +97,7 @@
},
"evaluationFrequency": {
"type": "string",
"defaultValue": "PT1M",
"defaultValue": "PT5M",
"metadata": {
"description": "How often the metric alert is evaluated represented in ISO 8601 duration format"
}
Expand All @@ -107,6 +107,20 @@
},
"actionGroupResourceGroup": {
"type": "string"
},
"alertType": {
"type": "string",
"allowedValues": ["Static","Dynamic"]
},
"dynamicAlertProperties": {
"type": "object",
"defaultValue": {
"alertSensitivity": "Low",
"failingPeriods": {
"numberOfEvaluationPeriods": "4",
"minFailingPeriodsToAlert": "3"
}
}
}
},
"variables": {},
Expand All @@ -125,14 +139,17 @@
"evaluationFrequency": "[parameters('evaluationFrequency')]",
"windowSize": "[parameters('windowSize')]",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"odata.type": "[concat('Microsoft.Azure.Monitor.', if(equals(parameters('alertType'),'Static'),'SingleResourceMultipleMetricCriteria','MultipleResourceMultipleMetricCriteria'))]",
"allOf": [
{
"criterionType": "[if(equals(parameters('alertType'),'Static'),'StaticThresholdCriterion','DynamicThresholdCriterion')]",
"name": "1st criterion",
"metricName": "[parameters('metricName')]",
"dimensions": [],
"operator": "[parameters('operator')]",
"threshold": "[parameters('threshold')]",
"threshold": "[if(equals(parameters('alertType'),'Static'),parameters('threshold'),'')]",
"alertSensitivity": "[if(equals(parameters('alertType'),'Dynamic'),parameters('dynamicAlertProperties').alertSensitivity,'')]",
"failingPeriods": "[if(equals(parameters('alertType'),'Dynamic'),parameters('dynamicAlertProperties').failingPeriods,json('null'))]",
"timeAggregation": "[parameters('timeAggregation')]"
}
]
Expand Down
168 changes: 0 additions & 168 deletions ingredient/ingredient-metric-alert/src/dynamicAlert.json

This file was deleted.

14 changes: 7 additions & 7 deletions ingredient/ingredient-metric-alert/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BaseIngredient, IngredientManager } from "@azbake/core"
import { ARMHelper } from "@azbake/arm-helper"
import staticAlertARMTemplate from "./staticAlert.json"
import dynamicAlertARMTemplate from "./dynamicAlert.json"
import alertARMTemplate from "./alert.json"

export class MetricAlertPlugin extends BaseIngredient {

Expand All @@ -24,18 +23,19 @@ export class MetricAlertPlugin extends BaseIngredient {
params["source-rg"] = { "value": resource.resourceGroup };
params["source-name"] = { "value": resource.resource };

//Generate alertName param as env + region + "alert" + source resource + time aggregation (max, min, etc.) + metric name.
//Generate alertName param as env + region + "alert" + source resource + time aggregation (max, min, etc.) + metric name + alert type (static, dynamic).
//Alert names can be up to 128 characaters long in Azure.
//Ex) deveusalert-sbwounds-maximum-throttledrequests
//Ex) deveusalert-sbwounds-maximum-throttledrequests-dynamic
const timeAggregation = params["timeAggregation"].value;
const metricName = params["metricName"].value;
const sourceName = resource.resource;
const tempName = '-' + sourceName + '-' + timeAggregation + '-' + metricName;
const alertName = util.create_resource_name("alert", tempName, true);
const alertType = params["alertType"].value;
const tempName = '-' + sourceName + '-' + timeAggregation + '-' + metricName + '-' + alertType;
const alertName = util.create_resource_name("alert", tempName, true);
this._logger.log(alertName);
params["alertName"] = { "value": alertName };

await helper.DeployTemplate(this._name, staticAlertARMTemplate, params, await util.resource_group())
await helper.DeployTemplate(this._name, alertARMTemplate, params, await util.resource_group())

} catch (error) {
this._logger.error('deployment failed: ' + error)
Expand Down
Loading