当日志报告成功时,为什么云功能会失败 return?
Why would a cloud function fail to return when the logs report success?
我有一个云函数,需要大约 5 分钟才能 运行。我每个星期一都需要它 运行 多次,所以我设置了一个 Google Cloud Scheduler 作业,每分钟调用它一次。
Cloud Scheduler 日志:
{
httpRequest: {}
insertId: "1cklvxkf7jdt20"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
jobName: "projects/site-speed-dashboard-v2/locations/us-central1/jobs/<job_id>"
status: "UNKNOWN"
targetType: "HTTP"
url: "https://us-central1-<project>.cloudfunctions.net/<function_id>"
}
logName: "projects/<project>/logs/cloudscheduler.googleapis.com%2Fexecutions"
receiveTimestamp: "2021-11-02T22:03:00.584062076Z"
resource: {
labels: {
job_id: "<job_id>"
location: "us-central1"
project_id: "<project>"
}
type: "cloud_scheduler_job"
}
severity: "ERROR"
timestamp: "2021-11-02T22:03:00.584062076Z"
}
Cloud Functions 日志大致如下所示:
2021-11-03T20:18:00.867270511Z
lighthouse-runner7jabijqjeuz1 Function execution started
2021-11-03T20:18:01.649Z
lighthouse-runner7jabijqjeuz1 Running task B
2021-11-03T20:18:01.651Z
lighthouse-runner7jabijqjeuz1 Status 1 of 5 on task B
2021-11-03T20:18:37.863Z
lighthouse-runner7jabijqjeuz1 Status 2 of 5 on task B
2021-11-03T20:19:06.586Z
lighthouse-runnervhyzz79vlmyb Saving results for task A...
2021-11-03T20:19:09.585588918Z
lighthouse-runnervhyzz79vlmyb Function execution took 308731 ms, finished with status code: 200
2021-11-03T20:19:14.866Z
lighthouse-runner7jabijqjeuz1 Status 3 of 5 on task B
2021-11-03T20:19:44.667Z
lighthouse-runner7jabijqjeuz1 Status 4 of 5 on task B
2021-11-03T20:20:15.261Z
lighthouse-runner7jabijqjeuz1 Status 5 of 5 on task B
2021-11-03T20:20:45.675Z
lighthouse-runner7jabijqjeuz1 Saving results for task B...
2021-11-03T20:20:48.338318504Z
lighthouse-runner7jabijqjeuz1 Function execution took 167472 ms, finished with status code: 200
2021-11-03T20:21:00.409847950Z
lighthouse-runner7jab3riqsqx7 Function execution started
2021-11-03T20:21:01.205Z
lighthouse-runner7jab3riqsqx7 Running task C
2021-11-03T20:21:01.206Z
lighthouse-runner7jab3riqsqx7 Status 1 of 5 on task C
2021-11-03T20:21:58.668Z
lighthouse-runner7jab3riqsqx7 Status 2 of 5 on task C
2021-11-03T20:23:05.464Z
lighthouse-runner7jab3riqsqx7 Status 3 of 5 on task C
2021-11-03T20:24:01.974Z
lighthouse-runner7jab3riqsqx7 Status 4 of 5 on task C
2021-11-03T20:25:00.416988195Z
lighthouse-runner9o59yxh9wi7g Function execution started
2021-11-03T20:25:01.608Z
lighthouse-runner9o59yxh9wi7g Running task D
2021-11-03T20:25:01.608Z
lighthouse-runner9o59yxh9wi7g Status 1 of 5 on task D
2021-11-03T20:25:08.062Z
lighthouse-runner7jab3riqsqx7 Status 5 of 5 on task C
2021-11-03T20:26:05.760Z
lighthouse-runner7jab3riqsqx7 Saving results for task C...
2021-11-03T20:26:09.605393223Z
lighthouse-runner7jab3riqsqx7 Function execution took 309196 ms, finished with status code: 200
2021-11-03T20:26:27.471Z
lighthouse-runner9o59yxh9wi7g Status 2 of 5 on task D
2021-11-03T20:27:37.853Z
lighthouse-runner9o59yxh9wi7g Status 3 of 5 on task D
请注意,日志中没有错误(我知道 ID 不匹配,但这是一个非常一致的模式)。这里发生了什么?
当没有重叠(或者通常只有 少 重叠)时,函数 运行 没问题,但我没有所需的吞吐量。 运行 本地没问题,每次都能成功returns 200
你的错误很常见。查看您的 Cloud Functions 日志:
2021-11-03T20:18:00.867270511Z lighthouse-runner7jabijqjeuz1 Function execution started
...
...
...
2021-11-03T20:20:48.338318504Z lighthouse-runner7jabijqjeuz1 Function execution took 167472 ms, finished with status code: 200
我只取了这两行,因为它们具有相同的 executionID 7jabijqjeuz1
。现在,不是处理时长:大约2分48秒。
没问题,我确定您会增加 Cloud Functions 超时。但是,Cloud Scheduler 超时默认也是 60 秒,如果 Cloud Scheduler 在延迟期间没有收到肯定的 ack,则 运行 被视为失败。
将 Cloud Scheduler 超时增加到 3 分钟(至少)以解决您的问题。
我有一个云函数,需要大约 5 分钟才能 运行。我每个星期一都需要它 运行 多次,所以我设置了一个 Google Cloud Scheduler 作业,每分钟调用它一次。
Cloud Scheduler 日志:
{
httpRequest: {}
insertId: "1cklvxkf7jdt20"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
jobName: "projects/site-speed-dashboard-v2/locations/us-central1/jobs/<job_id>"
status: "UNKNOWN"
targetType: "HTTP"
url: "https://us-central1-<project>.cloudfunctions.net/<function_id>"
}
logName: "projects/<project>/logs/cloudscheduler.googleapis.com%2Fexecutions"
receiveTimestamp: "2021-11-02T22:03:00.584062076Z"
resource: {
labels: {
job_id: "<job_id>"
location: "us-central1"
project_id: "<project>"
}
type: "cloud_scheduler_job"
}
severity: "ERROR"
timestamp: "2021-11-02T22:03:00.584062076Z"
}
Cloud Functions 日志大致如下所示:
2021-11-03T20:18:00.867270511Z
lighthouse-runner7jabijqjeuz1 Function execution started
2021-11-03T20:18:01.649Z
lighthouse-runner7jabijqjeuz1 Running task B
2021-11-03T20:18:01.651Z
lighthouse-runner7jabijqjeuz1 Status 1 of 5 on task B
2021-11-03T20:18:37.863Z
lighthouse-runner7jabijqjeuz1 Status 2 of 5 on task B
2021-11-03T20:19:06.586Z
lighthouse-runnervhyzz79vlmyb Saving results for task A...
2021-11-03T20:19:09.585588918Z
lighthouse-runnervhyzz79vlmyb Function execution took 308731 ms, finished with status code: 200
2021-11-03T20:19:14.866Z
lighthouse-runner7jabijqjeuz1 Status 3 of 5 on task B
2021-11-03T20:19:44.667Z
lighthouse-runner7jabijqjeuz1 Status 4 of 5 on task B
2021-11-03T20:20:15.261Z
lighthouse-runner7jabijqjeuz1 Status 5 of 5 on task B
2021-11-03T20:20:45.675Z
lighthouse-runner7jabijqjeuz1 Saving results for task B...
2021-11-03T20:20:48.338318504Z
lighthouse-runner7jabijqjeuz1 Function execution took 167472 ms, finished with status code: 200
2021-11-03T20:21:00.409847950Z
lighthouse-runner7jab3riqsqx7 Function execution started
2021-11-03T20:21:01.205Z
lighthouse-runner7jab3riqsqx7 Running task C
2021-11-03T20:21:01.206Z
lighthouse-runner7jab3riqsqx7 Status 1 of 5 on task C
2021-11-03T20:21:58.668Z
lighthouse-runner7jab3riqsqx7 Status 2 of 5 on task C
2021-11-03T20:23:05.464Z
lighthouse-runner7jab3riqsqx7 Status 3 of 5 on task C
2021-11-03T20:24:01.974Z
lighthouse-runner7jab3riqsqx7 Status 4 of 5 on task C
2021-11-03T20:25:00.416988195Z
lighthouse-runner9o59yxh9wi7g Function execution started
2021-11-03T20:25:01.608Z
lighthouse-runner9o59yxh9wi7g Running task D
2021-11-03T20:25:01.608Z
lighthouse-runner9o59yxh9wi7g Status 1 of 5 on task D
2021-11-03T20:25:08.062Z
lighthouse-runner7jab3riqsqx7 Status 5 of 5 on task C
2021-11-03T20:26:05.760Z
lighthouse-runner7jab3riqsqx7 Saving results for task C...
2021-11-03T20:26:09.605393223Z
lighthouse-runner7jab3riqsqx7 Function execution took 309196 ms, finished with status code: 200
2021-11-03T20:26:27.471Z
lighthouse-runner9o59yxh9wi7g Status 2 of 5 on task D
2021-11-03T20:27:37.853Z
lighthouse-runner9o59yxh9wi7g Status 3 of 5 on task D
请注意,日志中没有错误(我知道 ID 不匹配,但这是一个非常一致的模式)。这里发生了什么?
当没有重叠(或者通常只有 少 重叠)时,函数 运行 没问题,但我没有所需的吞吐量。 运行 本地没问题,每次都能成功returns 200
你的错误很常见。查看您的 Cloud Functions 日志:
2021-11-03T20:18:00.867270511Z lighthouse-runner7jabijqjeuz1 Function execution started
...
...
...
2021-11-03T20:20:48.338318504Z lighthouse-runner7jabijqjeuz1 Function execution took 167472 ms, finished with status code: 200
我只取了这两行,因为它们具有相同的 executionID 7jabijqjeuz1
。现在,不是处理时长:大约2分48秒。
没问题,我确定您会增加 Cloud Functions 超时。但是,Cloud Scheduler 超时默认也是 60 秒,如果 Cloud Scheduler 在延迟期间没有收到肯定的 ack,则 运行 被视为失败。
将 Cloud Scheduler 超时增加到 3 分钟(至少)以解决您的问题。