vmauth: fix vmauth_user_request_backend_errors_total metric calc logic for use case when only one backend is available - if we get an error from the retry_status_codes list, but cannot execute retry, we increment vmauth_user_request_backend_errors_total as well (#5688)

This commit is contained in:
Alexander Marshalov 2024-01-25 14:04:20 +01:00 committed by Aliaksandr Valialkin
parent bd7ebb41b2
commit ef4bb36d99
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -261,7 +261,8 @@ func tryProcessingRequest(w http.ResponseWriter, r *http.Request, targetURL *url
logger.Warnf("remoteAddr: %s; requestURI: %s; retrying the request to %s because of response error: %s", remoteAddr, req.URL, targetURL, err) logger.Warnf("remoteAddr: %s; requestURI: %s; retrying the request to %s because of response error: %s", remoteAddr, req.URL, targetURL, err)
return false return false
} }
if (rtbOK && rtb.canRetry()) && hasInt(retryStatusCodes, res.StatusCode) { if hasInt(retryStatusCodes, res.StatusCode) {
if rtbOK && rtb.canRetry() {
// Retry requests at other backends if it matches retryStatusCodes. // Retry requests at other backends if it matches retryStatusCodes.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4893 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4893
remoteAddr := httpserver.GetQuotedRemoteAddr(r) remoteAddr := httpserver.GetQuotedRemoteAddr(r)
@ -271,6 +272,10 @@ func tryProcessingRequest(w http.ResponseWriter, r *http.Request, targetURL *url
remoteAddr, req.URL, targetURL, res.StatusCode, retryStatusCodes) remoteAddr, req.URL, targetURL, res.StatusCode, retryStatusCodes)
return false return false
} }
// if we get an error from the retry_status_codes list, but cannot execute retry,
// we consider such a request an error as well
ui.backendErrors.Inc()
}
removeHopHeaders(res.Header) removeHopHeaders(res.Header)
copyHeader(w.Header(), res.Header) copyHeader(w.Header(), res.Header)
updateHeadersByConfig(w.Header(), hc.ResponseHeaders) updateHeadersByConfig(w.Header(), hc.ResponseHeaders)