INCLUDE_RUNNER_SCALE_SET_NAME_IN_JOB_LABELS=true to include it into job metrics labels
This commit is contained in:
parent
ae7ade0191
commit
3778fb0f65
|
|
@ -3,6 +3,7 @@ package metrics
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -46,14 +47,25 @@ var (
|
||||||
labelKeyJobName,
|
labelKeyJobName,
|
||||||
labelKeyJobWorkflowRef,
|
labelKeyJobWorkflowRef,
|
||||||
labelKeyEventName,
|
labelKeyEventName,
|
||||||
|
labelKeyRunnerID,
|
||||||
|
labelKeyRunnerName,
|
||||||
}
|
}
|
||||||
|
|
||||||
completedJobsTotalLabels = append(jobLabels, labelKeyJobResult, labelKeyRunnerID, labelKeyRunnerName)
|
completedJobLabels []string
|
||||||
jobExecutionDurationLabels = append(jobLabels, labelKeyJobResult, labelKeyRunnerID, labelKeyRunnerName)
|
|
||||||
startedJobsTotalLabels = append(jobLabels, labelKeyRunnerID, labelKeyRunnerName)
|
includeRunnerScaleSetNameInJobLabels = false
|
||||||
jobStartupDurationLabels = append(jobLabels, labelKeyRunnerID, labelKeyRunnerName)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if os.Getenv("INCLUDE_RUNNER_SCALE_SET_NAME_IN_JOB_LABELS") == "true" {
|
||||||
|
includeRunnerScaleSetNameInJobLabels = true
|
||||||
|
|
||||||
|
jobLabels = append(jobLabels, labelKeyRunnerScaleSetName)
|
||||||
|
}
|
||||||
|
|
||||||
|
completedJobLabels = append([]string{}, append(jobLabels, labelKeyJobResult)...)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
assignedJobs = prometheus.NewGaugeVec(
|
assignedJobs = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
|
|
@ -133,7 +145,7 @@ var (
|
||||||
Name: "started_jobs_total",
|
Name: "started_jobs_total",
|
||||||
Help: "Total number of jobs started.",
|
Help: "Total number of jobs started.",
|
||||||
},
|
},
|
||||||
startedJobsTotalLabels,
|
jobLabels,
|
||||||
)
|
)
|
||||||
|
|
||||||
completedJobsTotal = prometheus.NewCounterVec(
|
completedJobsTotal = prometheus.NewCounterVec(
|
||||||
|
|
@ -142,7 +154,7 @@ var (
|
||||||
Help: "Total number of jobs completed.",
|
Help: "Total number of jobs completed.",
|
||||||
Subsystem: githubScaleSetSubsystem,
|
Subsystem: githubScaleSetSubsystem,
|
||||||
},
|
},
|
||||||
completedJobsTotalLabels,
|
completedJobLabels,
|
||||||
)
|
)
|
||||||
|
|
||||||
jobStartupDurationSeconds = prometheus.NewHistogramVec(
|
jobStartupDurationSeconds = prometheus.NewHistogramVec(
|
||||||
|
|
@ -152,7 +164,7 @@ var (
|
||||||
Help: "Time spent waiting for workflow job to get started on the runner owned by the scale set (in seconds).",
|
Help: "Time spent waiting for workflow job to get started on the runner owned by the scale set (in seconds).",
|
||||||
Buckets: runtimeBuckets,
|
Buckets: runtimeBuckets,
|
||||||
},
|
},
|
||||||
jobStartupDurationLabels,
|
jobLabels,
|
||||||
)
|
)
|
||||||
|
|
||||||
jobExecutionDurationSeconds = prometheus.NewHistogramVec(
|
jobExecutionDurationSeconds = prometheus.NewHistogramVec(
|
||||||
|
|
@ -162,7 +174,7 @@ var (
|
||||||
Help: "Time spent executing workflow jobs by the scale set (in seconds).",
|
Help: "Time spent executing workflow jobs by the scale set (in seconds).",
|
||||||
Buckets: runtimeBuckets,
|
Buckets: runtimeBuckets,
|
||||||
},
|
},
|
||||||
jobExecutionDurationLabels,
|
completedJobLabels,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -223,7 +235,7 @@ type baseLabels struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *baseLabels) jobLabels(jobBase *actions.JobMessageBase) prometheus.Labels {
|
func (b *baseLabels) jobLabels(jobBase *actions.JobMessageBase) prometheus.Labels {
|
||||||
return prometheus.Labels{
|
l := prometheus.Labels{
|
||||||
labelKeyEnterprise: b.enterprise,
|
labelKeyEnterprise: b.enterprise,
|
||||||
labelKeyOrganization: jobBase.OwnerName,
|
labelKeyOrganization: jobBase.OwnerName,
|
||||||
labelKeyRepository: jobBase.RepositoryName,
|
labelKeyRepository: jobBase.RepositoryName,
|
||||||
|
|
@ -231,6 +243,10 @@ func (b *baseLabels) jobLabels(jobBase *actions.JobMessageBase) prometheus.Label
|
||||||
labelKeyJobWorkflowRef: jobBase.JobWorkflowRef,
|
labelKeyJobWorkflowRef: jobBase.JobWorkflowRef,
|
||||||
labelKeyEventName: jobBase.EventName,
|
labelKeyEventName: jobBase.EventName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if includeRunnerScaleSetNameInJobLabels {
|
||||||
|
l[labelKeyRunnerScaleSetName] = b.scaleSetName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *baseLabels) scaleSetLabels() prometheus.Labels {
|
func (b *baseLabels) scaleSetLabels() prometheus.Labels {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue