1
0
mirror of synced 2024-11-21 20:46:05 +03:00

better logging for rate limiting

This commit is contained in:
Pavel 2024-02-13 12:13:49 +03:00 committed by GitHub
parent 8ea0679a09
commit 1012f97f08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -63,16 +63,8 @@ func makeRequest(reqType, url string, buf io.Reader, c *MgClient) ([]byte, int,
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Transport-Token", c.Token) req.Header.Set("X-Transport-Token", c.Token)
if c.Debug {
if strings.Contains(url, "/files/upload") {
c.writeLog("MG TRANSPORT API Request: %s %s %s [file data]", reqType, url, c.Token)
} else {
c.writeLog("MG TRANSPORT API Request: %s %s %s %v", reqType, url, c.Token, buf)
}
}
c.mux.Lock()
defer c.mux.Unlock() defer c.mux.Unlock()
c.mux.Lock()
attempt := 0 attempt := 0
tryAgain: tryAgain:
@ -87,6 +79,14 @@ tryAgain:
} }
c.rps++ c.rps++
if c.Debug {
if strings.Contains(url, "/files/upload") {
c.writeLog("MG TRANSPORT API Request: %s %s %s [file data]", reqType, url, c.Token)
} else {
c.writeLog("MG TRANSPORT API Request: %s %s %s %v", reqType, url, c.Token, buf)
}
}
resp, err := c.httpClient.Do(req) resp, err := c.httpClient.Do(req)
if err != nil { if err != nil {
return res, 0, NewCriticalHTTPError(err) return res, 0, NewCriticalHTTPError(err)
@ -94,6 +94,7 @@ tryAgain:
if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 { if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
attempt++ attempt++
c.writeLog("MG TRANSPORT API Request rate limit hit on attempt %d, retrying", attempt)
goto tryAgain goto tryAgain
} }