Skip to content

Commit ee7c975

Browse files
authored
feat: Add metrics per specific step in the CI job (#20)
* feat: Add metrics per specific step in the CI job In order to get more detailed overview of the CI runs, we want to add a new metric github_workflow_job_step_run_duration_seconds which is give the run stats for each job in each workflow. This way we will be able to see the full picture of the runs and see what takes the most of the time * only track succeeded jobs * only check client repo
1 parent d17051a commit ee7c975

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pkg/actionsmetrics/event_reader.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
7474
labels["job_name"] = *e.WorkflowJob.Name
7575
keysAndValues = append(keysAndValues, "job_name", *e.WorkflowJob.Name)
7676

77+
var repoName = ""
7778
if e.Repo != nil {
7879
if n := e.Repo.Name; n != nil {
80+
repoName = *n
7981
labels["repository"] = *n
8082
keysAndValues = append(keysAndValues, "repository", *n)
8183
}
@@ -210,6 +212,21 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
210212
githubWorkflowJobRunDurationSeconds.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Observe(*runTimeSeconds)
211213
}
212214
}
215+
216+
if *e.WorkflowJob.Conclusion == "success" && repoName == "client" {
217+
for _, step := range e.WorkflowJob.Steps {
218+
stepLabels := extraLabel("step_name", *step.Name, labels)
219+
stepLabels["step_number"] = fmt.Sprint(step.Number)
220+
stepLabels["step_conclusion"] = *step.Conclusion
221+
stepLabels["step_status"] = *step.Status
222+
223+
stepDuration := step.CompletedAt.Sub(step.StartedAt.Time)
224+
225+
githubWorkflowJobStepDurationSeconds.With(stepLabels).Observe(stepDuration.Seconds())
226+
227+
log.Info("processed step in the repository", "repo", repoName, "step_name", *step.Name, "step_conclusion", *step.Conclusion)
228+
}
229+
}
213230
}
214231
}
215232

pkg/actionsmetrics/metrics.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ func init() {
4242

4343
githubWorkflowJobQueueDurationSeconds = initGithubWorkflowJobQueueDurationSeconds(queueBuckets)
4444
githubWorkflowJobRunDurationSeconds = initGithubWorkflowJobRunDurationSeconds(runBuckets)
45+
githubWorkflowJobStepDurationSeconds = initGithubWorkflowJobStepDurationSeconds(runBuckets)
4546

4647
metrics.Registry.MustRegister(
4748
githubWorkflowJobQueueDurationSeconds,
4849
githubWorkflowJobRunDurationSeconds,
50+
githubWorkflowJobStepDurationSeconds,
4951
githubWorkflowJobConclusionsTotal,
5052
githubWorkflowJobsQueuedTotal,
5153
githubWorkflowJobsStartedTotal,
@@ -145,10 +147,22 @@ func initGithubWorkflowJobRunDurationSeconds(buckets []float64) *prometheus.Hist
145147
)
146148
}
147149

150+
func initGithubWorkflowJobStepDurationSeconds(buckets []float64) *prometheus.HistogramVec {
151+
return prometheus.NewHistogramVec(
152+
prometheus.HistogramOpts{
153+
Name: "github_workflow_job_step_run_duration_seconds",
154+
Help: "Run times for the steps in workflow jobs in seconds",
155+
Buckets: buckets,
156+
},
157+
metricLabels("step_name", "step_number", "step_conclusion", "step_status"),
158+
)
159+
}
160+
148161
var (
149162
commonLabels = []string{"runs_on", "job_name", "organization", "repository", "owner", "workflow_name", "is_main_branch"}
150163
githubWorkflowJobQueueDurationSeconds *prometheus.HistogramVec
151164
githubWorkflowJobRunDurationSeconds *prometheus.HistogramVec
165+
githubWorkflowJobStepDurationSeconds *prometheus.HistogramVec
152166
githubWorkflowJobConclusionsTotal = prometheus.NewCounterVec(
153167
prometheus.CounterOpts{
154168
Name: "github_workflow_job_conclusions_total",

0 commit comments

Comments
 (0)