2
votes

I'm using ARM templates to deploy resources in Azure but I'd like to deploy alerts at the same time. This case is about an Azure Function.

I first created the Http5xx alert in the portal and then used the Azure Resource Manager to lookup the template to be used:

    {
  "type": "Microsoft.Insights/alertRules",
  "name": "Http Server Error",
  "apiVersion": "2014-04-01",
  "location": "[resourceGroup().Location]",
  "tags": {
    "[concat('hidden-link:', resourceId('Microsoft.Web/sites', parameters('functionName')))]": "Resource"
  },
  "scale": null,
  "properties": {
    "name": "Http Server Error",
    "description": "Raise alert when the function returns HTTP 5xx error",
    "isEnabled": true,
    "condition": {
      "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
      "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
      "dataSource": {
        "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
        "resourceUri": "[resourceId('Microsoft.Web/sites', parameters('functionName'))]",
        "resourceLocation": null,
        "metricNamespace": null,
        "metricName": "Http5xx",
        "legacyResourceId": null
      },
      "operator": "GreaterThan",
      "threshold": 1,
      "windowSize": "PT5M",
      "timeAggregation": "Total"
    },
    "actions": [
      {
        "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleWebhookAction, Microsoft.WindowsAzure.Management.Mon.Client",
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleWebhookAction",
        "serviceUri": "https://some-awesome-webhook",
        "properties": {
          "$type": "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary`1[[System.String, mscorlib]], Microsoft.WindowsAzure.Management.Common.Storage"
        }
      }
    ]
  }
}

In the middle you can see the 'metricName' with value 'Http5xx'. Now when I run this as part of my ARM template, it fails with this message:

{
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'.",
    "details": [
      {
        "code": "DeploymentFailed",
        "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.",
        "details": [
          {
            "code": "BadRequest",
            "message": "{\r\n  \"code\": \"UnsupportedMetric\",\r\n  \"message\": \"The metric with namespace '' and name 'Http5xx' is not supported for this resource id '/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx/resourceGroups/my-awesome-rg/providers/Microsoft.Web/sites/my-awesome-function'.\"\r\n}"
          }
        ]
      }
    ]
  }
}

It basically says my Http5xx is not supported for Functions, but in this documentation it states this metric is supported: https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics

Anyone an idea what I'm doing wrong?

1
Update: the exact same definition works fine on an Azure App Service (Microsoft.Web/sites) where the 'kind' field is not set. So there must be a difference between the ARM template handling for web and function (where 'kind' field is set to 'functionapp') .Jean-Paul Smit
According to Jeff Hollan of the Azure Functions team this currently is not supported. This is also indicated by the fact that it currently is not possible to create an alert for Functions in using the portal. This is assumed to be fixed soon. Posted as comment because Stackoverflow banned my account due to numerous low quality answers, while I haven't answered any questions before. #FailJean-Paul Smit

1 Answers

1
votes

You api versión is horribly outdated. use something newer. the page suggests this versión: 2017-05-01-preview api-versión

Official api versions for this type: 2016-03-01, 2015-04-01, 2014-04-01