Skip to content

Commit

Permalink
Made org ratios more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelycode committed Jan 11, 2016
1 parent 82e2fdf commit 840afb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ func (m Monitor) Check(sessionData *SessionState, key string) {
usagePerc = (float64(remainder) / float64(sessionData.QuotaMax)) * 100.0

log.Debug("Perc is: ", usagePerc)
RenewalDate := time.Unix(sessionData.QuotaRenews, 0)

log.Debug("Now is: ", time.Now())
log.Debug("Renewal is: ", RenewalDate)
if time.Now().After(RenewalDate) {
// Make sure that renewal is still in the future, If renewal is in the past,
// then the quota can expire and will auto-renew
log.Debug("Renewal date is in the past, skipping")
return
}

if config.Monitor.GlobalTriggerLimit > 0.0 {
if usagePerc >= config.Monitor.GlobalTriggerLimit {
log.Info("Firing...")
m.Fire(sessionData, key, config.Monitor.GlobalTriggerLimit)
}
}
Expand All @@ -52,6 +63,7 @@ func (m Monitor) Check(sessionData *SessionState, key string) {
if usagePerc >= triggerLimit {

if triggerLimit != config.Monitor.GlobalTriggerLimit {
log.Info("Firing...")
m.Fire(sessionData, key, triggerLimit)
break
}
Expand Down
2 changes: 1 addition & 1 deletion redis_cluster_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (r *RedisClusterStorageManager) IncrememntWithExpire(keyName string, expire
log.Debug("Incremented key: ", fixedKey, ", val is: ", val)
if val == 1 {
log.Debug("--> Setting Expire")
r.db.Send("EXPIRE", fixedKey, expire)
r.db.Do("EXPIRE", fixedKey, expire)
}
if err != nil {
log.Error("Error trying to increment value:", err)
Expand Down
1 change: 1 addition & 0 deletions session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (l SessionLimiter) IsRedisQuotaExceeded(currentSession *SessionState, key s
log.Debug("[QUOTA] Inbound raw key is: ", key)
rawKey := QuotaKeyPrefix + publicHash(key)
log.Debug("[QUOTA] Quota limiter key is: ", rawKey)
log.Debug("Renewing with TTL: ", currentSession.QuotaRenewalRate)
// INCR the key (If it equals 1 - set EXPIRE)
qInt := store.IncrememntWithExpire(rawKey, currentSession.QuotaRenewalRate)

Expand Down

0 comments on commit 840afb8

Please sign in to comment.