Skip to content

Avoid nil point when config.Metrics is nil and expose all metrics if none are configured #4101

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

Merged
merged 4 commits into from
Jun 11, 2025

Conversation

TingluoHuang
Copy link
Member

@TingluoHuang TingluoHuang commented May 23, 2025

When metrics are configured on the controller, but no metrics are applied to the scale set, the listener would panic with nil dereference error.

This change applies all metrics by default if metrics are configured, but no customisation is being done.

To avoid server errors in the future, defaults are applied to the server address and the default endpoint. This code path should not be hit by default, since the app.go decides if it should apply metrics based on the server address. But it made sense to use the default :8080 port and /metrics endpoint in the default function to future-proof the code.

Fixes #3993

@Copilot Copilot AI review requested due to automatic review settings May 23, 2025 17:56
Copy link
Contributor

@Copilot Copilot AI left a comment

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 prevents a nil pointer dereference when config.Metrics is nil by separating the exporter configuration creation and only assigning Metrics when it’s non-nil.

  • Extracted metrics.ExporterConfig into a local variable.
  • Added a nil check around config.Metrics before assignment.
  • Moved NewExporter call to use the pre-built config.

@nikola-jokic nikola-jokic changed the title Avoid nil point when config.Metrics is nil. Avoid nil point when config.Metrics is nil and expose all metrics if none are configured Jun 3, 2025
@nikola-jokic nikola-jokic requested a review from Link- June 3, 2025 12:55
@nikola-jokic nikola-jokic added the gha-runner-scale-set Related to the gha-runner-scale-set mode label Jun 4, 2025
@nikola-jokic nikola-jokic requested a review from Link- June 4, 2025 09:26
@nikola-jokic nikola-jokic merged commit c359d14 into master Jun 11, 2025
15 checks passed
@nikola-jokic nikola-jokic deleted the users/tihuang/fixnullref branch June 11, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gha-runner-scale-set Related to the gha-runner-scale-set mode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SIGSEGV after update to 0.11.0 on listener
4 participants