Skip to content

Commit

Permalink
add ability to override separate queue and run buckets for histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillbilchenko authored and sindunuragarp committed Nov 13, 2023
1 parent 2574214 commit 3219cfe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
13 changes: 8 additions & 5 deletions cmd/actionsmetricsserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -87,7 +89,8 @@ func main() {
}

webhookSecretTokenEnv = os.Getenv(webhookSecretTokenEnvName)
bucketsList.Set(os.Getenv(prometheusBucketIntervalsName))
runBucketsList.Set(os.Getenv(prometheusRunBucketIntervalsName))

Check failure on line 92 in cmd/actionsmetricsserver/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `runBucketsList.Set` is not checked (errcheck)
queueBucketsList.Set(os.Getenv(prometheusQueueBucketIntervalsName))

Check failure on line 93 in cmd/actionsmetricsserver/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `queueBucketsList.Set` is not checked (errcheck)

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.")
Expand Down Expand Up @@ -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))
Expand Down
18 changes: 10 additions & 8 deletions pkg/actionsmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 3219cfe

Please sign in to comment.