From 50f78906b3039871dc83f9e26f07db81d2f351c7 Mon Sep 17 00:00:00 2001 From: Kyrylo Bilchenko Date: Wed, 6 Mar 2024 17:58:25 +0100 Subject: [PATCH] Improve logging and print url for debug (#17) Co-authored-by: kyrylomiro --- pkg/actionsmetrics/event_reader.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/actionsmetrics/event_reader.go b/pkg/actionsmetrics/event_reader.go index 1136bdb28a..eff53696b8 100644 --- a/pkg/actionsmetrics/event_reader.go +++ b/pkg/actionsmetrics/event_reader.go @@ -109,7 +109,7 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in log := reader.Log.WithValues(keysAndValues...) // switch on job status - switch action := e.GetAction(); action { + switch action := *e.WorkflowJob.Status; strings.ToLower(action) { case "queued": githubWorkflowJobsQueuedTotal.With(labels).Inc() @@ -125,7 +125,7 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in log.Error(err, "reading workflow job log") return } else { - log.Info("reading workflow_job logs") + log.Info("reading workflow_job logs for in progress job", "workflow_job_status", *e.WorkflowJob.Status, "parseResult", &parseResult) } githubWorkflowJobQueueDurationSeconds.With(labels).Observe(parseResult.QueueTime.Seconds()) @@ -160,7 +160,7 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in s := parseResult.RunTime.Seconds() runTimeSeconds = &s - log.Info("reading workflow_job logs", "exit_code", exitCode, "run_time_seconds", &runTimeSeconds, "parseResult", &parseResult) + log.Info("reading workflow_job logs for completed job", "exit_code", exitCode, "run_time_seconds", &runTimeSeconds, "parseResult", &parseResult) } if *e.WorkflowJob.Conclusion == "failure" { @@ -232,6 +232,15 @@ func (reader *EventReader) fetchAndParseWorkflowJobLogs(ctx context.Context, e * if err != nil { return nil, err } + if *e.WorkflowJob.Status == "in_progress" { + if strings.Contains(url.String(), "actions-results") { + return &ParseResult{ + ExitCode: "", + QueueTime: time.Duration(0), + RunTime: time.Duration(0), + }, nil + } + } jobLogs, err := http.DefaultClient.Get(url.String()) if err != nil { return nil, err