MM-60269: Removed an incorrect return that caused missing API timing metrics for 4xx and 5xx errors (#28049)

* removed an incorretc return that caused missing API timing metrics for 4xx and 5xx errors

* Added tests and recorded metric for URL length limit as well

* Status code fix
Этот коммит содержится в:
Harshil Sharma
2024-08-26 19:51:47 +05:30
коммит произвёл GitHub
родитель 9591e6182f
Коммит c2c37cea20
2 изменённых файлов: 78 добавлений и 4 удалений

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

@@ -164,7 +164,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
requestID := model.NewId()
var statusCode string
var rateLimitExceeded bool
defer func() {
responseLogFields := []mlog.Field{
mlog.String("method", r.Method),
@@ -175,11 +175,18 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if c.AppContext.Session() != nil {
responseLogFields = append(responseLogFields, mlog.String("user_id", c.AppContext.Session().UserId))
}
statusCode := strconv.Itoa(w.(*responseWriterWrapper).StatusCode())
// Websockets are returning status code 0 to requests after closing the socket
if statusCode != "0" {
responseLogFields = append(responseLogFields, mlog.String("status_code", statusCode))
}
mlog.Debug("Received HTTP request", responseLogFields...)
if !rateLimitExceeded {
h.recordMetrics(c, r, now, statusCode)
}
}()
t, _ := i18n.GetTranslationsAndLocaleFromRequest(r)
@@ -302,8 +309,11 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// Rate limit by UserID
if c.App.Srv().RateLimiter != nil && c.App.Srv().RateLimiter.UserIdRateLimit(c.AppContext.Session().UserId, w) {
return
if c.App.Srv().RateLimiter != nil {
rateLimitExceeded = c.App.Srv().RateLimiter.UserIdRateLimit(c.AppContext.Session().UserId, w)
if rateLimitExceeded {
return
}
}
h.checkCSRFToken(c, r, token, tokenLocation, session)
@@ -382,8 +392,9 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.handleContextError(c, w, r)
return
}
}
statusCode = strconv.Itoa(w.(*responseWriterWrapper).StatusCode())
func (h Handler) recordMetrics(c *Context, r *http.Request, now time.Time, statusCode string) {
if c.App.Metrics() != nil {
c.App.Metrics().IncrementHTTPRequest()