Skip to content

Commit a608abd

Browse files
authored
actions-metrics: Do our best not to fail the whole event processing on no API creds (#2459)
1 parent 02d9add commit a608abd

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

pkg/actionsmetrics/event_reader.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,27 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
136136
// job_conclusion -> (neutral, success, skipped, cancelled, timed_out, action_required, failure)
137137
githubWorkflowJobConclusionsTotal.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Inc()
138138

139-
parseResult, err := reader.fetchAndParseWorkflowJobLogs(ctx, e)
140-
if err != nil {
141-
log.Error(err, "reading workflow job log")
142-
return
143-
} else {
144-
log.Info("reading workflow_job logs", keysAndValues...)
139+
var (
140+
exitCode = "na"
141+
runTimeSeconds *float64
142+
)
143+
144+
// We need to do our best not to fail the whole event processing
145+
// when the user provided no GitHub API credentials.
146+
// See https://github.com/actions/actions-runner-controller/issues/2424
147+
if reader.GitHubClient != nil {
148+
parseResult, err := reader.fetchAndParseWorkflowJobLogs(ctx, e)
149+
if err != nil {
150+
log.Error(err, "reading workflow job log")
151+
return
152+
}
153+
154+
exitCode = parseResult.ExitCode
155+
156+
s := parseResult.RunTime.Seconds()
157+
runTimeSeconds = &s
158+
159+
log.WithValues(keysAndValues...).Info("reading workflow_job logs", "exit_code", exitCode)
145160
}
146161

147162
if *e.WorkflowJob.Conclusion == "failure" {
@@ -167,18 +182,20 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
167182
}
168183
if *conclusion == "timed_out" {
169184
failedStep = fmt.Sprint(i)
170-
parseResult.ExitCode = "timed_out"
185+
exitCode = "timed_out"
171186
break
172187
}
173188
}
174189
githubWorkflowJobFailuresTotal.With(
175190
extraLabel("failed_step", failedStep,
176-
extraLabel("exit_code", parseResult.ExitCode, labels),
191+
extraLabel("exit_code", exitCode, labels),
177192
),
178193
).Inc()
179194
}
180195

181-
githubWorkflowJobRunDurationSeconds.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Observe(parseResult.RunTime.Seconds())
196+
if runTimeSeconds != nil {
197+
githubWorkflowJobRunDurationSeconds.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Observe(*runTimeSeconds)
198+
}
182199
}
183200
}
184201

0 commit comments

Comments
 (0)