【问题标题】:How to get the details of an error message in an Azure Data Factory pipeline如何在 Azure 数据工厂管道中获取错误消息的详细信息
【发布时间】:2021-10-20 12:42:46
【问题描述】:

我在 Azure 数据工厂中的管道的最后一步执行另一个管道,其中包含一个 Notebook 步骤。作为我要求的一部分,我需要在此步骤失败时捕获错误消息的详细信息(将其存储在数据库中)。

但是,最后一步的输出不提供此信息,仅提供指向另一信息的链接。我的挑战是我无法修改“内部”管道来获取该数据(我们对错误的 URL 感兴趣),我需要从我创建的那个中做所有事情。

不幸的是,我无法找到任何可能的解决方案或文档来尝试解决此问题。如果您能给我任何建议,我将不胜感激。

【问题讨论】:

    标签: azure-pipelines azure-data-factory error-messaging


    【解决方案1】:

    任何活动都将以如下格式存储输出。

    @activity('*activityName*').output.*subfield1*.*subfield2*
    

    要在活动失败的情况下访问输出,您可以选择 Add activity on failure stream 并使用 设置变量。

    但是,在这种情况下,由于正在执行另一个管道,其返回到父管道(ExecutePipeline 活动)的输出只是子 PipelineNamePipelineRunId

    所以让我们利用这个 PipelineRunId。让我们使用 WebActivity 调用 REST API Activity Runs - Query By Pipeline Run

    POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}/queryActivityruns?api-version=2018-06-01
    

    1. 从 ExecutePipeline 活动输出中获取 PipelineRunId 并设置为变量。

    错误输出: @activity('Execute Pipeline').output.pipelineRunId

    2.使用这个run id来动态形成url

    网址:https://management.azure.com/subscriptions/b83c1ed3-xxxx-xxxx-xxxx-2b83a074c23f/resourceGroups/myrg/providers/Microsoft.DataFactory/factories/ktestadf/pipelineruns/@{variables('pipelineRunId')}/queryActivityruns?api-version=2018-06-01

    3. 现在准备调用 REST API。使用已经准备好的url。设置方法 POST、header 和 body。

    请求正文是查询管道运行的时间范围。我们将在动态进行此调用之前和之后设置一个 1 小时的窗口。

    方法: POST

    标题: 内容类型:application/json

    正文: {"lastUpdatedAfter":getPastTime(1, 'Hour'),"lastUpdatedBefore":getFutureTime(1, 'Hour')}

    身份验证:如果使用 MSI 集资源:https://management.azure.com/

    4. 最后将该错误消息存储在另一个 Array 变量中,您可以从中解析数组并根据需要存储到 SQL sink。

    这是它的内容。

    {
        "name": "ErrorMsg",
        "value": [
            {
                "activityRunEnd": "2021-10-14T07:43:20.1291832Z",
                "activityName": "Notebook",
                "activityRunStart": "2021-10-14T07:43:18.3867797Z",
                "activityType": "DatabricksNotebook",
                "durationInMs": 1742,
                "retryAttempt": null,
                "error": {
                    "errorCode": "2011",
                    "message": "Caller was not found on any access policy in this key vault, secretName: databricksclientsecret, secretVersion: , vaultBaseUrl: https://ktestkeyvaults.vault.azure.net/. The error message is: The user, group or application 'name=Microsoft.DataFactory/factories;appid=3ecdccaf-xxxx-xxxx-8818-4f30b45856eb;oid=7ee614a9-xxxx-xxxx-a7cd-fbad1afc715b;iss=https://sts.windows.net/72f988bf-xxxx-41af-91ab-2d7cd011db47/' does not have secrets get permission on key vault 'ktestkeyvaultss;location=eastus'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287.",
                    "failureType": "UserError",
                    "target": "Notebook",
                    "details": []
                },
                "activityRunId": "6c9519e1-b646-4d5b-a974-29bef371d7e5",
                "iterationHash": "",
                "input": {
                    "notebookPath": "https://adb-7020907718042127.7.azuredatabricks.net/?o=7020907718041127#notebook/171399934287251/command/171399934287255"
                },
                "linkedServiceName": "",
                "output": {
                    "effectiveIntegrationRuntime": "DefaultIntegrationRuntime (Central US)",
                    "executionDuration": 0,
                    "durationInQueue": {
                        "integrationRuntimeQueue": 1
                    },
                    "billingReference": {
                        "activityType": "ExternalActivity",
                        "billableDuration": [
                            {
                                "meterType": "AzureIR",
                                "duration": 0.016666666666666666,
                                "unit": "Hours"
                            }
                        ]
                    }
                },
                "userProperties": {},
                "pipelineName": "error2",
                "pipelineRunId": "6a717388-516e-46d7-883c-fdcf2d517bd8",
                "status": "Failed",
                "recoveryStatus": "None",
                "integrationRuntimeNames": [
                    "defaultintegrationruntime"
                ],
                "executionDetails": {
                    "integrationRuntime": [
                        {
                            "name": "DefaultIntegrationRuntime",
                            "type": "Managed",
                            "location": "Central US"
                        }
                    ]
                },
                "id": "/SUBSCRIPTIONS/B83C2ED3-xxxx-xxxx-xxxx-2B80A074C23F/RESOURCEGROUPS/myrg/PROVIDERS/MICROSOFT.DATAFACTORY/FACTORIES/KTESTADF/pipelineruns/6a717388-516e-46d7-883c-fdcf2d517bd8/activityruns/6c9519e1-b646-4d5b-a974-29bef371d7e5"
            }
        ]
    }
    

    我有一条不同的错误消息,您会找到类似的所需 URL。

    【讨论】:

    • 嗨。非常感谢您的宝贵帮助。
    • 很高兴能为您提供帮助?
    【解决方案2】:

    尝试将您的代码包含在此处提到的 try-except 块中

    Exception Handling

    在 except 块中,您也可以使用返回错误消息

    dbutils.notebook.exit(errmsg)
    

    返回 ADF 并分配给变量,如

    @activity('Notebook1').output.runoutput
    

    您可以从变量中写入表/文件。

    Video

    【讨论】:

    • 嗨。惊人的解决方案。我不能触摸笔记本代码,但我肯定会通过你的视频提出它。
    • 感谢您的反馈
    猜你喜欢
    • 2021-03-19
    • 2020-03-13
    • 2021-09-09
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多