@@ -8,6 +8,7 @@ package logic
88import (
99 "fmt"
1010 "net/http"
11+ "strings"
1112 "sync/atomic"
1213 "time"
1314
@@ -18,6 +19,26 @@ import (
1819 "github.com/outbrain/golib/sqlutils"
1920)
2021
22+ var (
23+ httpStatusMessages map [int ]string = map [int ]string {
24+ 200 : "OK" ,
25+ 404 : "Not found" ,
26+ 417 : "Expectation failed" ,
27+ 429 : "Too many requests" ,
28+ 500 : "Internal server error" ,
29+ }
30+ // See https://github.com/github/freno/blob/master/doc/http.md
31+ httpStatusFrenoMessages map [int ]string = map [int ]string {
32+ 200 : "OK" ,
33+ 404 : "freno: unknown metric" ,
34+ 417 : "freno: access forbidden" ,
35+ 429 : "freno: threshold exceeded" ,
36+ 500 : "freno: internal error" ,
37+ }
38+ )
39+
40+ const frenoMagicHint = "freno"
41+
2142// Throttler collects metrics related to throttling and makes informed decisison
2243// whether throttling should take place.
2344type Throttler struct {
@@ -34,6 +55,17 @@ func NewThrottler(applier *Applier, inspector *Inspector) *Throttler {
3455 }
3556}
3657
58+ func (this * Throttler ) throttleHttpMessage (statusCode int ) string {
59+ statusCodesMap := httpStatusMessages
60+ if throttleHttp := this .migrationContext .GetThrottleHTTP (); strings .Contains (throttleHttp , frenoMagicHint ) {
61+ statusCodesMap = httpStatusFrenoMessages
62+ }
63+ if message , ok := statusCodesMap [statusCode ]; ok {
64+ return fmt .Sprintf ("%s (http=%d)" , message , statusCode )
65+ }
66+ return fmt .Sprintf ("http=%d" , statusCode )
67+ }
68+
3769// shouldThrottle performs checks to see whether we should currently be throttling.
3870// It merely observes the metrics collected by other components, it does not issue
3971// its own metric collection.
@@ -49,7 +81,7 @@ func (this *Throttler) shouldThrottle() (result bool, reason string, reasonHint
4981 // HTTP throttle
5082 statusCode := atomic .LoadInt64 (& this .migrationContext .ThrottleHTTPStatusCode )
5183 if statusCode != 0 && statusCode != http .StatusOK {
52- return true , fmt . Sprintf ( "http=%d" , statusCode ), base .NoThrottleReasonHint
84+ return true , this . throttleHttpMessage ( int ( statusCode ) ), base .NoThrottleReasonHint
5385 }
5486 // Replication lag throttle
5587 maxLagMillisecondsThrottleThreshold := atomic .LoadInt64 (& this .migrationContext .MaxLagMillisecondsThrottleThreshold )
0 commit comments