From 3219cfe1c83c068249453a238c3c33c4da38f5d3 Mon Sep 17 00:00:00 2001 From: kirillbilchenko Date: Mon, 18 Sep 2023 18:28:41 +0200 Subject: [PATCH] add ability to override separate queue and run buckets for histograms --- cmd/actionsmetricsserver/main.go | 13 ++++++++----- pkg/actionsmetrics/metrics.go | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cmd/actionsmetricsserver/main.go b/cmd/actionsmetricsserver/main.go index c2e3104344..7a39a16db1 100644 --- a/cmd/actionsmetricsserver/main.go +++ b/cmd/actionsmetricsserver/main.go @@ -48,8 +48,9 @@ var ( ) const ( - webhookSecretTokenEnvName = "GITHUB_WEBHOOK_SECRET_TOKEN" - prometheusBucketIntervalsName = "PROMETHEUS_BUCKET_INTERVALS" + webhookSecretTokenEnvName = "GITHUB_WEBHOOK_SECRET_TOKEN" + prometheusRunBucketIntervalsName = "PROMETHEUS_RUN_BUCKET_INTERVALS" + prometheusQueueBucketIntervalsName = "PROMETHEUS_QUEUE_BUCKET_INTERVALS" ) func init() { @@ -76,7 +77,8 @@ func main() { ghClient *github.Client // List of histogram buckets that we want to see in metrics - bucketsList actionsmetrics.BucketsSlice + runBucketsList actionsmetrics.BucketsSlice + queueBucketsList actionsmetrics.BucketsSlice ) var c github.Config @@ -87,7 +89,8 @@ func main() { } webhookSecretTokenEnv = os.Getenv(webhookSecretTokenEnvName) - bucketsList.Set(os.Getenv(prometheusBucketIntervalsName)) + runBucketsList.Set(os.Getenv(prometheusRunBucketIntervalsName)) + queueBucketsList.Set(os.Getenv(prometheusQueueBucketIntervalsName)) flag.StringVar(&webhookAddr, "webhook-addr", ":8000", "The address the metric endpoint binds to.") flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") @@ -118,7 +121,7 @@ func main() { webhookSecretToken = webhookSecretTokenEnv } - actionsmetrics.InitializeMetrics(bucketsList) + actionsmetrics.InitializeMetrics(runBucketsList, queueBucketsList) if webhookSecretToken == "" { logger.Info(fmt.Sprintf("-github-webhook-secret-token and %s are missing or empty. Create one following https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks and specify it via the flag or the envvar", webhookSecretTokenEnvName)) diff --git a/pkg/actionsmetrics/metrics.go b/pkg/actionsmetrics/metrics.go index 8f9e3c0ae7..77f4744e52 100644 --- a/pkg/actionsmetrics/metrics.go +++ b/pkg/actionsmetrics/metrics.go @@ -34,14 +34,16 @@ func (i *BucketsSlice) Set(value string) error { var githubWorkflowJobQueueHistogram *prometheus.HistogramVec var githubWorkflowJobRunHistogram *prometheus.HistogramVec -func initMetrics(buckets []float64) { - if len(buckets) > 0 { - githubWorkflowJobQueueHistogram = githubWorkflowJobQueueDurationSeconds(buckets) - githubWorkflowJobRunHistogram = githubWorkflowJobRunDurationSeconds(buckets) - } else { - githubWorkflowJobQueueHistogram = githubWorkflowJobQueueDurationSeconds(DefaultRuntimeBuckets) +func initMetrics(runBuckets, queueBuckets []float64) { + githubWorkflowJobRunHistogram = githubWorkflowJobRunDurationSeconds(runBuckets) + githubWorkflowJobQueueHistogram = githubWorkflowJobQueueDurationSeconds(queueBuckets) + + if len(runBuckets) == 0 { githubWorkflowJobRunHistogram = githubWorkflowJobRunDurationSeconds(DefaultRuntimeBuckets) } + if len(queueBuckets) == 0 { + githubWorkflowJobQueueHistogram = githubWorkflowJobQueueDurationSeconds(DefaultRuntimeBuckets) + } metrics.Registry.MustRegister( githubWorkflowJobQueueHistogram, githubWorkflowJobRunHistogram, @@ -75,8 +77,8 @@ func githubWorkflowJobRunDurationSeconds(buckets []float64) *prometheus.Histogra ) } -func InitializeMetrics(buckets []float64) { - initMetrics(buckets) +func InitializeMetrics(runBuckets, queueBuckets []float64) { + initMetrics(runBuckets, queueBuckets) } var (