diff --git a/pkg/actionsmetrics/event_reader.go b/pkg/actionsmetrics/event_reader.go index 3e14b8921a..f6f5b5902a 100644 --- a/pkg/actionsmetrics/event_reader.go +++ b/pkg/actionsmetrics/event_reader.go @@ -74,8 +74,10 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in labels["job_name"] = *e.WorkflowJob.Name keysAndValues = append(keysAndValues, "job_name", *e.WorkflowJob.Name) + var repoName = "" if e.Repo != nil { if n := e.Repo.Name; n != nil { + repoName = *n labels["repository"] = *n keysAndValues = append(keysAndValues, "repository", *n) } @@ -210,6 +212,21 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in githubWorkflowJobRunDurationSeconds.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Observe(*runTimeSeconds) } } + + if *e.WorkflowJob.Conclusion == "success" && repoName == "client" { + for _, step := range e.WorkflowJob.Steps { + stepLabels := extraLabel("step_name", *step.Name, labels) + stepLabels["step_number"] = fmt.Sprint(step.Number) + stepLabels["step_conclusion"] = *step.Conclusion + stepLabels["step_status"] = *step.Status + + stepDuration := step.CompletedAt.Sub(step.StartedAt.Time) + + githubWorkflowJobStepDurationSeconds.With(stepLabels).Observe(stepDuration.Seconds()) + + log.Info("processed step in the repository", "repo", repoName, "step_name", *step.Name, "step_conclusion", *step.Conclusion) + } + } } } diff --git a/pkg/actionsmetrics/metrics.go b/pkg/actionsmetrics/metrics.go index bb13e879d2..c31cf4c3ae 100644 --- a/pkg/actionsmetrics/metrics.go +++ b/pkg/actionsmetrics/metrics.go @@ -42,10 +42,12 @@ func init() { githubWorkflowJobQueueDurationSeconds = initGithubWorkflowJobQueueDurationSeconds(queueBuckets) githubWorkflowJobRunDurationSeconds = initGithubWorkflowJobRunDurationSeconds(runBuckets) + githubWorkflowJobStepDurationSeconds = initGithubWorkflowJobStepDurationSeconds(runBuckets) metrics.Registry.MustRegister( githubWorkflowJobQueueDurationSeconds, githubWorkflowJobRunDurationSeconds, + githubWorkflowJobStepDurationSeconds, githubWorkflowJobConclusionsTotal, githubWorkflowJobsQueuedTotal, githubWorkflowJobsStartedTotal, @@ -145,10 +147,22 @@ func initGithubWorkflowJobRunDurationSeconds(buckets []float64) *prometheus.Hist ) } +func initGithubWorkflowJobStepDurationSeconds(buckets []float64) *prometheus.HistogramVec { + return prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "github_workflow_job_step_run_duration_seconds", + Help: "Run times for the steps in workflow jobs in seconds", + Buckets: buckets, + }, + metricLabels("step_name", "step_number", "step_conclusion", "step_status"), + ) +} + var ( commonLabels = []string{"runs_on", "job_name", "organization", "repository", "owner", "workflow_name", "is_main_branch"} githubWorkflowJobQueueDurationSeconds *prometheus.HistogramVec githubWorkflowJobRunDurationSeconds *prometheus.HistogramVec + githubWorkflowJobStepDurationSeconds *prometheus.HistogramVec githubWorkflowJobConclusionsTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "github_workflow_job_conclusions_total",