Skip to content

Commit 6c3e832

Browse files
committed
only track succeeded jobs
1 parent dfb4d1c commit 6c3e832

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

pkg/actionsmetrics/event_reader.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -213,30 +213,28 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
213213
}
214214
}
215215

216-
trackedRepositories := map[string]bool{
217-
"client": true,
218-
"client-dev": true,
219-
}
220-
221-
if _, ok := trackedRepositories[repoName]; ok {
222-
for _, step := range e.WorkflowJob.Steps {
223-
if step.StartedAt == nil || step.CompletedAt == nil || step.Conclusion == nil || step.Name == nil || step.Status == nil || step.Number == nil {
224-
continue // Skip steps with incomplete data
225-
}
216+
if *e.WorkflowJob.Conclusion == "success" {
217+
trackedRepositories := map[string]bool{
218+
"client": true,
219+
"client-dev": true,
220+
}
226221

227-
stepLabels := extraLabel("step_name", *step.Name, labels)
228-
stepLabels["step_number"] = fmt.Sprint(step.Number)
229-
stepLabels["step_conclusion"] = *step.Conclusion
230-
stepLabels["step_status"] = *step.Status
222+
if _, ok := trackedRepositories[repoName]; ok {
223+
for _, step := range e.WorkflowJob.Steps {
224+
stepLabels := extraLabel("step_name", *step.Name, labels)
225+
stepLabels["step_number"] = fmt.Sprint(step.Number)
226+
stepLabels["step_conclusion"] = *step.Conclusion
227+
stepLabels["step_status"] = *step.Status
231228

232-
stepDuration := step.CompletedAt.Sub(step.StartedAt.Time)
229+
stepDuration := step.CompletedAt.Sub(step.StartedAt.Time)
233230

234-
githubWorkflowJobStepDurationSeconds.With(stepLabels).Observe(stepDuration.Seconds())
231+
githubWorkflowJobStepDurationSeconds.With(stepLabels).Observe(stepDuration.Seconds())
235232

236-
log.Info("processed step", "step_name", *step.Name, "step_conclusion", *step.Conclusion, "step_duration_seconds", stepDuration.Seconds())
233+
log.Info("processed step", "step_name", *step.Name, "step_conclusion", *step.Conclusion, "step_duration_seconds", stepDuration.Seconds())
234+
}
235+
} else {
236+
log.Info("skipping the step reporting for the repo", "repo_name", repoName)
237237
}
238-
} else {
239-
log.Info("skipping the step reporting for the repo", "repo_name", repoName)
240238
}
241239
}
242240
}

0 commit comments

Comments
 (0)