Skip to content

Commit 8dd567d

Browse files
authored
fix: use prometheus default registry (#4907)
1 parent dad8945 commit 8dd567d

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

cli/server.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,23 +505,21 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
505505
defer serveHandler(ctx, logger, nil, cfg.Pprof.Address.Value, "pprof")()
506506
}
507507
if cfg.Prometheus.Enable.Value {
508-
options.PrometheusRegistry = prometheus.NewRegistry()
509-
closeUsersFunc, err := prometheusmetrics.ActiveUsers(ctx, options.PrometheusRegistry, options.Database, 0)
508+
options.PrometheusRegisterer = prometheus.DefaultRegisterer
509+
closeUsersFunc, err := prometheusmetrics.ActiveUsers(ctx, options.PrometheusRegisterer, options.Database, 0)
510510
if err != nil {
511511
return xerrors.Errorf("register active users prometheus metric: %w", err)
512512
}
513513
defer closeUsersFunc()
514514

515-
closeWorkspacesFunc, err := prometheusmetrics.Workspaces(ctx, options.PrometheusRegistry, options.Database, 0)
515+
closeWorkspacesFunc, err := prometheusmetrics.Workspaces(ctx, options.PrometheusRegisterer, options.Database, 0)
516516
if err != nil {
517517
return xerrors.Errorf("register workspaces prometheus metric: %w", err)
518518
}
519519
defer closeWorkspacesFunc()
520520

521521
//nolint:revive
522-
defer serveHandler(ctx, logger, promhttp.InstrumentMetricHandler(
523-
options.PrometheusRegistry, promhttp.HandlerFor(options.PrometheusRegistry, promhttp.HandlerOpts{}),
524-
), cfg.Prometheus.Address.Value, "prometheus")()
522+
defer serveHandler(ctx, logger, promhttp.Handler(), cfg.Prometheus.Address.Value, "prometheus")()
525523
}
526524

527525
// We use a separate coderAPICloser so the Enterprise API

coderd/coderd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ type Options struct {
7878
GoogleTokenValidator *idtoken.Validator
7979
GithubOAuth2Config *GithubOAuth2Config
8080
OIDCConfig *OIDCConfig
81-
PrometheusRegistry *prometheus.Registry
81+
PrometheusRegisterer prometheus.Registerer
8282
SecureAuthCookie bool
8383
SSHKeygenAlgorithm gitsshkey.Algorithm
8484
Telemetry telemetry.Reporter
@@ -132,8 +132,8 @@ func New(options *Options) *API {
132132
if options.Authorizer == nil {
133133
options.Authorizer = rbac.NewAuthorizer()
134134
}
135-
if options.PrometheusRegistry == nil {
136-
options.PrometheusRegistry = prometheus.NewRegistry()
135+
if options.PrometheusRegisterer == nil {
136+
options.PrometheusRegisterer = prometheus.NewRegistry()
137137
}
138138
if options.TailnetCoordinator == nil {
139139
options.TailnetCoordinator = tailnet.NewCoordinator()
@@ -204,7 +204,7 @@ func New(options *Options) *API {
204204
httpmw.Recover(api.Logger),
205205
httpmw.ExtractRealIP(api.RealIPConfig),
206206
httpmw.Logger(api.Logger),
207-
httpmw.Prometheus(options.PrometheusRegistry),
207+
httpmw.Prometheus(options.PrometheusRegisterer),
208208
// handleSubdomainApplications checks if the first subdomain is a valid
209209
// app URL. If it is, it will serve that application.
210210
api.handleSubdomainApplications(

0 commit comments

Comments
 (0)