From e1ffaee1dd0cc954f084fcdd5fd30547956cf4c6 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 14 Jan 2022 23:10:56 +0300 Subject: fix(gerrit-tvl): Support all documented Buildkite job statuses I'm not sure where the previous list originated, but it was missing some officially documented statuses. However, the API definitely returns statuses that are documented to only appear in other types, so this commit simply maps ALL statuses that Buildkite has documented for any type. Also adds a log statement in case we encounter a brand new, unknown, undocumented status. Change-Id: Iff003a3bd2608702019ae0f4137958435ad0856f Reviewed-on: https://cl.tvl.fyi/c/depot/+/4888 Autosubmit: tazjin Tested-by: BuildkiteCI Reviewed-by: lukegb --- ops/gerrit-tvl/static/tvl.js | 70 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/ops/gerrit-tvl/static/tvl.js b/ops/gerrit-tvl/static/tvl.js index 2f8db90945..f4592ef44b 100644 --- a/ops/gerrit-tvl/static/tvl.js +++ b/ops/gerrit-tvl/static/tvl.js @@ -24,6 +24,59 @@ function formatDuration(from, to) { return `${hoursTook}hr ${minutesRemainder}min`; } +// Maps the status of a Buildkite *job* to the statuses available for +// a Gerrit check. +// +// Note that jobs can have statuses that, according to the Buildkite +// documentation, are only available for builds, and maybe vice-versa. +// To deal with this we simply cover all statuses for all types here. +// +// Buildkite job statuses: https://buildkite.com/docs/pipelines/notifications#job-states +// +// Gerrit check statuses: https://gerrit.googlesource.com/gerrit/+/v3.4.0/polygerrit-ui/app/api/checks.ts#167 +// +// TODO(tazjin): Use SCHEDULED status once we have upgraded Gerrit +// past 3.4 +function jobStateToCheckRunStatus(state) { + const status = { + // Statuses documented for both types + 'blocked': 'RUNNABLE', + 'canceled': 'COMPLETED', + 'canceling': 'RUNNING', + 'running': 'RUNNING', + 'scheduled': 'RUNNABLE', + 'skipped': 'COMPLETED', + + // Statuses only documented for builds + 'creating': 'RUNNABLE', + 'failed': 'COMPLETED', + 'not_run': 'COMPLETED', + 'passed': 'COMPLETED', + + // Statuses only documented for jobs + 'accepted': 'RUNNABLE', + 'assigned': 'RUNNABLE', + 'blocked_failed': 'COMPLETED', + 'broken': 'COMPLETED', + 'finished': 'COMPLETED', + 'limited': 'RUNNABLE', + 'limiting': 'RUNNABLE', + 'pending': 'RUNNABLE', + 'timed_out': 'COMPLETED', + 'timing_out': 'RUNNING', + 'unblocked': 'RUNNABLE', + 'unblocked_failed': 'COMPLETED', + 'waiting': 'RUNNABLE', + 'waiting_failed': 'COMPLETED', + }[state]; + + if (!status) { + console.log(`unknown Buildkite job state: ${state}`); + } + + return status; +} + const tvlChecksProvider = { async fetch(change) { let {changeNumber, patchsetNumber, repo} = change; @@ -58,32 +111,25 @@ const tvlChecksProvider = { const build = respJSON[i]; for (let job of build.jobs) { - // TODO(lukegb): add the ability to retry these (sometimes whitby runs out of disk...) + // TODO(lukegb): add the ability to retry these const checkRun = { attempt: attempt, externalId: job.id, checkName: job.name, checkDescription: job.command, checkLink: job.web_url, - status: { - 'running': 'RUNNING', - 'scheduled': 'RUNNABLE', - 'passed': 'COMPLETED', - 'failed': 'COMPLETED', - 'blocked': 'RUNNABLE', - 'canceled': 'COMPLETED', - 'canceling': 'RUNNING', - 'skipped': 'COMPLETED', - 'not_run': 'COMPLETED', - }[job.state], + status: jobStateToCheckRunStatus(job.state), labelName: 'Verified', }; + if (job.scheduled_at) { checkRun.scheduledTimestamp = new Date(job.scheduled_at); } + if (job.started_at) { checkRun.startedTimestamp = new Date(job.started_at); } + if (job.finished_at) { checkRun.finishedTimestamp = new Date(job.finished_at); } -- cgit 1.4.1