Use metrics to display runner statuses instead of status field for EphemeralRunnerSet and AutoscalingRunnerSet (#4557)

This commit is contained in:
Nikola Jokic
2026-07-14 19:31:11 +02:00
committed by GitHub
parent 368e2f28b8
commit f6a3d738de
22 changed files with 509 additions and 449 deletions
@@ -1,6 +1,7 @@
package metrics
import (
"github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)
@@ -50,6 +51,14 @@ var (
},
labels,
)
succeededEphemeralRunners = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: githubScaleSetControllerSubsystem,
Name: "succeeded_ephemeral_runners",
Help: "Number of ephemeral runners in a succeeded state.",
},
labels,
)
failedEphemeralRunners = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: githubScaleSetControllerSubsystem,
@@ -58,6 +67,14 @@ var (
},
labels,
)
outdatedEphemeralRunners = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: githubScaleSetControllerSubsystem,
Name: "outdated_ephemeral_runners",
Help: "Number of ephemeral runners in an outdated state.",
},
labels,
)
runningListeners = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: githubScaleSetControllerSubsystem,
@@ -72,15 +89,34 @@ func RegisterMetrics() {
metrics.Registry.MustRegister(
pendingEphemeralRunners,
runningEphemeralRunners,
succeededEphemeralRunners,
failedEphemeralRunners,
outdatedEphemeralRunners,
runningListeners,
)
}
func SetEphemeralRunnerCountsByStatus(commonLabels CommonLabels, pending, running, failed int) {
pendingEphemeralRunners.With(commonLabels.labels()).Set(float64(pending))
runningEphemeralRunners.With(commonLabels.labels()).Set(float64(running))
failedEphemeralRunners.With(commonLabels.labels()).Set(float64(failed))
func AddEphemeralRunner(commonLabels CommonLabels, phase v1alpha1.EphemeralRunnerPhase) {
updateEphemeralRunner(commonLabels, phase, 1)
}
func SubEphemeralRunner(commonLabels CommonLabels, phase v1alpha1.EphemeralRunnerPhase) {
updateEphemeralRunner(commonLabels, phase, -1)
}
func updateEphemeralRunner(commonLabels CommonLabels, phase v1alpha1.EphemeralRunnerPhase, delta float64) {
switch phase {
case v1alpha1.EphemeralRunnerPhasePending:
pendingEphemeralRunners.With(commonLabels.labels()).Add(delta)
case v1alpha1.EphemeralRunnerPhaseRunning:
runningEphemeralRunners.With(commonLabels.labels()).Add(delta)
case v1alpha1.EphemeralRunnerPhaseSucceeded:
succeededEphemeralRunners.With(commonLabels.labels()).Add(delta)
case v1alpha1.EphemeralRunnerPhaseFailed:
failedEphemeralRunners.With(commonLabels.labels()).Add(delta)
case v1alpha1.EphemeralRunnerPhaseOutdated:
outdatedEphemeralRunners.With(commonLabels.labels()).Add(delta)
}
}
func AddRunningListener(commonLabels CommonLabels) {