Do not register the build_info collectors multiple times. (#2014)

Since we call base.NewServer multiple times when building the Commands map this was returning
an error "duplicate metrics collector registration attempted".  This PR only creates a single
server which is used for both the "server" command as well as "dev".
This commit is contained in:
Todd authored and GitHub committed 2022-04-15 09:30:23 -07:00
1 parent 4636efce8f
commit 0b12feb953
2 files changed
+8 -10

No files matched your search

+3 -5
View File
@@ -134,12 +134,10 @@ type Server struct {
StatusGracePeriodDuration time.Duration
}
// The only option used here is WithPrometheusRegisterer; all others are ignored.
// NewServer creates a new Server.
// The WithPrometheusRegisterer Option uses the passed in registry to initialize
// the build info collectors. All other Options are ignored.
func NewServer(cmd *Command, opt ...Option) *Server {
// Create a new prometheus registry here to avoid "duplicate metrics collector
// registration" panics in tests where new servers are called consecutively.
// prometheus.DefaultRegisterer and prometheus.DefaultGatherer vars need to be
// assigned for promhttp package to work correctly.
opts := getOpts(opt...)
metric.InitializeBuildInfo(opts.withPrometheusRegisterer)