Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACCDT-1238: Parametrize actions metrics histogram buckets size #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
env:
REGISTRY_IMAGE: ghcr.io/miroapp/actions-runner-controller
BUILD_PLATFORM: linux/amd64
BUILD_VERSION: ${{ github.sha }}
BUILD_VERSION: ${{ github.event_name != 'pull_request' && 'master' || 'branch' }}-${{ github.sha }}
steps:
- uses: docker/setup-buildx-action@v3

Expand All @@ -113,7 +113,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}

- uses: docker/build-push-action@v5
id: build
with:
Expand All @@ -128,5 +128,5 @@ jobs:
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}
platforms: ${{ env.BUILD_PLATFORM }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ env.REGISTRY_IMAGE }}:${{ env.BUILD_VERSION }}
72 changes: 64 additions & 8 deletions pkg/actionsmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,44 @@
package actionsmetrics

import (
"fmt"
"os"
"strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

const (
prometheusRunBucketIntervalsName = "PROMETHEUS_RUN_BUCKET_INTERVALS"
prometheusQueueBucketIntervalsName = "PROMETHEUS_QUEUE_BUCKET_INTERVALS"
)

func init() {
queueBuckets := defaultRuntimeBuckets
if _, ok := os.LookupEnv(prometheusQueueBucketIntervalsName); ok {
buckets, err := parseBucketsString(os.Getenv(prometheusQueueBucketIntervalsName))
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Failed to parse %s, using default buckets: %s\n", prometheusQueueBucketIntervalsName, err)
} else {
queueBuckets = buckets
}
}

runBuckets := defaultRuntimeBuckets
if _, ok := os.LookupEnv(prometheusRunBucketIntervalsName); ok {
buckets, err := parseBucketsString(os.Getenv(prometheusRunBucketIntervalsName))
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Failed to parse %s, using default buckets: %s\n", prometheusRunBucketIntervalsName, err)
} else {
runBuckets = buckets
}
}

githubWorkflowJobQueueDurationSeconds = initGithubWorkflowJobQueueDurationSeconds(queueBuckets)
githubWorkflowJobRunDurationSeconds = initGithubWorkflowJobRunDurationSeconds(runBuckets)

metrics.Registry.MustRegister(
githubWorkflowJobQueueDurationSeconds,
githubWorkflowJobRunDurationSeconds,
Expand All @@ -22,7 +55,7 @@ func init() {
}

var (
runtimeBuckets []float64 = []float64{
defaultRuntimeBuckets = []float64{
0.01,
0.05,
0.1,
Expand Down Expand Up @@ -75,25 +108,48 @@ func metricLabels(extras ...string) []string {
return append(append([]string{}, commonLabels...), extras...)
}

var (
commonLabels = []string{"runs_on", "job_name", "organization", "repository", "repository_full_name", "owner", "workflow_name", "head_branch"}
githubWorkflowJobQueueDurationSeconds = prometheus.NewHistogramVec(
func parseBucketsString(value string) ([]float64, error) {
valuesStr := strings.Split(value, ",")
buckets := make([]float64, 0, len(valuesStr))

for _, str := range valuesStr {
val, err := strconv.ParseFloat(str, 64)
if err != nil {
return nil, err
}
buckets = append(buckets, val)
}

return buckets, nil
}

func initGithubWorkflowJobQueueDurationSeconds(buckets []float64) *prometheus.HistogramVec {
return prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "github_workflow_job_queue_duration_seconds",
Help: "Queue times for workflow jobs in seconds",
Buckets: runtimeBuckets,
Buckets: buckets,
},
metricLabels(),
)
githubWorkflowJobRunDurationSeconds = prometheus.NewHistogramVec(
}

func initGithubWorkflowJobRunDurationSeconds(buckets []float64) *prometheus.HistogramVec {
return prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "github_workflow_job_run_duration_seconds",
Help: "Run times for workflow jobs in seconds",
Buckets: runtimeBuckets,
Buckets: buckets,
},
metricLabels("job_conclusion"),
)
githubWorkflowJobConclusionsTotal = prometheus.NewCounterVec(
}

var (
commonLabels = []string{"runs_on", "job_name", "organization", "repository", "repository_full_name", "owner", "workflow_name", "head_branch"}
githubWorkflowJobQueueDurationSeconds *prometheus.HistogramVec
githubWorkflowJobRunDurationSeconds *prometheus.HistogramVec
githubWorkflowJobConclusionsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "github_workflow_job_conclusions_total",
Help: "Conclusions for tracked workflow jobs",
Expand Down