mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Users: Add config option to control how often last_seen is updated (#88721)
Users: Add config option to control how often last_seen is updated Co-authored-by: Karl Persson <kalle.persson92@gmail.com>
This commit is contained in:
parent
399651b9ad
commit
1b2f110664
@ -519,6 +519,9 @@ user_invite_max_lifetime_duration = 24h
|
|||||||
# The duration in time a verification email, used to update the email address of a user, remains valid before expiring. This setting should be expressed as a duration. Examples: 6h (hours), 2d (days), 1w (week). Default is 1h (1 hour).
|
# The duration in time a verification email, used to update the email address of a user, remains valid before expiring. This setting should be expressed as a duration. Examples: 6h (hours), 2d (days), 1w (week). Default is 1h (1 hour).
|
||||||
verification_email_max_lifetime_duration = 1h
|
verification_email_max_lifetime_duration = 1h
|
||||||
|
|
||||||
|
# Frequency of updating a user's last seen time. The minimum supported duration is 5m (5 minutes). The maximum supported duration is 1h (1 hour)
|
||||||
|
last_seen_update_interval = 15m
|
||||||
|
|
||||||
# Enter a comma-separated list of usernames to hide them in the Grafana UI. These users are shown to Grafana admins and to themselves.
|
# Enter a comma-separated list of usernames to hide them in the Grafana UI. These users are shown to Grafana admins and to themselves.
|
||||||
hidden_users =
|
hidden_users =
|
||||||
|
|
||||||
|
@ -520,6 +520,9 @@
|
|||||||
# The duration in time a verification email, used to update the email address of a user, remains valid before expiring. This setting should be expressed as a duration. Examples: 6h (hours), 2d (days), 1w (week). Default is 1h (1 hour).
|
# The duration in time a verification email, used to update the email address of a user, remains valid before expiring. This setting should be expressed as a duration. Examples: 6h (hours), 2d (days), 1w (week). Default is 1h (1 hour).
|
||||||
;verification_email_max_lifetime_duration = 1h
|
;verification_email_max_lifetime_duration = 1h
|
||||||
|
|
||||||
|
# Frequency of updating a user's last seen time. The minimum supported duration is 5m (5 minutes). The maximum supported duration is 1h (1 hour).
|
||||||
|
;last_seen_update_interval = 15m
|
||||||
|
|
||||||
# Enter a comma-separated list of users login to hide them in the Grafana UI. These users are shown to Grafana admins and themselves.
|
# Enter a comma-separated list of users login to hide them in the Grafana UI. These users are shown to Grafana admins and themselves.
|
||||||
; hidden_users =
|
; hidden_users =
|
||||||
|
|
||||||
|
@ -892,6 +892,12 @@ The duration in time a verification email, used to update the email address of a
|
|||||||
This setting should be expressed as a duration. Examples: 6h (hours), 2d (days), 1w (week).
|
This setting should be expressed as a duration. Examples: 6h (hours), 2d (days), 1w (week).
|
||||||
Default is 1h (1 hour).
|
Default is 1h (1 hour).
|
||||||
|
|
||||||
|
### last_seen_update_interval
|
||||||
|
|
||||||
|
The frequency of updating a user's last seen time.
|
||||||
|
This setting should be expressed as a duration. Examples: 1h (hour), 15m (minutes)
|
||||||
|
Default is `15m` (15 minutes). The minimum supported duration is `5m` (5 minutes). The maximum supported duration is `1h` (1 hour).
|
||||||
|
|
||||||
### hidden_users
|
### hidden_users
|
||||||
|
|
||||||
This is a comma-separated list of usernames. Users specified here are hidden in the Grafana UI. They are still visible to Grafana administrators and to themselves.
|
This is a comma-separated list of usernames. Users specified here are hidden in the Grafana UI. They are still visible to Grafana administrators and to themselves.
|
||||||
|
@ -301,15 +301,15 @@ func (s *Service) UpdateLastSeenAt(ctx context.Context, cmd *user.UpdateUserLast
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !shouldUpdateLastSeen(u.LastSeenAt) {
|
if !s.shouldUpdateLastSeen(u.LastSeenAt) {
|
||||||
return user.ErrLastSeenUpToDate
|
return user.ErrLastSeenUpToDate
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.store.UpdateLastSeenAt(ctx, cmd)
|
return s.store.UpdateLastSeenAt(ctx, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldUpdateLastSeen(t time.Time) bool {
|
func (s *Service) shouldUpdateLastSeen(t time.Time) bool {
|
||||||
return time.Since(t) > time.Minute*15
|
return time.Since(t) > s.cfg.UserLastSeenUpdateInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
func (s *Service) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
||||||
|
@ -221,6 +221,7 @@ func TestUpdateLastSeenAt(t *testing.T) {
|
|||||||
tracer: tracing.InitializeTracerForTest(),
|
tracer: tracing.InitializeTracerForTest(),
|
||||||
}
|
}
|
||||||
userService.cfg = setting.NewCfg()
|
userService.cfg = setting.NewCfg()
|
||||||
|
userService.cfg.UserLastSeenUpdateInterval = 5 * time.Minute
|
||||||
|
|
||||||
t.Run("update last seen at", func(t *testing.T) {
|
t.Run("update last seen at", func(t *testing.T) {
|
||||||
userStore.ExpectedSignedInUser = &user.SignedInUser{UserID: 1, OrgID: 1, Email: "email", Login: "login", Name: "name", LastSeenAt: time.Now().Add(-20 * time.Minute)}
|
userStore.ExpectedSignedInUser = &user.SignedInUser{UserID: 1, OrgID: 1, Email: "email", Login: "login", Name: "name", LastSeenAt: time.Now().Add(-20 * time.Minute)}
|
||||||
|
@ -306,6 +306,7 @@ type Cfg struct {
|
|||||||
UserInviteMaxLifetime time.Duration
|
UserInviteMaxLifetime time.Duration
|
||||||
HiddenUsers map[string]struct{}
|
HiddenUsers map[string]struct{}
|
||||||
CaseInsensitiveLogin bool // Login and Email will be considered case insensitive
|
CaseInsensitiveLogin bool // Login and Email will be considered case insensitive
|
||||||
|
UserLastSeenUpdateInterval time.Duration
|
||||||
VerificationEmailMaxLifetime time.Duration
|
VerificationEmailMaxLifetime time.Duration
|
||||||
|
|
||||||
// Service Accounts
|
// Service Accounts
|
||||||
@ -1695,6 +1696,19 @@ func readUserSettings(iniFile *ini.File, cfg *Cfg) error {
|
|||||||
return errors.New("the minimum supported value for the `user_invite_max_lifetime_duration` configuration is 15m (15 minutes)")
|
return errors.New("the minimum supported value for the `user_invite_max_lifetime_duration` configuration is 15m (15 minutes)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.UserLastSeenUpdateInterval, err = gtime.ParseDuration(valueAsString(users, "last_seen_update_interval", "15m"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.UserLastSeenUpdateInterval < time.Minute*5 {
|
||||||
|
cfg.Logger.Warn("the minimum supported value for the `last_seen_update_interval` configuration is 5m (5 minutes)")
|
||||||
|
cfg.UserLastSeenUpdateInterval = time.Minute * 5
|
||||||
|
} else if cfg.UserLastSeenUpdateInterval > time.Hour*1 {
|
||||||
|
cfg.Logger.Warn("the maximum supported value for the `last_seen_update_interval` configuration is 1h (1 hour)")
|
||||||
|
cfg.UserLastSeenUpdateInterval = time.Hour * 1
|
||||||
|
}
|
||||||
|
|
||||||
cfg.HiddenUsers = make(map[string]struct{})
|
cfg.HiddenUsers = make(map[string]struct{})
|
||||||
hiddenUsers := users.Key("hidden_users").MustString("")
|
hiddenUsers := users.Key("hidden_users").MustString("")
|
||||||
for _, user := range strings.Split(hiddenUsers, ",") {
|
for _, user := range strings.Split(hiddenUsers, ",") {
|
||||||
|
Loading…
Reference in New Issue
Block a user