diff --git a/AGENTS.md b/AGENTS.md index b325b8ff4fe..83762df84c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,3 +16,4 @@ When creating a pull request, follow `.github/PULL_REQUEST_TEMPLATE.md` exactly: This repository has a checked-in Cloud Agent environment under `.cursor/`. Docker is started by `.cursor/scripts/cloud-agent-start.sh`; if Docker is unavailable in Cloud, treat that as an environment failure rather than falling back to snapshot assumptions. The environment declares `mattermost/enterprise` as a Cursor multi-repo dependency. Cursor clones the repositories as siblings, so `server/Makefile` can use its default `../../enterprise` path; the install hook does not clone or symlink enterprise. + diff --git a/server/AGENTS.md b/server/AGENTS.md index fbaf80788e7..9e51dfa9060 100644 --- a/server/AGENTS.md +++ b/server/AGENTS.md @@ -3,3 +3,5 @@ Never run `go mod tidy` directly. Always run `make modules-tidy` instead — it excludes private enterprise imports that would otherwise break the tidy. After editing `i18n/en.json`, always run `make i18n-extract` — it regenerates the file with strings in the required order. + +In the store layer, do not use `context.Context` in store method signatures. Use `request.CTX` and only call `rctx.Context()` inside internals that require a standard `context.Context`. diff --git a/server/channels/app/platform/support_packet.go b/server/channels/app/platform/support_packet.go index dd2f23e13bd..9925b3493a1 100644 --- a/server/channels/app/platform/support_packet.go +++ b/server/channels/app/platform/support_packet.go @@ -221,7 +221,7 @@ func (ps *PlatformService) getSupportPacketDiagnostics(rctx request.CTX) (*model d.Database.ReplicaConnections = ps.Store.TotalReadDbConnections() d.Database.SearchConnections = ps.Store.TotalSearchDbConnections() - err = ps.applyStoreDiagnostics(rctx.Context(), &d) + err = ps.applyStoreDiagnostics(rctx, &d) if err != nil { rErr = multierror.Append(rErr, err) } @@ -389,8 +389,8 @@ func (ps *PlatformService) getSupportPacketDiagnostics(rctx request.CTX) (*model return fileData, rErr.ErrorOrNil() } -func (ps *PlatformService) applyStoreDiagnostics(ctx context.Context, diagnostics *model.SupportPacketDiagnostics) error { - storeDiagnostics, err := ps.Store.GetDiagnostics(ctx) +func (ps *PlatformService) applyStoreDiagnostics(rctx request.CTX, diagnostics *model.SupportPacketDiagnostics) error { + storeDiagnostics, err := ps.Store.GetDiagnostics(rctx) if storeDiagnostics == nil { if err != nil { return errors.Wrap(err, "error while collecting support packet database diagnostics") diff --git a/server/channels/app/platform/support_packet_test.go b/server/channels/app/platform/support_packet_test.go index 3116bb7431f..7953cd1a911 100644 --- a/server/channels/app/platform/support_packet_test.go +++ b/server/channels/app/platform/support_packet_test.go @@ -6,7 +6,6 @@ package platform import ( "bufio" "bytes" - "context" "database/sql" "encoding/json" "errors" @@ -28,6 +27,7 @@ import ( "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/shared/mlog" + "github.com/mattermost/mattermost/server/public/shared/request" "github.com/mattermost/mattermost/server/v8/channels/store" "github.com/mattermost/mattermost/server/v8/channels/testlib" "github.com/mattermost/mattermost/server/v8/config" @@ -42,7 +42,7 @@ type fixedDBStatsStore struct { replicaStats sql.DBStats } -func (s *fixedDBStatsStore) GetDiagnostics(_ context.Context) (*store.DatabaseDiagnostics, error) { +func (s *fixedDBStatsStore) GetDiagnostics(_ request.CTX) (*store.DatabaseDiagnostics, error) { diagnostics := &store.DatabaseDiagnostics{ MasterConnectionsInUse: s.masterStats.InUse, MasterConnectionsIdle: s.masterStats.Idle, diff --git a/server/channels/store/sqlstore/diagnostics.go b/server/channels/store/sqlstore/diagnostics.go index e6ef19d0242..009fae79635 100644 --- a/server/channels/store/sqlstore/diagnostics.go +++ b/server/channels/store/sqlstore/diagnostics.go @@ -13,12 +13,13 @@ import ( "github.com/pkg/errors" "github.com/mattermost/mattermost/server/public/model" + "github.com/mattermost/mattermost/server/public/shared/request" "github.com/mattermost/mattermost/server/v8/channels/store" ) const pgDiagnosticsQueryTimeout = 10 * time.Second -func (ss *SqlStore) GetDiagnostics(ctx context.Context) (*store.DatabaseDiagnostics, error) { +func (ss *SqlStore) GetDiagnostics(rctx request.CTX) (*store.DatabaseDiagnostics, error) { diagnostics := &store.DatabaseDiagnostics{} applyDBPoolStats(diagnostics, ss.MasterDBStats(), ss.ReplicaDBStats()) @@ -26,7 +27,7 @@ func (ss *SqlStore) GetDiagnostics(ctx context.Context) (*store.DatabaseDiagnost return diagnostics, nil } - if err := collectPostgresDatabaseDiagnostics(ctx, ss.GetMaster().DB(), diagnostics); err != nil { + if err := collectPostgresDatabaseDiagnostics(rctx.Context(), ss.GetMaster().DB(), diagnostics); err != nil { return diagnostics, err } diff --git a/server/channels/store/sqlstore/diagnostics_test.go b/server/channels/store/sqlstore/diagnostics_test.go index e66781f6611..278a3a875ac 100644 --- a/server/channels/store/sqlstore/diagnostics_test.go +++ b/server/channels/store/sqlstore/diagnostics_test.go @@ -4,7 +4,6 @@ package sqlstore import ( - "context" "database/sql" "testing" "time" @@ -18,10 +17,10 @@ import ( ) func TestGetDiagnostics(t *testing.T) { - StoreTest(t, func(t *testing.T, _ request.CTX, ss store.Store) { + StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) { sqlStore := ss.(*SqlStore) - diagnostics, err := sqlStore.GetDiagnostics(context.Background()) + diagnostics, err := sqlStore.GetDiagnostics(rctx) require.NoError(t, err) require.NotNil(t, diagnostics) diff --git a/server/channels/store/store.go b/server/channels/store/store.go index cfa764ee384..f1b5de3d9f1 100644 --- a/server/channels/store/store.go +++ b/server/channels/store/store.go @@ -80,7 +80,7 @@ type Store interface { TotalMasterDbConnections() int TotalReadDbConnections() int TotalSearchDbConnections() int - GetDiagnostics(ctx context.Context) (*DatabaseDiagnostics, error) + GetDiagnostics(rctx request.CTX) (*DatabaseDiagnostics, error) ReplicaLagTime() error ReplicaLagAbs() error CheckIntegrity() <-chan model.IntegrityCheckResult diff --git a/server/channels/store/storetest/mocks/Store.go b/server/channels/store/storetest/mocks/Store.go index 4a68ee640b9..8bbd08efec5 100644 --- a/server/channels/store/storetest/mocks/Store.go +++ b/server/channels/store/storetest/mocks/Store.go @@ -5,12 +5,12 @@ package mocks import ( - context "context" sql "database/sql" time "time" model "github.com/mattermost/mattermost/server/public/model" mlog "github.com/mattermost/mattermost/server/public/shared/mlog" + request "github.com/mattermost/mattermost/server/public/shared/request" store "github.com/mattermost/mattermost/server/v8/channels/store" mock "github.com/stretchr/testify/mock" ) @@ -516,9 +516,9 @@ func (_m *Store) GetDbVersion(numerical bool) (string, error) { return r0, r1 } -// GetDiagnostics provides a mock function with given fields: ctx -func (_m *Store) GetDiagnostics(ctx context.Context) (*store.DatabaseDiagnostics, error) { - ret := _m.Called(ctx) +// GetDiagnostics provides a mock function with given fields: rctx +func (_m *Store) GetDiagnostics(rctx request.CTX) (*store.DatabaseDiagnostics, error) { + ret := _m.Called(rctx) if len(ret) == 0 { panic("no return value specified for GetDiagnostics") @@ -526,19 +526,19 @@ func (_m *Store) GetDiagnostics(ctx context.Context) (*store.DatabaseDiagnostics var r0 *store.DatabaseDiagnostics var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*store.DatabaseDiagnostics, error)); ok { - return rf(ctx) + if rf, ok := ret.Get(0).(func(request.CTX) (*store.DatabaseDiagnostics, error)); ok { + return rf(rctx) } - if rf, ok := ret.Get(0).(func(context.Context) *store.DatabaseDiagnostics); ok { - r0 = rf(ctx) + if rf, ok := ret.Get(0).(func(request.CTX) *store.DatabaseDiagnostics); ok { + r0 = rf(rctx) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*store.DatabaseDiagnostics) } } - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) + if rf, ok := ret.Get(1).(func(request.CTX) error); ok { + r1 = rf(rctx) } else { r1 = ret.Error(1) } diff --git a/server/channels/store/storetest/store.go b/server/channels/store/storetest/store.go index dbc4f5cfd9e..4c83eb47948 100644 --- a/server/channels/store/storetest/store.go +++ b/server/channels/store/storetest/store.go @@ -4,7 +4,6 @@ package storetest import ( - "context" "database/sql" "time" @@ -12,6 +11,7 @@ import ( "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/shared/mlog" + "github.com/mattermost/mattermost/server/public/shared/request" "github.com/mattermost/mattermost/server/v8/channels/store" "github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks" ) @@ -204,7 +204,7 @@ func (s *Store) GetSchemaDefinition() (*model.SupportPacketDatabaseSchema, error }, nil } -func (s *Store) GetDiagnostics(_ context.Context) (*store.DatabaseDiagnostics, error) { +func (s *Store) GetDiagnostics(_ request.CTX) (*store.DatabaseDiagnostics, error) { return &store.DatabaseDiagnostics{}, nil }