From b63f61fe7d022bf1569993afbd9441ee7db2feca Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Wed, 29 Jun 2016 04:16:20 -0800 Subject: PLT-3440 (#3440) --- api/context.go | 13 ++++++++++++- api/general.go | 19 ++++++++++++++++++- webapp/actions/websocket_actions.jsx | 13 +++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/api/context.go b/api/context.go index 798f4dc87..fd8a0da7e 100644 --- a/api/context.go +++ b/api/context.go @@ -283,6 +283,11 @@ func (c *Context) LogError(err *model.AppError) { c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.T), err.DetailedError) } +func (c *Context) LogDebug(err *model.AppError) { + l4g.Debug(utils.T("api.context.log.error"), c.Path, err.Where, err.StatusCode, + c.RequestId, c.Session.UserId, c.IpAddress, err.SystemMessage(utils.T), err.DetailedError) +} + func (c *Context) UserRequired() { if len(c.Session.UserId) == 0 { c.Err = model.NewLocAppError("", "api.context.session_expired.app_error", nil, "UserRequired") @@ -481,7 +486,13 @@ func Handle404(w http.ResponseWriter, r *http.Request) { err := model.NewLocAppError("Handle404", "api.context.404.app_error", nil, "") err.Translate(utils.T) err.StatusCode = http.StatusNotFound - l4g.Error("%v: code=404 ip=%v", r.URL.Path, GetIpAddress(r)) + + // filter out old paths that are poluting the log file + if strings.Contains(r.URL.Path, "/api/v1/") { + l4g.Debug("%v: code=404 ip=%v", r.URL.Path, GetIpAddress(r)) + } else { + l4g.Error("%v: code=404 ip=%v", r.URL.Path, GetIpAddress(r)) + } if IsApiCall(r) { w.WriteHeader(err.StatusCode) diff --git a/api/general.go b/api/general.go index 0adc36d9f..fdf884d6b 100644 --- a/api/general.go +++ b/api/general.go @@ -6,6 +6,7 @@ package api import ( "fmt" "net/http" + "strings" l4g "github.com/alecthomas/log4go" @@ -27,11 +28,22 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) { } func logClient(c *Context, w http.ResponseWriter, r *http.Request) { + forceToDebug := false + + if !*utils.Cfg.ServiceSettings.EnableDeveloper { + forceToDebug = true + } + m := model.MapFromJson(r.Body) lvl := m["level"] msg := m["message"] + // filter out javascript errors from franz that are poluting the log files + if strings.Contains(msg, "/franz") { + forceToDebug = true + } + if len(msg) > 400 { msg = msg[0:399] } @@ -41,7 +53,12 @@ func logClient(c *Context, w http.ResponseWriter, r *http.Request) { err.Message = msg err.Id = msg err.Where = "client" - c.LogError(err) + + if forceToDebug { + c.LogDebug(err) + } else { + c.LogError(err) + } } ReturnStatusOK(w) diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index 11d7bbe18..fba5632ca 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -21,7 +21,8 @@ const SocketEvents = Constants.SocketEvents; import {browserHistory} from 'react-router/es6'; const MAX_WEBSOCKET_FAILS = 7; -const WEBSOCKET_RETRY_TIME = 3000; +const MIN_WEBSOCKET_RETRY_TIME = 3000; // 3 sec +const MAX_WEBSOCKET_RETRY_TIME = 300000; // 5 mins var conn = null; var connectFailCount = 0; @@ -74,8 +75,16 @@ export function initialize() { connectFailCount = connectFailCount + 1; + var retryTime = MIN_WEBSOCKET_RETRY_TIME; + if (connectFailCount > MAX_WEBSOCKET_FAILS) { ErrorStore.storeLastError({message: Utils.localizeMessage('channel_loader.socketError', 'Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port.')}); + + // If we've failed a bunch of connections then start backing off + retryTime = MIN_WEBSOCKET_RETRY_TIME * connectFailCount * connectFailCount; + if (retryTime > MAX_WEBSOCKET_RETRY_TIME) { + retryTime = MAX_WEBSOCKET_RETRY_TIME; + } } ErrorStore.setConnectionErrorCount(connectFailCount); @@ -85,7 +94,7 @@ export function initialize() { () => { initialize(); }, - WEBSOCKET_RETRY_TIME + retryTime ); }; -- cgit v1.2.3-1-g7c22