Auth: Fix disable/remove duplicate user entries metrics for performance reasons (#61675)

* fix: remove metrics from duplicate user entries

* fix: disable metrics collection for authinfo

* fix: initifine goroutine loop that happened

* removed: metrics
This commit is contained in:
Eric Leijonmarck 2023-01-18 16:01:47 +01:00 committed by GitHub
parent fa36591380
commit bedd2304d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -29,7 +29,9 @@ func ProvideAuthInfoStore(sqlStore db.DB, secretsService secrets.Service, userSe
logger: log.New("login.authinfo.store"),
userService: userService,
}
InitMetrics()
// FIXME: disabled the metric collection for duplicate user entries
// due to query performance issues that is clogging the users Grafana instance
// InitDuplicateUserMetrics()
return store
}

View File

@ -10,7 +10,10 @@ import (
"github.com/grafana/grafana/pkg/services/login"
)
func InitMetrics() {
// Should be in use in ProvideAuthInfoStore
// due to query performance for big user tables
// we have disabled these metrics from Grafana for now
func InitDuplicateUserMetrics() {
login.Once.Do(func() {
login.MStatDuplicateUserEntries = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_users_total_duplicate_user_entries",
@ -39,18 +42,18 @@ func InitMetrics() {
}
func (s *AuthInfoStore) RunMetricsCollection(ctx context.Context) error {
if _, err := s.GetLoginStats(ctx); err != nil {
s.logger.Warn("Failed to get authinfo metrics", "error", err.Error())
}
// if _, err := s.GetLoginStats(ctx); err != nil {
// s.logger.Warn("Failed to get authinfo metrics", "error", err.Error())
// }
updateStatsTicker := time.NewTicker(login.MetricsCollectionInterval)
defer updateStatsTicker.Stop()
for {
select {
case <-updateStatsTicker.C:
if _, err := s.GetLoginStats(ctx); err != nil {
s.logger.Warn("Failed to get authinfo metrics", "error", err.Error())
}
// if _, err := s.GetLoginStats(ctx); err != nil {
// s.logger.Warn("Failed to get authinfo metrics", "error", nil)
// }
case <-ctx.Done():
return ctx.Err()
}

View File

@ -25,7 +25,9 @@ func ProvideAuthInfoService(userProtectionService login.UserProtectionService, a
authInfoStore: authInfoStore,
logger: log.New("login.authinfo"),
}
usageStats.RegisterMetricsFunc(authInfoStore.CollectLoginStats)
// FIXME: disabled metrics until further notice
// query performance is slow for more than 20000 users
// usageStats.RegisterMetricsFunc(authInfoStore.CollectLoginStats)
return s
}