0

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. enter image description here

And the successfull execution:

enter image description here

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • did you set up the alert via azure monitor? and if you configure the alert via UI, can you please share us some screenshots? – Ivan Glasenberg Jul 22 '20 at 07:34
  • i set it up via azure resource manager, – Szilágyi István Jul 22 '20 at 07:44
  • oh, I'm not familiar with resource manager. But if you can use azure monitor via UI to setup it, I can provide some ideas. – Ivan Glasenberg Jul 22 '20 at 07:45
  • i added the picture – Szilágyi István Jul 22 '20 at 07:47
  • from the screenshot, I can see it always has an error. Did you link your azure function to application insights? – Ivan Glasenberg Jul 22 '20 at 07:50
  • yes i did, my other function works fine, and alert on it also works fine, both of them have very similar alert definition, just the name is different basically, and the trigger type – Szilágyi István Jul 22 '20 at 07:52
  • I suggest you can check if there're any errors about this function in application insights. – Ivan Glasenberg Jul 22 '20 at 07:54
  • no errors in application insight – Szilágyi István Jul 22 '20 at 07:56
  • If that's the case, could you please setup a `custom search log` signal for this alert? By using this kind of alert, you can write query for errors in application insights. If error logs in application insights, the alert will be triggered. – Ivan Glasenberg Jul 22 '20 at 07:58
  • I did a query for logs just to double check the interfaces, and they seem to be correct. So if i dont find error in querry for the logs there is no point to set up custom search log i think, i tried with this: requests | project timestamp, id, operation_Name, success, resultCode, duration, operation_Id, cloud_RoleName, invocationId=customDimensions['InvocationId'] | where timestamp > ago(30d) | where cloud_RoleName =~ 'insert info here' and operation_Name =~ 'insert info here' | where success = false | order by timestamp desc | take 20 – Szilágyi István Jul 22 '20 at 08:58
  • what do you mean of "there is no point to set up custom search log"? – Ivan Glasenberg Jul 22 '20 at 09:09
  • if its returning the same result? – Szilágyi István Jul 22 '20 at 09:18
  • if it's returning the same result, yes, then you don't need to consider using custom search log. – Ivan Glasenberg Jul 22 '20 at 09:20
  • Yes it returns that everything is ok... no errors/ fail executions... weird – Szilágyi István Jul 22 '20 at 09:25
  • I'm always using this kind of alert, because I know the application insights will records errors and will give me the exact result. But for other pre-defined signals, I really don't know the logic behind it. So I recommend that you can use it:) – Ivan Glasenberg Jul 22 '20 at 09:28
  • 1
    yeah probably it will be a better idea to switch to it. First i will finish up a few modifications which i still need on my function app, then will check the custom search log and how the alerts work with it. Thank you for your input :) – Szilágyi István Jul 22 '20 at 09:33
  • Hello, I just posted an answer for this issue. If it's helpful, could you please accept it as answer? Thanks:). – Ivan Glasenberg Jul 28 '20 at 06:04

1 Answers1

1

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.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60