@@ -8,6 +8,7 @@ package logic
8
8
import (
9
9
"fmt"
10
10
"net/http"
11
+ "strings"
11
12
"sync/atomic"
12
13
"time"
13
14
@@ -18,6 +19,26 @@ import (
18
19
"github.com/outbrain/golib/sqlutils"
19
20
)
20
21
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
+
21
42
// Throttler collects metrics related to throttling and makes informed decisison
22
43
// whether throttling should take place.
23
44
type Throttler struct {
@@ -34,6 +55,17 @@ func NewThrottler(applier *Applier, inspector *Inspector) *Throttler {
34
55
}
35
56
}
36
57
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
+
37
69
// shouldThrottle performs checks to see whether we should currently be throttling.
38
70
// It merely observes the metrics collected by other components, it does not issue
39
71
// its own metric collection.
@@ -49,7 +81,7 @@ func (this *Throttler) shouldThrottle() (result bool, reason string, reasonHint
49
81
// HTTP throttle
50
82
statusCode := atomic .LoadInt64 (& this .migrationContext .ThrottleHTTPStatusCode )
51
83
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
53
85
}
54
86
// Replication lag throttle
55
87
maxLagMillisecondsThrottleThreshold := atomic .LoadInt64 (& this .migrationContext .MaxLagMillisecondsThrottleThreshold )
0 commit comments