From ab58a4c5371774cd5f4d560afc30f49666eebb6e Mon Sep 17 00:00:00 2001 From: Jeremy Donahue Date: Wed, 15 May 2024 16:26:29 -0700 Subject: [PATCH] Use timestamps from Workflow Job event as defaults for queued,started,completed time Default these values to the timestamps contained in the event. They will be updated if the log contains more accurate values, however the "Waiting for a runner to pick up this job..." and "Job is about to start running on the runner:" lines are only present in the logs until the job has finished, at which point they are removed from the job logs by Github, so they can't be used to calculate the job duration after the job has finished. Fixes actions/actions-runner-controller#3522 --- pkg/actionsmetrics/event_reader.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/actionsmetrics/event_reader.go b/pkg/actionsmetrics/event_reader.go index 606891fe..0c5f2cd9 100644 --- a/pkg/actionsmetrics/event_reader.go +++ b/pkg/actionsmetrics/event_reader.go @@ -244,6 +244,22 @@ func (reader *EventReader) fetchAndParseWorkflowJobLogs(ctx context.Context, e * startedTime time.Time completedTime time.Time ) + // Default these values to the timestamps contained in the event. They will + // be updated if the log contains more accurate values, however the + // "Waiting for a runner to pick up this job..." and "Job is about to start + // running on the runner:" lines are only present in the logs until the job + // has finished, at which point they are removed from the job logs by + // Github, so they can't be used to calculate the job duration after the + // job has finished. + if e.WorkflowJob.CreatedAt != nil { + queuedTime = e.WorkflowJob.CreatedAt.Time + } + if e.WorkflowJob.StartedAt != nil { + startedTime = e.WorkflowJob.StartedAt.Time + } + if e.WorkflowJob.CompletedAt != nil { + completedTime = e.WorkflowJob.CompletedAt.Time + } func() { // Read jobLogs.Body line by line