Converting to structured logging the file app/ratelimit.go (#12176)

Этот коммит содержится в:
Nikhil Ranjan
2019-09-12 13:35:07 +02:00
коммит произвёл Claudio Costa
родитель d327df12e6
Коммит 37d719d20c

Просмотреть файл

@@ -4,7 +4,6 @@
package app package app
import ( import (
"fmt"
"math" "math"
"net/http" "net/http"
"strconv" "strconv"
@@ -77,14 +76,14 @@ func (rl *RateLimiter) GenerateKey(r *http.Request) string {
func (rl *RateLimiter) RateLimitWriter(key string, w http.ResponseWriter) bool { func (rl *RateLimiter) RateLimitWriter(key string, w http.ResponseWriter) bool {
limited, context, err := rl.throttledRateLimiter.RateLimit(key, 1) limited, context, err := rl.throttledRateLimiter.RateLimit(key, 1)
if err != nil { if err != nil {
mlog.Critical("Internal server error when rate limiting. Rate Limiting broken. Error:" + err.Error()) mlog.Critical("Internal server error when rate limiting. Rate Limiting broken.", mlog.Err(err))
return false return false
} }
setRateLimitHeaders(w, context) setRateLimitHeaders(w, context)
if limited { if limited {
mlog.Error(fmt.Sprintf("Denied due to throttling settings code=429 key=%v", key)) mlog.Error("Denied due to throttling settings code=429", mlog.String("key", key))
http.Error(w, "limit exceeded", 429) http.Error(w, "limit exceeded", 429)
} }