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:
parent
7d0918b6d5
commit
ec3afef00d
1
go.mod
1
go.mod
|
|
@ -57,6 +57,7 @@ require (
|
|||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/gnostic v0.5.7-v3refs // indirect
|
||||
github.com/google/go-github/v45 v45.2.0 // indirect
|
||||
github.com/google/go-github/v50 v50.0.0 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/gofuzz v1.1.0 // indirect
|
||||
github.com/gruntwork-io/go-commons v0.8.0 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -178,6 +178,8 @@ github.com/google/go-github/v45 v45.2.0 h1:5oRLszbrkvxDDqBCNj2hjDZMKmvexaZ1xw/FC
|
|||
github.com/google/go-github/v45 v45.2.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
|
||||
github.com/google/go-github/v47 v47.1.0 h1:Cacm/WxQBOa9lF0FT0EMjZ2BWMetQ1TQfyurn4yF1z8=
|
||||
github.com/google/go-github/v47 v47.1.0/go.mod h1:VPZBXNbFSJGjyjFRUKo9vZGawTajnWzC/YjGw/oFKi0=
|
||||
github.com/google/go-github/v50 v50.0.0 h1:gdO1AeuSZZK4iYWwVbjni7zg8PIQhp7QfmPunr016Jk=
|
||||
github.com/google/go-github/v50 v50.0.0/go.mod h1:Ev4Tre8QoKiolvbpOSG3FIi4Mlon3S2Nt9W5JYqKiwA=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
|
|
|
|||
|
|
@ -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" {
|
||||
|
|
|
|||
Loading…
Reference in New Issue