Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: add logic for infinite displays #172

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/base/app_throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ func NewAppThrottle(expireAt time.Time, ratio float64) *AppThrottle {
}
return result
}

// DisplayAppThrottle is a type for displaying data back to the end
// user via chatop. Handles infinite TTL and allows ExpiresAt to be "INFINITE"
type DisplayAppThrottle struct {
ExpireAt string
Ratio float64
}
2 changes: 1 addition & 1 deletion pkg/group/consensus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ConsensusServiceStatus struct {
// ConsensusService is a freno-oriented interface for making requests that require consensus.
type ConsensusService interface {
ThrottleApp(appName string, ttlMinutes int64, expireAt time.Time, ratio float64) error
ThrottledAppsMap() (result map[string](*base.AppThrottle))
ThrottledAppsMap() (result map[string](*base.DisplayAppThrottle))
UnthrottleApp(appName string) error
RecentAppsMap() (result map[string](*base.RecentApp))

Expand Down
2 changes: 1 addition & 1 deletion pkg/group/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (backend *MySQLBackend) ThrottleApp(appName string, ttlMinutes int64, expir
return err
}

func (backend *MySQLBackend) ThrottledAppsMap() (result map[string](*base.AppThrottle)) {
func (backend *MySQLBackend) ThrottledAppsMap() (result map[string](*base.DisplayAppThrottle)) {
return backend.throttler.ThrottledAppsMap()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/group/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (store *Store) SkippedHostsMap() map[string]time.Time {
return store.throttler.SkippedHostsMap()
}

func (store *Store) ThrottledAppsMap() (result map[string](*base.AppThrottle)) {
func (store *Store) ThrottledAppsMap() (result map[string](*base.DisplayAppThrottle)) {
return store.throttler.ThrottledAppsMap()
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,20 @@ func (throttler *Throttler) IsAppThrottled(appName, storeName string) bool {
return false
}

func (throttler *Throttler) ThrottledAppsMap() (result map[string](*base.AppThrottle)) {
result = make(map[string](*base.AppThrottle))
func (throttler *Throttler) ThrottledAppsMap() (result map[string](*base.DisplayAppThrottle)) {
result = make(map[string](*base.DisplayAppThrottle))

for appName, item := range throttler.throttledApps.Items() {
appThrottle := item.Object.(*base.AppThrottle)
appThrottle := item.Object.(*base.DisplayAppThrottle)
expire, expireErr := time.Parse(appThrottle.ExpireAt, "2024-Jan-01")

if expireErr != nil {
panic(expireErr)
}

if expire.IsZero() {
appThrottle.ExpireAt = "INFINITE"
}
result[appName] = appThrottle
}
return result
Expand Down
Loading