Skip to content

Commit

Permalink
make timer service
Browse files Browse the repository at this point in the history
  • Loading branch information
ying-jeanne committed Dec 19, 2024
1 parent d2eab6b commit 1f39282
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/sources/mimir/configure/about-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ We do not guarantee backwards compatibility for experimental features and flags.
Experimental configuration and flags are subject to change.

The following features are currently experimental:

- Cost attribution
- Configure labels for cost attribution
- `-validation.cost-attribution-labels`
Expand Down
18 changes: 3 additions & 15 deletions pkg/costattribution/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,15 @@ func NewManager(cleanupInterval, exportInterval, inactiveTimeout time.Duration,
metricsExportInterval: exportInterval,
}

m.Service = services.NewBasicService(nil, m.running, nil).WithName("cost attribution manager")
m.Service = services.NewTimerService(cleanupInterval, nil, m.iteration, nil).WithName("cost attribution manager")
if err := reg.Register(m); err != nil {
return nil, err
}
return m, nil
}

func (m *Manager) running(ctx context.Context) error {
t := time.NewTicker(m.cleanupInterval)
defer t.Stop()

for {
select {
case <-t.C:
if err := m.purgeInactiveAttributionsUntil(time.Now().Add(-m.inactiveTimeout).Unix()); err != nil {
return err
}
case <-ctx.Done():
return nil
}
}
func (m *Manager) iteration(_ context.Context) error {
return m.purgeInactiveAttributionsUntil(time.Now().Add(-m.inactiveTimeout).Unix())
}

func (m *Manager) EnabledForUser(userID string) bool {
Expand Down

0 comments on commit 1f39282

Please sign in to comment.