MM-43082: Added new telemetry values for groups. (#19918)

Этот коммит содержится в:
mkraft
2022-04-08 11:25:40 -04:00
коммит произвёл GitHub
родитель 1418828443
Коммит 0e4b0b6939
8 изменённых файлов: 96 добавлений и 0 удалений

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

@@ -4213,6 +4213,24 @@ func (s *OpenTracingLayerGroupStore) GroupCount() (int64, error) {
return result, err
}
func (s *OpenTracingLayerGroupStore) GroupCountBySource(source model.GroupSource) (int64, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupCountBySource")
s.Root.Store.SetContext(newCtx)
defer func() {
s.Root.Store.SetContext(origCtx)
}()
defer span.Finish()
result, err := s.GroupStore.GroupCountBySource(source)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
}
return result, err
}
func (s *OpenTracingLayerGroupStore) GroupCountWithAllowReference() (int64, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GroupCountWithAllowReference")

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

@@ -4750,6 +4750,27 @@ func (s *RetryLayerGroupStore) GroupCount() (int64, error) {
}
func (s *RetryLayerGroupStore) GroupCountBySource(source model.GroupSource) (int64, error) {
tries := 0
for {
result, err := s.GroupStore.GroupCountBySource(source)
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 *RetryLayerGroupStore) GroupCountWithAllowReference() (int64, error) {
tries := 0

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

@@ -1720,6 +1720,10 @@ func (s *SqlGroupStore) GroupCount() (int64, error) {
return s.countTable("UserGroups")
}
func (s *SqlGroupStore) GroupCountBySource(source model.GroupSource) (int64, error) {
return s.countTableWithSelectAndWhere("COUNT(*)", "UserGroups", sq.Eq{"Source": source, "DeleteAt": 0})
}
func (s *SqlGroupStore) GroupTeamCount() (int64, error) {
return s.countTable("GroupTeams")
}

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

@@ -853,6 +853,8 @@ type GroupStore interface {
// GroupCount returns the total count of records in the UserGroups table.
GroupCount() (int64, error)
GroupCountBySource(source model.GroupSource) (int64, error)
// GroupTeamCount returns the total count of records in the GroupTeams table.
GroupTeamCount() (int64, error)

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

@@ -849,6 +849,27 @@ func (_m *GroupStore) GroupCount() (int64, error) {
return r0, r1
}
// GroupCountBySource provides a mock function with given fields: source
func (_m *GroupStore) GroupCountBySource(source model.GroupSource) (int64, error) {
ret := _m.Called(source)
var r0 int64
if rf, ok := ret.Get(0).(func(model.GroupSource) int64); ok {
r0 = rf(source)
} else {
r0 = ret.Get(0).(int64)
}
var r1 error
if rf, ok := ret.Get(1).(func(model.GroupSource) error); ok {
r1 = rf(source)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GroupCountWithAllowReference provides a mock function with given fields:
func (_m *GroupStore) GroupCountWithAllowReference() (int64, error) {
ret := _m.Called()

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

@@ -3835,6 +3835,22 @@ func (s *TimerLayerGroupStore) GroupCount() (int64, error) {
return result, err
}
func (s *TimerLayerGroupStore) GroupCountBySource(source model.GroupSource) (int64, error) {
start := timemodule.Now()
result, err := s.GroupStore.GroupCountBySource(source)
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
if s.Root.Metrics != nil {
success := "false"
if err == nil {
success = "true"
}
s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.GroupCountBySource", success, elapsed)
}
return result, err
}
func (s *TimerLayerGroupStore) GroupCountWithAllowReference() (int64, error) {
start := timemodule.Now()