diff --git a/apis/actions.github.com/v1alpha1/autoscalinglistener_types.go b/apis/actions.github.com/v1alpha1/autoscalinglistener_types.go index 5c35b88b..57363dba 100644 --- a/apis/actions.github.com/v1alpha1/autoscalinglistener_types.go +++ b/apis/actions.github.com/v1alpha1/autoscalinglistener_types.go @@ -61,6 +61,9 @@ type AutoscalingListenerSpec struct { // +optional GitHubServerTLS *GitHubServerTLSConfig `json:"githubServerTLS,omitempty"` + // +optional + Metrics *MetricsConfig `json:"metrics,omitempty"` + // +optional Template *corev1.PodTemplateSpec `json:"template,omitempty"` } diff --git a/apis/actions.github.com/v1alpha1/autoscalingrunnerset_types.go b/apis/actions.github.com/v1alpha1/autoscalingrunnerset_types.go index 55644d6b..cfc0d8b3 100644 --- a/apis/actions.github.com/v1alpha1/autoscalingrunnerset_types.go +++ b/apis/actions.github.com/v1alpha1/autoscalingrunnerset_types.go @@ -18,6 +18,7 @@ package v1alpha1 import ( "crypto/x509" + "encoding/json" "fmt" "net/http" "net/url" @@ -74,6 +75,9 @@ type AutoscalingRunnerSetSpec struct { // Required Template corev1.PodTemplateSpec `json:"template,omitempty"` + // +optional + ListenerMetrics *MetricsConfig `json:"metrics,omitempty"` + // +optional ListenerTemplate *corev1.PodTemplateSpec `json:"listenerTemplate,omitempty"` @@ -232,6 +236,29 @@ type ProxyServerConfig struct { CredentialSecretRef string `json:"credentialSecretRef,omitempty"` } +// MetricsConfig holds configuration parameters for each metric type +type MetricsConfig struct { + Counters map[string]*CounterMetric `json:"counters"` + Gauges map[string]*GaugeMetric `json:"gauges"` + Histograms map[string]*HistogramMetric `json:"histograms"` +} + +// CounterMetric holds configuration of a single metric of type Counter +type CounterMetric struct { + Labels []string `json:"labels"` +} + +// GaugeMetric holds configuration of a single metric of type Gauge +type GaugeMetric struct { + Labels []string `json:"labels"` +} + +// HistogramMetric holds configuration of a single metric of type Histogram +type HistogramMetric struct { + Labels []string `json:"labels"` + Buckets []json.Number `json:"buckets,omitempty"` +} + // AutoscalingRunnerSetStatus defines the observed state of AutoscalingRunnerSet type AutoscalingRunnerSetStatus struct { // +optional diff --git a/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalinglisteners.yaml b/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalinglisteners.yaml index 5edb826d..143c4c27 100644 --- a/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalinglisteners.yaml +++ b/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalinglisteners.yaml @@ -119,6 +119,55 @@ spec: description: Required minimum: 0 type: integer + metrics: + description: MetricsConfig holds configuration parameters for each metric type + properties: + counters: + additionalProperties: + description: CounterMetric holds configuration of a single metric of type Counter + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + gauges: + additionalProperties: + description: GaugeMetric holds configuration of a single metric of type Gauge + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + histograms: + additionalProperties: + description: HistogramMetric holds configuration of a single metric of type Histogram + properties: + buckets: + items: + description: A Number represents a JSON number literal. + type: string + type: array + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + required: + - counters + - gauges + - histograms + type: object minRunners: description: Required minimum: 0 diff --git a/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalingrunnersets.yaml b/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalingrunnersets.yaml index 33782f42..bb4a5863 100644 --- a/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalingrunnersets.yaml +++ b/charts/gha-runner-scale-set-controller/crds/actions.github.com_autoscalingrunnersets.yaml @@ -7772,6 +7772,55 @@ spec: maxRunners: minimum: 0 type: integer + metrics: + description: MetricsConfig holds configuration parameters for each metric type + properties: + counters: + additionalProperties: + description: CounterMetric holds configuration of a single metric of type Counter + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + gauges: + additionalProperties: + description: GaugeMetric holds configuration of a single metric of type Gauge + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + histograms: + additionalProperties: + description: HistogramMetric holds configuration of a single metric of type Histogram + properties: + buckets: + items: + description: A Number represents a JSON number literal. + type: string + type: array + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + required: + - counters + - gauges + - histograms + type: object minRunners: minimum: 0 type: integer diff --git a/charts/gha-runner-scale-set/values.yaml b/charts/gha-runner-scale-set/values.yaml index 7c32b436..2a9e7984 100644 --- a/charts/gha-runner-scale-set/values.yaml +++ b/charts/gha-runner-scale-set/values.yaml @@ -119,6 +119,35 @@ githubConfigSecret: # - name: side-car # image: example-sidecar +listenerMetrics: + counters: + gha_started_jobs_total: + labels: [] + gha_completed_jobs_total: + labels: [] + gauges: + gha_assigned_jobs: + labels: [] + gha_running_jobs: + labels: [] + gha_registered_runners: + labels: [] + gha_busy_runners: + labels: [] + gha_min_runners: + labels: [] + gha_max_runners: + labels: [] + gha_desired_runners: + labels: [] + gha_idle_runners: + labels: [] + histograms: + gha_job_startup_duration_seconds: + labels: [] + gha_job_execution_duration_seconds: + labels: [] + ## template is the PodSpec for each runner Pod ## For reference: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec template: diff --git a/cmd/ghalistener/config/config.go b/cmd/ghalistener/config/config.go index 838eb3fe..321b902c 100644 --- a/cmd/ghalistener/config/config.go +++ b/cmd/ghalistener/config/config.go @@ -8,6 +8,7 @@ import ( "net/url" "os" + "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1" "github.com/actions/actions-runner-controller/build" "github.com/actions/actions-runner-controller/github/actions" "github.com/actions/actions-runner-controller/logging" @@ -16,22 +17,23 @@ import ( ) type Config struct { - ConfigureUrl string `json:"configure_url"` - AppID int64 `json:"app_id"` - AppInstallationID int64 `json:"app_installation_id"` - AppPrivateKey string `json:"app_private_key"` - Token string `json:"token"` - EphemeralRunnerSetNamespace string `json:"ephemeral_runner_set_namespace"` - EphemeralRunnerSetName string `json:"ephemeral_runner_set_name"` - MaxRunners int `json:"max_runners"` - MinRunners int `json:"min_runners"` - RunnerScaleSetId int `json:"runner_scale_set_id"` - RunnerScaleSetName string `json:"runner_scale_set_name"` - ServerRootCA string `json:"server_root_ca"` - LogLevel string `json:"log_level"` - LogFormat string `json:"log_format"` - MetricsAddr string `json:"metrics_addr"` - MetricsEndpoint string `json:"metrics_endpoint"` + ConfigureUrl string `json:"configure_url"` + AppID int64 `json:"app_id"` + AppInstallationID int64 `json:"app_installation_id"` + AppPrivateKey string `json:"app_private_key"` + Token string `json:"token"` + EphemeralRunnerSetNamespace string `json:"ephemeral_runner_set_namespace"` + EphemeralRunnerSetName string `json:"ephemeral_runner_set_name"` + MaxRunners int `json:"max_runners"` + MinRunners int `json:"min_runners"` + RunnerScaleSetId int `json:"runner_scale_set_id"` + RunnerScaleSetName string `json:"runner_scale_set_name"` + ServerRootCA string `json:"server_root_ca"` + LogLevel string `json:"log_level"` + LogFormat string `json:"log_format"` + MetricsAddr string `json:"metrics_addr"` + MetricsEndpoint string `json:"metrics_endpoint"` + Metrics map[string]*v1alpha1.MetricConfig `json:"metrics"` } func Read(path string) (Config, error) { diff --git a/config/crd/bases/actions.github.com_autoscalinglisteners.yaml b/config/crd/bases/actions.github.com_autoscalinglisteners.yaml index 5edb826d..143c4c27 100644 --- a/config/crd/bases/actions.github.com_autoscalinglisteners.yaml +++ b/config/crd/bases/actions.github.com_autoscalinglisteners.yaml @@ -119,6 +119,55 @@ spec: description: Required minimum: 0 type: integer + metrics: + description: MetricsConfig holds configuration parameters for each metric type + properties: + counters: + additionalProperties: + description: CounterMetric holds configuration of a single metric of type Counter + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + gauges: + additionalProperties: + description: GaugeMetric holds configuration of a single metric of type Gauge + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + histograms: + additionalProperties: + description: HistogramMetric holds configuration of a single metric of type Histogram + properties: + buckets: + items: + description: A Number represents a JSON number literal. + type: string + type: array + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + required: + - counters + - gauges + - histograms + type: object minRunners: description: Required minimum: 0 diff --git a/config/crd/bases/actions.github.com_autoscalingrunnersets.yaml b/config/crd/bases/actions.github.com_autoscalingrunnersets.yaml index 33782f42..bb4a5863 100644 --- a/config/crd/bases/actions.github.com_autoscalingrunnersets.yaml +++ b/config/crd/bases/actions.github.com_autoscalingrunnersets.yaml @@ -7772,6 +7772,55 @@ spec: maxRunners: minimum: 0 type: integer + metrics: + description: MetricsConfig holds configuration parameters for each metric type + properties: + counters: + additionalProperties: + description: CounterMetric holds configuration of a single metric of type Counter + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + gauges: + additionalProperties: + description: GaugeMetric holds configuration of a single metric of type Gauge + properties: + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + histograms: + additionalProperties: + description: HistogramMetric holds configuration of a single metric of type Histogram + properties: + buckets: + items: + description: A Number represents a JSON number literal. + type: string + type: array + labels: + items: + type: string + type: array + required: + - labels + type: object + type: object + required: + - counters + - gauges + - histograms + type: object minRunners: minimum: 0 type: integer diff --git a/controllers/actions.github.com/resourcebuilder.go b/controllers/actions.github.com/resourcebuilder.go index 7a26f889..3fba12fc 100644 --- a/controllers/actions.github.com/resourcebuilder.go +++ b/controllers/actions.github.com/resourcebuilder.go @@ -125,6 +125,7 @@ func (b *ResourceBuilder) newAutoScalingListener(autoscalingRunnerSet *v1alpha1. ImagePullSecrets: imagePullSecrets, Proxy: autoscalingRunnerSet.Spec.Proxy, GitHubServerTLS: autoscalingRunnerSet.Spec.GitHubServerTLS, + Metrics: autoscalingRunnerSet.Spec.ListenerMetrics, Template: autoscalingRunnerSet.Spec.ListenerTemplate, }, } @@ -198,6 +199,7 @@ func (b *ResourceBuilder) newScaleSetListenerConfig(autoscalingListener *v1alpha LogFormat: scaleSetListenerLogFormat, MetricsAddr: metricsAddr, MetricsEndpoint: metricsEndpoint, + Metrics: autoscalingListener.Spec.Metrics, } var buf bytes.Buffer