python - Azure 功能运行状况检查失败

标签 python azure azure-functions azure-application-insights

我正在尝试配置 Azure 函数应用运行状况检查,以检查函数应用的可用性。

所以,我为它创建了一个单独的端点。正如下面的指标图表所示,它似乎正在工作。 但健康检查状态停留在Health Check:0.00% (Healthy 0/Degraded 1)

您知道如何进行健康检查吗?

我的代码:

import base64
import json
import logging
import os
import azure.functions as func
import requests

def main(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("", status_code=200)

指标图: enter image description here

最佳答案

我认为唯一的问题是auth_level。默认值为function,这意味着需要特定于函数的 API key 。健康检查请求不会插入任何 key ,因此对端点的请求将返回 401(未经授权)。

根据您使用的版本,解决方案是相同的,但应用于不同的点:

V1

authLevel 设置为 anonymous,如下例所示:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "health",
      "type": "httpTrigger",
      "authLevel": "anonymous",
      "direction": "in"
    }
  ]
}

V2

对于使用最新版本的用户,请尝试将 auth_level 设置为 ANONYMOUS,如下例所示:

@app.function_name(name="HealthCheck")
@app.route(route="health", auth_level=func.AuthLevel.ANONYMOUS)
def health(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("", status_code=200)

关于python - Azure 功能运行状况检查失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74852734/

相关文章:

python - 使用按日期分组将字典列表转换为字典列表

python - 如何在 Python/Django 中获取图片标题

azure 逻辑应用程序: waiting for an ACI container to terminate to get its logs

Azure逻辑应用程序: how to make a x-www-form-encoded?

c# - 异步编程和 Azure 函数

python - KivyMD:工具栏在 Android 上不起作用。应用程序崩溃

Azure 备份与快照

Azure Function 在 VSTS 构建期间进行转换

azure - 无法导出我的模型以在 Azure Custom Vision 上进行部署

python - 使用 Python 从单尾分布生成范围内的随机数