fix: use safe prometheus.Register instead of MustRegister in main#522
Merged
fix: use safe prometheus.Register instead of MustRegister in main#522
Conversation
prometheus.MustRegister panics if the same collector is registered more than once in the same process (e.g. in tests, or if main were ever invoked multiple times). Replace with prometheus.Register and silently accept AlreadyRegisteredError while still fatally exiting on any other registration failure. No behavior change in normal production operation where registration only happens once. Signed-off-by: Todd Ekenstam <todd_ekenstam@intuit.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #522 +/- ##
=======================================
Coverage 46.89% 46.89%
=======================================
Files 40 40
Lines 5879 5879
=======================================
Hits 2757 2757
Misses 2964 2964
Partials 158 158 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
kevdowney
approved these changes
Mar 23, 2026
Contributor
|
The lint check is failing due to it requires go |
ZihanJiang96
approved these changes
Mar 23, 2026
added 2 commits
March 22, 2026 20:58
golangci-lint v2.1.1 is compiled with Go 1.24 and panics when analyzing files that require Go 1.26. Pinning to 1.24 matches go.mod and avoids the incompatibility with `stable` resolving to 1.26.1. Signed-off-by: Todd Ekenstam <todd_ekenstam@intuit.com>
The entire codebase uses aws-sdk-go v1 which is now deprecated upstream. Suppress the staticcheck SA1019 warnings until the migration tracked in #523 is complete. Signed-off-by: Todd Ekenstam <todd_ekenstam@intuit.com>
tekenstam
pushed a commit
that referenced
this pull request
Mar 23, 2026
Resolves conflict in .github/workflows/golangci-lint.yml by keeping GO_VERSION: stable and GOLANGCI_LINT_VERSION: v2.11.4 from PR branch (required for Go 1.26 support). Includes safe prometheus.Register fix from master (PR #522) and SA1019 suppression rule. Signed-off-by: Tomas Ekenstam <tekenstam@gmail.com> Signed-off-by: Todd Ekenstam <todd_ekenstam@intuit.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prometheus.MustRegister(cacheCollector, controllerCollector)inmain.gowith individualprometheus.Register(...)calls that handleAlreadyRegisteredErrorgracefullyWhy
prometheus.MustRegisterpanics if the same collector is registered more than once in the same process. Whilemain()is only called once in normal operation, this pattern is fragile:main()or triggers metric registration, it will panic on the second runFound during a cross-repo audit after fixing a similar issue in
lifecycle-manager(whereprometheus.MustRegisterin a method called directly from tests was causingEOFerrors inTest_Metrics).Change
No behavior change in production — the first registration always succeeds and the
AlreadyRegisteredErrorbranch is never taken. Any other registration error still causes a fatal exit.Test plan
go build ./...— compiles cleanlygo test $(go list ./... | grep -v test-bdd)— all unit tests pass🤖 Generated with Claude Code