feat(actionsmetrics): Add owner and workflow_name labels to workflow job metrics (#2225)
This commit is contained in:
parent
af625dd1cb
commit
bcaac39a2e
|
|
@ -79,14 +79,34 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
|
|||
labels["repository_full_name"] = *n
|
||||
keysAndValues = append(keysAndValues, "repository_full_name", *n)
|
||||
}
|
||||
|
||||
if e.Repo.Owner != nil {
|
||||
if l := e.Repo.Owner.Login; l != nil {
|
||||
labels["owner"] = *l
|
||||
keysAndValues = append(keysAndValues, "owner", *l)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var org string
|
||||
if e.Org != nil {
|
||||
if n := e.Org.Name; n != nil {
|
||||
labels["organization"] = *e.Org.Name
|
||||
org = *n
|
||||
keysAndValues = append(keysAndValues, "organization", *n)
|
||||
}
|
||||
}
|
||||
labels["organization"] = org
|
||||
|
||||
var wn string
|
||||
if e.WorkflowJob != nil {
|
||||
if n := e.WorkflowJob.WorkflowName; n != nil {
|
||||
wn = *n
|
||||
keysAndValues = append(keysAndValues, "workflow_name", *n)
|
||||
}
|
||||
}
|
||||
labels["workflow_name"] = wn
|
||||
|
||||
log := reader.Log.WithValues(keysAndValues...)
|
||||
|
||||
// switch on job status
|
||||
switch action := e.GetAction(); action {
|
||||
|
|
@ -102,14 +122,10 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
|
|||
|
||||
parseResult, err := reader.fetchAndParseWorkflowJobLogs(ctx, e)
|
||||
if err != nil {
|
||||
reader.Log.Error(err, "reading workflow job log")
|
||||
log.Error(err, "reading workflow job log")
|
||||
return
|
||||
} else {
|
||||
reader.Log.WithValues("job_name", *e.WorkflowJob.Name, "job_id", fmt.Sprint(*e.WorkflowJob.ID), "repository", *e.Repo.Name, "repository_full_name", *e.Repo.FullName)
|
||||
if len(*e.Org.Name) > 0 {
|
||||
reader.Log.WithValues("organization", *e.Org.Name)
|
||||
}
|
||||
reader.Log.Info("reading workflow_job logs")
|
||||
log.Info("reading workflow_job logs")
|
||||
}
|
||||
|
||||
githubWorkflowJobQueueDurationSeconds.With(labels).Observe(parseResult.QueueTime.Seconds())
|
||||
|
|
@ -122,10 +138,10 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
|
|||
|
||||
parseResult, err := reader.fetchAndParseWorkflowJobLogs(ctx, e)
|
||||
if err != nil {
|
||||
reader.Log.Error(err, "reading workflow job log")
|
||||
log.Error(err, "reading workflow job log")
|
||||
return
|
||||
} else {
|
||||
reader.Log.Info("reading workflow_job logs", keysAndValues...)
|
||||
log.Info("reading workflow_job logs", keysAndValues...)
|
||||
}
|
||||
|
||||
if *e.WorkflowJob.Conclusion == "failure" {
|
||||
|
|
|
|||
|
|
@ -71,14 +71,19 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func metricLabels(extras ...string) []string {
|
||||
return append(append([]string{}, commonLabels...), extras...)
|
||||
}
|
||||
|
||||
var (
|
||||
commonLabels = []string{"runs_on", "job_name", "organization", "repository", "repository_full_name", "owner", "workflow_name"}
|
||||
githubWorkflowJobQueueDurationSeconds = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "github_workflow_job_queue_duration_seconds",
|
||||
Help: "Queue times for workflow jobs in seconds",
|
||||
Buckets: runtimeBuckets,
|
||||
},
|
||||
[]string{"runs_on", "job_name"},
|
||||
metricLabels(),
|
||||
)
|
||||
githubWorkflowJobRunDurationSeconds = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
|
|
@ -86,41 +91,41 @@ var (
|
|||
Help: "Run times for workflow jobs in seconds",
|
||||
Buckets: runtimeBuckets,
|
||||
},
|
||||
[]string{"runs_on", "job_name", "job_conclusion"},
|
||||
metricLabels("job_conclusion"),
|
||||
)
|
||||
githubWorkflowJobConclusionsTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "github_workflow_job_conclusions_total",
|
||||
Help: "Conclusions for tracked workflow jobs",
|
||||
},
|
||||
[]string{"runs_on", "job_name", "job_conclusion"},
|
||||
metricLabels("job_conclusion"),
|
||||
)
|
||||
githubWorkflowJobsQueuedTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "github_workflow_jobs_queued_total",
|
||||
Help: "Total count of workflow jobs queued (events where job_status=queued)",
|
||||
},
|
||||
[]string{"runs_on", "job_name"},
|
||||
metricLabels(),
|
||||
)
|
||||
githubWorkflowJobsStartedTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "github_workflow_jobs_started_total",
|
||||
Help: "Total count of workflow jobs started (events where job_status=in_progress)",
|
||||
},
|
||||
[]string{"runs_on", "job_name"},
|
||||
metricLabels(),
|
||||
)
|
||||
githubWorkflowJobsCompletedTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "github_workflow_jobs_completed_total",
|
||||
Help: "Total count of workflow jobs completed (events where job_status=completed)",
|
||||
},
|
||||
[]string{"runs_on", "job_name"},
|
||||
metricLabels(),
|
||||
)
|
||||
githubWorkflowJobFailuresTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "github_workflow_job_failures_total",
|
||||
Help: "Conclusions for tracked workflow runs",
|
||||
},
|
||||
[]string{"runs_on", "job_name", "failed_step", "exit_code"},
|
||||
metricLabels("failed_step", "exit_code"),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
gogithub "github.com/google/go-github/v47/github"
|
||||
gogithub "github.com/google/go-github/v50/github"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
|
||||
"github.com/actions/actions-runner-controller/github"
|
||||
|
|
|
|||
Loading…
Reference in New Issue