Logging fixes

pull/633/head
binwiederhier 2023-02-25 15:31:12 -05:00
parent 0606fbe60a
commit f7f343fe55
3 changed files with 13 additions and 5 deletions

View File

@ -6,6 +6,8 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
This release changes the way UnifiedPush (UP) topics are rate limited from publisher-based rate limiting to subscriber-based This release changes the way UnifiedPush (UP) topics are rate limited from publisher-based rate limiting to subscriber-based
rate limiting. This allows UP application servers to send higher volumes, since the subscribers carry the rate limits. rate limiting. This allows UP application servers to send higher volumes, since the subscribers carry the rate limits.
However, it also means that UP clients have to subscribe to a topic first before they are allowed to publish. If they do
no, clients will receive an HTTP 507 response from the server.
We also fixed another issue with UnifiedPush: Some Mastodon servers were sending unsupported `Authorization` headers, We also fixed another issue with UnifiedPush: Some Mastodon servers were sending unsupported `Authorization` headers,
which ntfy rejected with an HTTP 401. We now ignore unsupported header values. which ntfy rejected with an HTTP 401. We now ignore unsupported header values.

View File

@ -30,6 +30,10 @@ const (
tagMatrix = "matrix" tagMatrix = "matrix"
) )
var (
normalErrorCodes = []int{http.StatusNotFound, http.StatusBadRequest, http.StatusTooManyRequests, http.StatusUnauthorized, http.StatusInsufficientStorage}
)
// logr creates a new log event with HTTP request fields // logr creates a new log event with HTTP request fields
func logr(r *http.Request) *log.Event { func logr(r *http.Request) *log.Event {
return log.Tag(tagHTTP).Fields(httpContext(r)) // Tag may be overwritten return log.Tag(tagHTTP).Fields(httpContext(r)) // Tag may be overwritten

View File

@ -319,19 +319,21 @@ func (s *Server) handleError(w http.ResponseWriter, r *http.Request, v *visitor,
if !ok { if !ok {
httpErr = errHTTPInternalError httpErr = errHTTPInternalError
} }
isNormalError := strings.Contains(err.Error(), "i/o timeout") || util.Contains([]int{http.StatusNotFound, http.StatusBadRequest, http.StatusTooManyRequests, http.StatusUnauthorized}, httpErr.HTTPCode) isNormalError := strings.Contains(err.Error(), "i/o timeout") || util.Contains(normalErrorCodes, httpErr.HTTPCode)
ev := logvr(v, r).Err(err)
if websocket.IsWebSocketUpgrade(r) { if websocket.IsWebSocketUpgrade(r) {
ev.Tag(tagWebsocket).Fields(websocketErrorContext(err))
if isNormalError { if isNormalError {
logvr(v, r).Tag(tagWebsocket).Err(err).Fields(websocketErrorContext(err)).Debug("WebSocket error (this error is okay, it happens a lot): %s", err.Error()) ev.Debug("WebSocket error (this error is okay, it happens a lot): %s", err.Error())
} else { } else {
logvr(v, r).Tag(tagWebsocket).Err(err).Fields(websocketErrorContext(err)).Info("WebSocket error: %s", err.Error()) ev.Info("WebSocket error: %s", err.Error())
} }
return // Do not attempt to write to upgraded connection return // Do not attempt to write to upgraded connection
} }
if isNormalError { if isNormalError {
logvr(v, r).Err(err).Debug("Connection closed with HTTP %d (ntfy error %d)", httpErr.HTTPCode, httpErr.Code) ev.Debug("Connection closed with HTTP %d (ntfy error %d)", httpErr.HTTPCode, httpErr.Code)
} else { } else {
logvr(v, r).Err(err).Info("Connection closed with HTTP %d (ntfy error %d)", httpErr.HTTPCode, httpErr.Code) ev.Info("Connection closed with HTTP %d (ntfy error %d)", httpErr.HTTPCode, httpErr.Code)
} }
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", s.config.AccessControlAllowOrigin) // CORS, allow cross-origin requests w.Header().Set("Access-Control-Allow-Origin", s.config.AccessControlAllowOrigin) // CORS, allow cross-origin requests