I have an issue where an azure alert gets triggered when an azure function gets executed. I looked into different documentations reviewed the alert rule, reviewed the code but it seems im not able to point out the issue. Can u guys please check and see what i missed?
The condition of the alert is the following:
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "1st criterion",
"metricName": "<functionName> Failures",
"metricNamespace": "Azure.ApplicationInsights",
"dimensions": [
],
"operator": "GreaterThan",
"threshold": "0",
"monitorTemplateType": "8",
"criterionType": "StaticThresholdCriterion",
"timeAggregation": "PT1M",
"skipMetricValidation": true
}
]
},
"autoMitigate": true,
Relevant part of the code:
module.exports = async function (context, req) {
try{
let res = await apicall();
response = {
status: 200, /* Defaults to 200 */
body: res
}
}catch(error){
response = {
status: 500, /* Defaults to 500 */
body: errorHandler(error)
};
errorObj = error
}finally{
if (response.status == 200) {
context.done(null, response)
} else {
context.done(errorObj, response)
}
}
}
Edit
, as requested in comment here is a picture of it.
And the successfull execution:
If you have your azure function linked with Application Insights, then I suggest you can use Custom log search
(You can refer to this article about it.).
The benefit of this kind of signal is that Application insights query will show the exact result which we need, and we know the logic clearly. But for the pre-defined signal, we are not clear it's logic in beckend.
Please give it a try, and let me know if there is any problem.