forked from actions/actions-runner-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics of RunnerDeployment and HRA (actions#408)
* Add metrics of RunnerDeployment and HRA * Use kube-state-metrics-style label names
- Loading branch information
Showing
5 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/summerwind/actions-runner-controller/api/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
hraName = "horizontalrunnerautoscaler" | ||
hraNamespace = "namespace" | ||
) | ||
|
||
var ( | ||
horizontalRunnerAutoscalerMetrics = []prometheus.Collector{ | ||
horizontalRunnerAutoscalerMinReplicas, | ||
horizontalRunnerAutoscalerMaxReplicas, | ||
horizontalRunnerAutoscalerDesiredReplicas, | ||
} | ||
) | ||
|
||
var ( | ||
horizontalRunnerAutoscalerMinReplicas = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "horizontalrunnerautoscaler_spec_min_replicas", | ||
Help: "minReplicas of HorizontalRunnerAutoscaler", | ||
}, | ||
[]string{hraName, hraNamespace}, | ||
) | ||
horizontalRunnerAutoscalerMaxReplicas = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "horizontalrunnerautoscaler_spec_max_replicas", | ||
Help: "maxReplicas of HorizontalRunnerAutoscaler", | ||
}, | ||
[]string{hraName, hraNamespace}, | ||
) | ||
horizontalRunnerAutoscalerDesiredReplicas = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "horizontalrunnerautoscaler_status_desired_replicas", | ||
Help: "desiredReplicas of HorizontalRunnerAutoscaler", | ||
}, | ||
[]string{hraName, hraNamespace}, | ||
) | ||
) | ||
|
||
func SetHorizontalRunnerAutoscalerSpec(o metav1.ObjectMeta, spec v1alpha1.HorizontalRunnerAutoscalerSpec) { | ||
labels := prometheus.Labels{ | ||
hraName: o.Name, | ||
hraNamespace: o.Namespace, | ||
} | ||
if spec.MaxReplicas != nil { | ||
horizontalRunnerAutoscalerMaxReplicas.With(labels).Set(float64(*spec.MaxReplicas)) | ||
} | ||
if spec.MinReplicas != nil { | ||
horizontalRunnerAutoscalerMinReplicas.With(labels).Set(float64(*spec.MinReplicas)) | ||
} | ||
} | ||
|
||
func SetHorizontalRunnerAutoscalerStatus(o metav1.ObjectMeta, status v1alpha1.HorizontalRunnerAutoscalerStatus) { | ||
labels := prometheus.Labels{ | ||
hraName: o.Name, | ||
hraNamespace: o.Namespace, | ||
} | ||
if status.DesiredReplicas != nil { | ||
horizontalRunnerAutoscalerDesiredReplicas.With(labels).Set(float64(*status.DesiredReplicas)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Package metrics provides the metrics of custom resources such as HRA. | ||
// | ||
// This depends on the metrics exporter of kubebuilder. | ||
// See https://book.kubebuilder.io/reference/metrics.html for details. | ||
package metrics | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
func init() { | ||
metrics.Registry.MustRegister(runnerDeploymentMetrics...) | ||
metrics.Registry.MustRegister(horizontalRunnerAutoscalerMetrics...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/summerwind/actions-runner-controller/api/v1alpha1" | ||
) | ||
|
||
const ( | ||
rdName = "runnerdeployment" | ||
rdNamespace = "namespace" | ||
) | ||
|
||
var ( | ||
runnerDeploymentMetrics = []prometheus.Collector{ | ||
runnerDeploymentReplicas, | ||
} | ||
) | ||
|
||
var ( | ||
runnerDeploymentReplicas = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "runnerdeployment_spec_replicas", | ||
Help: "replicas of RunnerDeployment", | ||
}, | ||
[]string{rdName, rdNamespace}, | ||
) | ||
) | ||
|
||
func SetRunnerDeployment(rd v1alpha1.RunnerDeployment) { | ||
labels := prometheus.Labels{ | ||
rdName: rd.Name, | ||
rdNamespace: rd.Namespace, | ||
} | ||
if rd.Spec.Replicas != nil { | ||
runnerDeploymentReplicas.With(labels).Set(float64(*rd.Spec.Replicas)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters