Merge pull request #150 from github/meiji163/throttle-cluster · github/freno@f987bf1 · GitHub
Skip to content

Commit f987bf1

Browse files
authored
Merge pull request #150 from github/meiji163/throttle-cluster
Throttle app by cluster
2 parents ca98a19 + e8c33cb commit f987bf1

4 files changed

Lines changed: 45 additions & 20 deletions

File tree

‎doc/http.md‎

Lines changed: 3 additions & 2 deletions

‎pkg/http/api.go‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,21 @@ func (api *APIImpl) MetricsHealth(w http.ResponseWriter, r *http.Request, ps htt
235235

236236
// ThrottleApp forcibly marks given app as throttled. Future requests by this app may be denied.
237237
func (api *APIImpl) ThrottleApp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
238-
appName := ps.ByName("app")
238+
storeName := r.URL.Query().Get("store_name")
239+
var appName string
240+
if storeName != "" {
241+
// limit throttling to this store
242+
appName = fmt.Sprintf("%s/%s", ps.ByName("app"), storeName)
243+
} else {
244+
// default is throttle app globally
245+
appName = ps.ByName("app")
246+
}
247+
239248
var expireAt time.Time // default zero
240249
var ttlMinutes int64
241250
var ratio float64
242251
var err error
252+
243253
if ps.ByName("ttlMinutes") == "" {
244254
ttlMinutes = 0
245255
} else if ttlMinutes, err = strconv.ParseInt(ps.ByName("ttlMinutes"), 10, 64); err != nil {
@@ -263,12 +273,21 @@ response:
263273
api.respondGeneric(w, r, err)
264274
}
265275

266-
// ThrottleApp unthrottles given app.
276+
// UnthrottleApp unthrottles given app.
267277
func (api *APIImpl) UnthrottleApp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
268278
appName := ps.ByName("app")
269-
err := api.consensusService.UnthrottleApp(appName)
270-
271-
api.respondGeneric(w, r, err)
279+
appWithStorePrefix := appName + "/"
280+
281+
for app := range api.consensusService.ThrottledAppsMap() {
282+
if app == appName || strings.HasPrefix(app, appWithStorePrefix) {
283+
err := api.consensusService.UnthrottleApp(app)
284+
if err != nil {
285+
api.respondGeneric(w, r, err)
286+
return
287+
}
288+
}
289+
}
290+
api.respondGeneric(w, r, nil)
272291
}
273292

274293
// ThrottledApps returns a snapshot of all currently throttled apps

‎pkg/throttle/check.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (check *ThrottlerCheck) checkAppMetricResult(appName string, storeType stri
4848
}
4949
}
5050
//
51-
metricResult, threshold := check.throttler.AppRequestMetricResult(appName, metricResultFunc, denyApp)
51+
metricResult, threshold := check.throttler.AppRequestMetricResult(appName, storeName, metricResultFunc, denyApp)
5252
if flags.OverrideThreshold > 0 {
5353
threshold = flags.OverrideThreshold
5454
}

‎pkg/throttle/throttler.go‎

Lines changed: 17 additions & 12 deletions

0 commit comments

Comments
 (0)