fix: only collect prometheus database metrics when explicitly enabled (#8045)

* fix: only collect prometheus database metrics when explicitly enabled

* add missing test

* de-duplicate wrapping
This commit is contained in:
Cian Johnston
2023-06-15 04:34:16 -07:00
committed by GitHub
parent 3f81f38fcc
commit 6e598234b6
14 changed files with 158 additions and 58 deletions

3
coderd/apidoc/docs.go generated
View File

@ -7880,6 +7880,9 @@ const docTemplate = `{
"collect_agent_stats": {
"type": "boolean"
},
"collect_db_metrics": {
"type": "boolean"
},
"enable": {
"type": "boolean"
}

View File

@ -7061,6 +7061,9 @@
"collect_agent_stats": {
"type": "boolean"
},
"collect_db_metrics": {
"type": "boolean"
},
"enable": {
"type": "boolean"
}

View File

@ -47,7 +47,6 @@ import (
"github.com/coder/coder/coderd/awsidentity"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbauthz"
"github.com/coder/coder/coderd/database/dbmetrics"
"github.com/coder/coder/coderd/database/pubsub"
"github.com/coder/coder/coderd/gitauth"
"github.com/coder/coder/coderd/gitsshkey"
@ -191,10 +190,6 @@ func New(options *Options) *API {
if options.Authorizer == nil {
options.Authorizer = rbac.NewCachingAuthorizer(options.PrometheusRegistry)
}
// The below are no-ops if already wrapped.
if options.PrometheusRegistry != nil {
options.Database = dbmetrics.New(options.Database, options.PrometheusRegistry)
}
options.Database = dbauthz.New(
options.Database,
options.Authorizer,