app/{vmagent,vminsert}: follow-up for 1cfa183c2b

- Call httpserver.GetQuotedRemoteAddr() and httpserver.GetRequestURI() only when the error occurs.
  This saves CPU time on fast path when there are no parsing errors.
- Create a helper function - httpserver.LogError() - for logging the error with the request uri and remote addr context.
This commit is contained in:
Aliaksandr Valialkin
2023-01-23 22:22:05 -08:00
parent 1cfa183c2b
commit f7acdb13db
4 changed files with 12 additions and 10 deletions

View File

@@ -705,3 +705,10 @@ func Redirect(w http.ResponseWriter, url string) {
// This may require browser cache cleaning after the incorrect redirect is fixed.
w.WriteHeader(http.StatusFound)
}
// LogError logs the errStr with the context from req.
func LogError(req *http.Request, errStr string) {
uri := GetRequestURI(req)
remoteAddr := GetQuotedRemoteAddr(req)
logger.Errorf("uri: %s, remote address: %q: %s", uri, remoteAddr, errStr)
}