Started implementing configurable metrics model

This commit is contained in:
Nikola Jokic 2025-03-13 14:07:57 +01:00
parent fb9b96bf75
commit dbac795ab0
No known key found for this signature in database
GPG Key ID: 09265A4BEA4F568A
9 changed files with 275 additions and 16 deletions

View File

@ -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"`
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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"
@ -32,6 +33,7 @@ type Config struct {
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) {

View File

@ -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

View File

@ -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

View File

@ -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