mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 19:50:30 +00:00
Add reposity name and full name for prometheus labels in actions metrics (#2218)
Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
gogithub "github.com/google/go-github/v47/github"
|
||||
gogithub "github.com/google/go-github/v50/github"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/actions/actions-runner-controller/github"
|
||||
@@ -59,11 +59,34 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
|
||||
}
|
||||
|
||||
// collect labels
|
||||
labels := make(prometheus.Labels)
|
||||
var (
|
||||
labels = make(prometheus.Labels)
|
||||
keysAndValues = []interface{}{"job_id", fmt.Sprint(*e.WorkflowJob.ID)}
|
||||
)
|
||||
|
||||
runsOn := strings.Join(e.WorkflowJob.Labels, `,`)
|
||||
labels["runs_on"] = runsOn
|
||||
|
||||
labels["job_name"] = *e.WorkflowJob.Name
|
||||
keysAndValues = append(keysAndValues, "job_name", *e.WorkflowJob.Name)
|
||||
|
||||
if e.Repo != nil {
|
||||
if n := e.Repo.Name; n != nil {
|
||||
labels["repository"] = *n
|
||||
keysAndValues = append(keysAndValues, "repository", *n)
|
||||
}
|
||||
if n := e.Repo.FullName; n != nil {
|
||||
labels["repository_full_name"] = *n
|
||||
keysAndValues = append(keysAndValues, "repository_full_name", *n)
|
||||
}
|
||||
}
|
||||
|
||||
if e.Org != nil {
|
||||
if n := e.Org.Name; n != nil {
|
||||
labels["organization"] = *e.Org.Name
|
||||
keysAndValues = append(keysAndValues, "organization", *n)
|
||||
}
|
||||
}
|
||||
|
||||
// switch on job status
|
||||
switch action := e.GetAction(); action {
|
||||
@@ -82,10 +105,11 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
|
||||
reader.Log.Error(err, "reading workflow job log")
|
||||
return
|
||||
} else {
|
||||
reader.Log.Info("reading workflow_job logs",
|
||||
"job_name", *e.WorkflowJob.Name,
|
||||
"job_id", fmt.Sprint(*e.WorkflowJob.ID),
|
||||
)
|
||||
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")
|
||||
}
|
||||
|
||||
githubWorkflowJobQueueDurationSeconds.With(labels).Observe(parseResult.QueueTime.Seconds())
|
||||
@@ -101,10 +125,7 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
|
||||
reader.Log.Error(err, "reading workflow job log")
|
||||
return
|
||||
} else {
|
||||
reader.Log.Info("reading workflow_job logs",
|
||||
"job_name", *e.WorkflowJob.Name,
|
||||
"job_id", fmt.Sprint(*e.WorkflowJob.ID),
|
||||
)
|
||||
reader.Log.Info("reading workflow_job logs", keysAndValues...)
|
||||
}
|
||||
|
||||
if *e.WorkflowJob.Conclusion == "failure" {
|
||||
|
||||
Reference in New Issue
Block a user