[MM-46694] A/B Test: welcome post (#20926)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Julien Tant
2022-10-13 14:23:22 -07:00
коммит произвёл GitHub
родитель a6a44b5824
Коммит 3747d99806
14 изменённых файлов: 230 добавлений и 0 удалений

Просмотреть файл

@@ -10801,6 +10801,24 @@ func (s *OpenTracingLayerUserStore) GetEtagForProfilesNotInTeam(teamID string) s
return result
}
func (s *OpenTracingLayerUserStore) GetFirstSystemAdminID() (string, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "UserStore.GetFirstSystemAdminID")
s.Root.Store.SetContext(newCtx)
defer func() {
s.Root.Store.SetContext(origCtx)
}()
defer span.Finish()
result, err := s.UserStore.GetFirstSystemAdminID()
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
}
return result, err
}
func (s *OpenTracingLayerUserStore) GetForLogin(loginID string, allowSignInWithUsername bool, allowSignInWithEmail bool) (*model.User, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "UserStore.GetForLogin")

Просмотреть файл

@@ -12324,6 +12324,27 @@ func (s *RetryLayerUserStore) GetEtagForProfilesNotInTeam(teamID string) string
}
func (s *RetryLayerUserStore) GetFirstSystemAdminID() (string, error) {
tries := 0
for {
result, err := s.UserStore.GetFirstSystemAdminID()
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
timepkg.Sleep(100 * timepkg.Millisecond)
}
}
func (s *RetryLayerUserStore) GetForLogin(loginID string, allowSignInWithUsername bool, allowSignInWithEmail bool) (*model.User, error) {
tries := 0

Просмотреть файл

@@ -1748,6 +1748,16 @@ func (us SqlUserStore) InferSystemInstallDate() (int64, error) {
return createAt, nil
}
func (us SqlUserStore) GetFirstSystemAdminID() (string, error) {
var id string
err := us.GetReplicaX().Get(&id, "SELECT Id FROM Users WHERE Roles LIKE ? ORDER BY CreateAt ASC LIMIT 1", "%system_admin%")
if err != nil {
return "", errors.Wrap(err, "failed to get first system admin")
}
return id, nil
}
func (us SqlUserStore) GetUsersBatchForIndexing(startTime int64, startFileID string, limit int) ([]*model.UserForIndexing, error) {
users := []*model.User{}
usersQuery, args, err := us.usersQuery.

Просмотреть файл

@@ -481,6 +481,7 @@ type UserStore interface {
IsEmpty(excludeBots bool) (bool, error)
GetUsersWithInvalidEmails(page int, perPage int, restrictedDomains string) ([]*model.User, error)
InsertUsers(users []*model.User) error
GetFirstSystemAdminID() (string, error)
}
type BotStore interface {

Просмотреть файл

@@ -569,6 +569,27 @@ func (_m *UserStore) GetEtagForProfilesNotInTeam(teamID string) string {
return r0
}
// GetFirstSystemAdminID provides a mock function with given fields:
func (_m *UserStore) GetFirstSystemAdminID() (string, error) {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
var r1 error
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetForLogin provides a mock function with given fields: loginID, allowSignInWithUsername, allowSignInWithEmail
func (_m *UserStore) GetForLogin(loginID string, allowSignInWithUsername bool, allowSignInWithEmail bool) (*model.User, error) {
ret := _m.Called(loginID, allowSignInWithUsername, allowSignInWithEmail)

Просмотреть файл

@@ -94,6 +94,7 @@ func TestUserStore(t *testing.T, ss store.Store, s SqlStore) {
t.Run("ResetLastPictureUpdate", func(t *testing.T) { testUserStoreResetLastPictureUpdate(t, ss) })
t.Run("GetKnownUsers", func(t *testing.T) { testGetKnownUsers(t, ss) })
t.Run("GetUsersWithInvalidEmails", func(t *testing.T) { testGetUsersWithInvalidEmails(t, ss) })
t.Run("GetFirstSystemAdminID", func(t *testing.T) { testUserStoreGetFirstSystemAdminID(t, ss) })
}
func testUserStoreSave(t *testing.T, ss store.Store) {
@@ -4163,6 +4164,30 @@ func testCount(t *testing.T, ss store.Store) {
}
}
func testUserStoreGetFirstSystemAdminID(t *testing.T, ss store.Store) {
sysAdmin := &model.User{}
sysAdmin.Email = MakeEmail()
sysAdmin.Roles = model.SystemAdminRoleId + " " + model.SystemUserRoleId
sysAdmin, err := ss.User().Save(sysAdmin)
require.NoError(t, err)
defer func() { require.NoError(t, ss.User().PermanentDelete(sysAdmin.Id)) }()
// We need the second system admin to be created after the first one
// our granulirity is ms
time.Sleep(1 * time.Millisecond)
sysAdmin2 := &model.User{}
sysAdmin2.Email = MakeEmail()
sysAdmin2.Roles = model.SystemAdminRoleId + " " + model.SystemUserRoleId
sysAdmin2, err = ss.User().Save(sysAdmin2)
require.NoError(t, err)
defer func() { require.NoError(t, ss.User().PermanentDelete(sysAdmin2.Id)) }()
returnedId, err := ss.User().GetFirstSystemAdminID()
require.NoError(t, err)
require.Equal(t, sysAdmin.Id, returnedId)
}
func testUserStoreAnalyticsActiveCount(t *testing.T, ss store.Store, s SqlStore) {
cleanupStatusStore(t, s)

Просмотреть файл

@@ -9727,6 +9727,22 @@ func (s *TimerLayerUserStore) GetEtagForProfilesNotInTeam(teamID string) string
return result
}
func (s *TimerLayerUserStore) GetFirstSystemAdminID() (string, error) {
start := time.Now()
result, err := s.UserStore.GetFirstSystemAdminID()
elapsed := float64(time.Since(start)) / float64(time.Second)
if s.Root.Metrics != nil {
success := "false"
if err == nil {
success = "true"
}
s.Root.Metrics.ObserveStoreMethodDuration("UserStore.GetFirstSystemAdminID", success, elapsed)
}
return result, err
}
func (s *TimerLayerUserStore) GetForLogin(loginID string, allowSignInWithUsername bool, allowSignInWithEmail bool) (*model.User, error) {
start := time.Now()