Skip to content

Commit

Permalink
fix regression on rate calculations (#2705)
Browse files Browse the repository at this point in the history
There are cases where apiLimit was nil resulting into tests to panic

This handles nil apiLimit and avoid division by zero
  • Loading branch information
gernest authored and buger committed Nov 28, 2019
1 parent 0750612 commit b51e391
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cli/lint/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ const confSchema = `{
"drl_notification_frequency": {
"type": "integer"
},
"drl_threshold": {
"type": "number"
},
"enable_analytics": {
"type": "boolean"
},
Expand Down
13 changes: 12 additions & 1 deletion session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,18 @@ func (l *SessionLimiter) ForwardMessage(r *http.Request, currentSession *user.Se
if DRLManager.Servers != nil {
n = float64(DRLManager.Servers.Count())
}
rate := apiLimit.Rate / apiLimit.Per
var rate float64
if apiLimit == nil {
rate = currentSession.Rate
if currentSession.Per != 0 {
rate /= currentSession.Per
}
} else {
rate = apiLimit.Rate
if apiLimit.Per != 0 {
rate /= apiLimit.Per
}
}
c := globalConf.DRLThreshold
if c == 0 {
// defaults to 5
Expand Down

0 comments on commit b51e391

Please sign in to comment.