成功时会触发 azure 函数失败警报
azure function failure alert gets triggered when success
我遇到一个问题,当执行 azure 函数时会触发 azure 警报。我查看了不同的文档,查看了警报规则,查看了代码,但似乎无法指出问题所在。你们可以检查一下我错过了什么吗?
警报条件如下:
"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,
代码相关部分:
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)
}
}
}
编辑
,正如评论中所要求的那样,这里有一张图片。
并成功执行:
如果你的azure函数是和Application Insights关联的,那我建议你可以使用Custom log search
(你可以参考this article)。
这种信号的好处是,Application insights query 会准确显示我们需要的结果,而且我们清楚其中的逻辑。但是对于预定义信号,我们不清楚它在beckend中的逻辑。
请试一试,如果有任何问题,请告诉我。
我遇到一个问题,当执行 azure 函数时会触发 azure 警报。我查看了不同的文档,查看了警报规则,查看了代码,但似乎无法指出问题所在。你们可以检查一下我错过了什么吗?
警报条件如下:
"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,
代码相关部分:
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)
}
}
}
编辑
,正如评论中所要求的那样,这里有一张图片。
并成功执行:
如果你的azure函数是和Application Insights关联的,那我建议你可以使用Custom log search
(你可以参考this article)。
这种信号的好处是,Application insights query 会准确显示我们需要的结果,而且我们清楚其中的逻辑。但是对于预定义信号,我们不清楚它在beckend中的逻辑。
请试一试,如果有任何问题,请告诉我。