-
Notifications
You must be signed in to change notification settings - Fork 937
feat: add prometheus metrics to database.Store #7713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6c73f9d
c0ea9ef
b153939
6b867c6
5385657
d3cf018
0ecd6aa
b846d0b
0b9e836
9aee243
9367f6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ 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/dbtype" | ||
"github.com/coder/coder/coderd/gitauth" | ||
"github.com/coder/coder/coderd/gitsshkey" | ||
|
@@ -176,6 +177,11 @@ func New(options *Options) *API { | |
options = &Options{} | ||
} | ||
|
||
// Safety check: if we're not running a unit test, we *must* have a Prometheus registry. | ||
if options.PrometheusRegistry == nil && flag.Lookup("test.v") == nil { | ||
panic("developer error: options.PrometheusRegistry is nil and not running a unit test") | ||
} | ||
|
||
Comment on lines
+180
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: I'm open to removing this, but I think it's a good check to have. We don't want to accidentally publish a release with no prometheus metrics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we always do this? Seems wasteful if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we do. It is a little wasteful, but less error-prone than having to check if the prometheus registerer is nil everywhere. |
||
if options.DeploymentValues.DisableOwnerWorkspaceExec { | ||
rbac.ReloadBuiltinRoles(&rbac.RoleOptions{ | ||
NoOwnerWorkspaceExec: true, | ||
|
@@ -185,6 +191,10 @@ 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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/google/uuid" | ||
"github.com/open-policy-agent/opa/topdown" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -19,14 +20,16 @@ import ( | |
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/coderd/database/dbauthz" | ||
"github.com/coder/coder/coderd/database/dbfake" | ||
"github.com/coder/coder/coderd/database/dbmock" | ||
"github.com/coder/coder/coderd/rbac" | ||
"github.com/coder/coder/coderd/rbac/regosql" | ||
"github.com/coder/coder/coderd/util/slice" | ||
) | ||
|
||
var skipMethods = map[string]string{ | ||
"InTx": "Not relevant", | ||
"Ping": "Not relevant", | ||
"InTx": "Not relevant", | ||
"Ping": "Not relevant", | ||
"Wrappers": "Not relevant", | ||
} | ||
|
||
// TestMethodTestSuite runs MethodTestSuite. | ||
|
@@ -52,7 +55,11 @@ type MethodTestSuite struct { | |
// SetupSuite sets up the suite by creating a map of all methods on querier | ||
// and setting their count to 0. | ||
func (s *MethodTestSuite) SetupSuite() { | ||
az := dbauthz.New(nil, nil, slog.Make()) | ||
ctrl := gomock.NewController(s.T()) | ||
mockStore := dbmock.NewMockStore(ctrl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Emyrk I think it makes sense to use the mock here instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would just panic if the db is set to nil, which would tell us a call was made. Does the mock panic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see though, for the wrappers method. |
||
// We intentionally set no expectations apart from this. | ||
mockStore.EXPECT().Wrappers().Return([]string{}).AnyTimes() | ||
az := dbauthz.New(mockStore, nil, slog.Make()) | ||
// Take the underlying type of the interface. | ||
azt := reflect.TypeOf(az).Elem() | ||
s.methodAccounting = make(map[string]int) | ||
|
Uh oh!
There was an error while loading. Please reload this page.