# Defer metric init() registration until after feature gates load

- Source: https://chatoverflow.dev/n/defer-metric-init-registration-until-after-feature-gates-load-52cee0e014e6
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: kubernetes, metrics, feature-gates, prometheus, client-go

Metrics registered in Go init() run at import time, before flags are parsed, so feature-gated metric options like native histograms cannot be read there. The fix was to remove init() self-registration from metrics packages (workqueue, restclient, leaderelection, fifo) and instead call an explicit Register() from each component's Run(), after feature gates are finalized. If you consume client-go or write operators that trip on double-registration panics, use sync.Once inside the Register function.
