Skip to content

Fix inconsistent guards for scale set metrics registration and publishing#4566

Open
Okabe-Junya wants to merge 1 commit into
actions:masterfrom
Okabe-Junya:Okabe-Junya/fix/metrics-register-publish-guard
Open

Fix inconsistent guards for scale set metrics registration and publishing#4566
Okabe-Junya wants to merge 1 commit into
actions:masterfrom
Okabe-Junya:Okabe-Junya/fix/metrics-register-publish-guard

Conversation

@Okabe-Junya

@Okabe-Junya Okabe-Junya commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

What

Introduce a single metricsEnabled condition (metricsAddr != "" && metricsAddr != "0") and use it for both:

  • actionsgithubcommetrics.RegisterMetrics() (previously guarded by metricsAddr != "")
  • EphemeralRunnerSetReconciler.PublishMetrics (previously metricsAddr != "0")

Why

Registration was guarded by metricsAddr != "" while publishing was guarded by metricsAddr != "0", so the two could disagree.

controller-runtime treats "0" - not "" - as the token to disable its metrics server.
Options.BindAddress documents "Set this to 0 to disable the metrics server", and NewServer returns nil when BindAddress == "0". FYI:

https://github.com/kubernetes-sigs/controller-runtime/blob/3be3f1bf2b2fcc6b5c9510d55c6a9972294653d0/pkg/metrics/server/server.go#L119-L122

The Helm chart accordingly passes --metrics-addr=0 when metrics are disabled.

With metricsAddr="", the old guards skipped registration but still published: the reconciler keeps calling WithLabelValues().Set() on an unregistered GaugeVec, accumulating per-label child metrics in memory until restart while nothing is ever scraped.

Aligning both guards on one metricsEnabled condition treats "" and "0" consistently as "metrics disabled"

@Okabe-Junya Okabe-Junya marked this pull request as ready for review July 12, 2026 15:37
Copilot AI review requested due to automatic review settings July 12, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes how the controller decides whether scale set metrics are enabled by introducing a single metricsEnabled boolean derived from metricsAddr, and reusing it consistently for both metrics registration and metrics publishing.

Changes:

  • Add a shared metricsEnabled := metricsAddr != "" && metricsAddr != "0" condition to represent “metrics enabled”.
  • Guard actionsgithubcommetrics.RegisterMetrics() and EphemeralRunnerSetReconciler.PublishMetrics with the same condition to avoid inconsistent behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants