如何解决Flaky Azure功能应用程序行为问题?

时间:2017-09-04 13:17:27

标签: azure f# azure-functions

我正在尝试Azure功能应用。

在开放天气地图教程中示例后面的第一个示例,在我使用log.WriteLine()之后停止了工作,这正确地引发了编译错误。我更改为log.Info()并且一直抱怨TraceWriter不包含WriteLine的定义。

经过漫长的故障排除会话后,我创建了一个新功能,复制了破碎的所有内容,并立即运行。

像以前一样创建了一个新函数,并开始对Run()方法进行更改,并运行此函数会产生:

  

“您要查找的资源已被删除,名称已有   已经改变,或暂时无法使用。“

请注意,函数URL基于Azure在创建函数时生成的默认密钥:https://. azurewebsites.net/api/WeatherWhereYouAre?code = my1really2RAndom3defauLT4Key5from6Azure ==

创建了另一个函数,没有更改默认的“Hello Azure”示例,它产生500错误:

  

“执行函数时出现异常:Functions.HttpTriggerCSharp2 - >   发生了一个或多个错误。 - >异常绑定参数'req' - >   输入字符串的格式不正确。“

这是project.json文件的内容:

{
    "frameworks": {
        "net46": {
            "dependencies": {
                "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.16.0",
                "Microsoft.Azure.KeyVault": "2.3.2",
                "Microsoft.AspNet.WebApi.Client": "5.2.3"
            }
        }
    }
}

和run.csx:

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    name = name ?? data?.name;

    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}

修改

Completely inconsistent behaviour 在上图中,请注意这是httpTriggerFSharp1,但异常是HttpTriggerCSharp2(这是唯一有效的!)

有没有办法可以对这些问题进行适当的排查?

1 个答案:

答案 0 :(得分:1)

对于C#的默认HttpTrigger模板,您可以按如下方式调用它:

Get https://brucefunapp.azurewebsites.net/api/HttpTriggerCSharp3?name=bruce&code=ItDhLMxwDYmTvMTYzVbbALtL5GEcmaL5DlzSaD4FRIuFdh17ZkY71g==

Or

Post https://brucefunapp.azurewebsites.net/api/HttpTriggerCSharp3?code=ItDhLMxwDYmTvMTYzVbbALtL5GEcmaL5DlzSaD4FRIuFdh17ZkY71g==
Content-type: application/json
{"name": "bruce"}

有关Azure Functions C#脚本的更多详细信息,请参阅here

  

有没有办法可以对这些问题进行适当的排查?

根据我的理解,您可以利用Precompiled functions并使用Visual Studio 2017 Tools for Azure Functions创建,本地调试和发布到Azure。