2

不确定我是否应该标记这个 google-cloud-logging 或 google-workflows,因为我不确定问题是否存在,所以我标记了两者。

我有一个通过BigQuery jobs.insert REST API执行 BigQuery 存储过程的 Google Cloud Workflow(下面提供了工作流定义) 。我想在 Google Cloud Console 中记录一条消息,提供该作业结果的 URL。

感谢在是否可以链接到 bigquery 控制台中的作业?我知道我可以构造一个带我到查询结果的 URL,它看起来像这样:

https://console.cloud.google.com/bigquery?project=<my-project>j=<bq:<location>:<job_id>>&page=queryresults

因此,我将一条消息从我的 Google Cloud Workflow 记录到包含该 URL 的 Google Cloud Logging。这是我的工作流程的一部分:

        - bq_job_get_post_completion:
            call: bqJobGet
            args:
                project_id: ${project_id}
                job_id: ${job_id}
            result: bq_job_get_response
        - set_job_completion_vars:
            assign:
                - jobCompletionStats:
                        jobId: ${job_id}
                        totalBytesBilled: ${bq_job_get_response.body.statistics.query.totalBytesBilled}
                        totalBytesProcessed: ${bq_job_get_response.body.statistics.query.totalBytesProcessed}
                        totalSlotMs: ${bq_job_get_response.body.statistics.query.totalSlotMs}
                        jobDetailsUrl: ${"https://console.cloud.google.com/bigquery?project=" + project_id + "&j=bq:EU:" + job_id + "&page=queryresults"}

注意jobDetailsUrl部分。

不幸的是,当这出现在云日志中时,URL 看起来像这样:

https://console.cloud.google.com/bigquery?project=my-redacted-project\u0026j=bq:EU:job_XXXXXX\u0026page=queryresults

如您所见,与号已替换为\u0026。我明白为什么会这样,26 是 & 符号的 unicode 字符代码......但是 URL 不再将我直接带到 Google Cloud Console 中的正确结果 - 基本上 URL 中的相关信息已失效。

谁能建议我如何阻止这种情况发生?我希望正确的 URL 出现在云日志记录中。

这是我的整个工作流程:

main:
    steps:
        - call_subWorkflow:
            call: callBQStoredProc
            args:
                stored_proc_name: "mydataset.my-stored-procedure"
                project_id: my-redacted-project


#SUBWORKFLOWS
callBQStoredProc:
    params: [stored_proc_name, project_id, poll_wait_time_seconds: 5]
    steps:
        - init:
            assign:
                - job:
                        jobReference:
                            location: EU
                        configuration:
                            query:
                                useLegacySql: false
                                useQueryCache: false
                                query: ${"call " + stored_proc_name + "()"}
        - log_start:
            call: sys.log
            args:
                text: >
                    ${"Starting execution of bigquery stored procedure \"" + stored_proc_name + "\" using subworkflow executeBQStoredProc"}
                severity: INFO
        - postCallStoredProc:
            call: http.post
            args:
                url: ${"https://bigquery.googleapis.com/bigquery/v2/projects/" + project_id + "/jobs"}
                body: ${job}
                auth:
                    type: OAuth2
            result: bq_jobs_insert_response
        - set_job_id:
            assign:
                - job_id: ${bq_jobs_insert_response.body.jobReference.jobId}
        - bq_job_get:
            call: bqJobGet
            args:
                project_id: ${project_id}
                job_id: ${job_id}
            result: bq_job_get_response
        - set_job_vars:
            assign:
                - job_state: ${bq_job_get_response.body.status.state}
                - job_project: ${bq_job_get_response.body.jobReference.projectId}
        - log_job_state:
            call: sys.log
            args:
                text: >
                    ${"Job " + job_id + " in project " + job_project + " has state : " + job_state}
                severity: INFO
        - check_job_state:
            switch:
                - condition: ${job_state != "DONE"}
                  steps:
                    - wait_10s:
                        call: sys.sleep
                        args:
                            seconds: ${int(poll_wait_time_seconds)}
                        next: bq_job_get
        - bq_job_get_post_completion:
            call: bqJobGet
            args:
                project_id: ${project_id}
                job_id: ${job_id}
            result: bq_job_get_response
        - set_job_completion_vars:
            assign:
                - jobCompletionStats:
                        jobId: ${job_id}
                        totalBytesBilled: ${bq_job_get_response.body.statistics.query.totalBytesBilled}
                        totalBytesProcessed: ${bq_job_get_response.body.statistics.query.totalBytesProcessed}
                        totalSlotMs: ${bq_job_get_response.body.statistics.query.totalSlotMs}
                        jobDetailsUrl: ${"https://console.cloud.google.com/bigquery?project=" + project_id + "&j=bq:EU:" + job_id + "&page=queryresults"}
        - log_job_completion:
            call: sys.log
            args:
                text: ${jobCompletionStats}
                severity: INFO
        - bq_job_get_query_results:
            call: http.request
            args:
                url: ${"https://bigquery.googleapis.com/bigquery/v2/projects/" + project_id + "/queries/" + job_id}
                method: GET
                auth:
                    type: OAuth2
            result: bq_job_get_query_results_response
        - returnResult:
            return: ${bq_job_get_query_results_response.body}
bqJobGet:
    params: [project_id, job_id]
    steps:
        - bq_job_get:
            call: http.request
            args:
                url: ${"https://bigquery.googleapis.com/bigquery/v2/projects/" + project_id + "/jobs/" + job_id}
                method: GET
                auth:
                    type: OAuth2
            result: bq_job_get_response
        - returnResult:
            return: ${bq_job_get_response}
4

0 回答 0