database max connections, recreated sendLog middleware, StrictSlash is now set to true (base path), removed OnSave method for Mobile notifier, increase health check time.

pull/224/head^2
hunterlong 2020-01-12 20:46:15 -08:00
parent 1aca05ecc6
commit d107d3cbee
7 changed files with 23 additions and 27 deletions

View File

@ -28,6 +28,6 @@ WORKDIR /app
VOLUME /app
EXPOSE $PORT
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true"
HEALTHCHECK --interval=60s --timeout=10s --retries=3 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true"
CMD statping -port $PORT

View File

@ -253,9 +253,11 @@ func (c *Core) Connect(retry bool, location string) error {
}
}
log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database")
if dbType == "sqlite3" {
dbSession.DB().SetMaxOpenConns(1)
}
dbSession.DB().SetMaxOpenConns(5)
dbSession.DB().SetMaxIdleConns(5)
dbSession.DB().SetConnMaxLifetime(1 * time.Minute)
if dbSession.DB().Ping() == nil {
DbSession = dbSession
if utils.VerboseMode >= 4 {

View File

@ -194,7 +194,6 @@ func loadTemplate(w http.ResponseWriter, r *http.Request) error {
return err
}
// render all templates
mainTemplate.Funcs(handlerFuncs(w, r))
for _, temp := range templates {
tmp, _ := source.TmplBox.String(temp)
mainTemplate, err = mainTemplate.Parse(tmp)

View File

@ -33,10 +33,9 @@ func basicAuthHandler(next http.Handler) http.Handler {
}
// sendLog is a http middleware that will log the duration of request and other useful fields
func sendLog(handler func(w http.ResponseWriter, r *http.Request)) http.Handler {
func sendLog(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t1 := utils.Now()
handler(w, r)
t2 := utils.Now().Sub(t1)
if r.RequestURI == "/logs/line" {
return
@ -46,6 +45,7 @@ func sendLog(handler func(w http.ResponseWriter, r *http.Request)) http.Handler
WithField("method", r.Method).
WithField("load_micro_seconds", t2.Microseconds()).
Infoln(fmt.Sprintf("%v (%v) | IP: %v", r.RequestURI, r.Method, r.Host))
next.ServeHTTP(w, r)
})
}

View File

@ -38,13 +38,14 @@ var (
func Router() *mux.Router {
dir := utils.Directory
CacheStorage = NewStorage()
r := mux.NewRouter()
r := mux.NewRouter().StrictSlash(true)
if os.Getenv("AUTH_USERNAME") != "" && os.Getenv("AUTH_PASSWORD") != "" {
authUser = os.Getenv("AUTH_USERNAME")
authPass = os.Getenv("AUTH_PASSWORD")
r.Use(basicAuthHandler)
}
r.Handle("/", sendLog(indexHandler))
r.Use(sendLog)
r.Handle("/", http.HandlerFunc(indexHandler))
if source.UsingAssets(dir) {
indexHandler := http.FileServer(http.Dir(dir + "/assets/"))
r.PathPrefix("/css/").Handler(http.StripPrefix("/css/", http.FileServer(http.Dir(dir+"/assets/css"))))
@ -61,12 +62,12 @@ func Router() *mux.Router {
r.PathPrefix("/favicon.ico").Handler(http.FileServer(source.TmplBox.HTTPBox()))
r.PathPrefix("/banner.png").Handler(http.FileServer(source.TmplBox.HTTPBox()))
}
r.Handle("/charts.js", sendLog(renderServiceChartsHandler))
r.Handle("/setup", sendLog(setupHandler)).Methods("GET")
r.Handle("/setup", sendLog(processSetupHandler)).Methods("POST")
r.Handle("/dashboard", sendLog(dashboardHandler)).Methods("GET")
r.Handle("/dashboard", sendLog(loginHandler)).Methods("POST")
r.Handle("/logout", sendLog(logoutHandler))
r.Handle("/charts.js", http.HandlerFunc(renderServiceChartsHandler))
r.Handle("/setup", http.HandlerFunc(setupHandler)).Methods("GET")
r.Handle("/setup", http.HandlerFunc(processSetupHandler)).Methods("POST")
r.Handle("/dashboard", http.HandlerFunc(dashboardHandler)).Methods("GET")
r.Handle("/dashboard", http.HandlerFunc(loginHandler)).Methods("POST")
r.Handle("/logout", http.HandlerFunc(logoutHandler))
r.Handle("/plugins/download/{name}", authenticated(pluginsDownloadHandler, true))
r.Handle("/plugins/{name}/save", authenticated(pluginSavedHandler, true)).Methods("POST")
r.Handle("/help", authenticated(helpHandler, true))
@ -97,11 +98,11 @@ func Router() *mux.Router {
// SERVICE Routes
r.Handle("/services", authenticated(servicesHandler, true)).Methods("GET")
r.Handle("/service/create", authenticated(createServiceHandler, true)).Methods("GET")
r.Handle("/service/{id}", sendLog(servicesViewHandler)).Methods("GET")
r.Handle("/service/{id}", readOnly(servicesViewHandler, true)).Methods("GET")
r.Handle("/service/{id}/edit", authenticated(servicesViewHandler, true)).Methods("GET")
r.Handle("/service/{id}/delete_failures", authenticated(servicesDeleteFailuresHandler, true)).Methods("GET")
r.Handle("/group/{id}", sendLog(groupViewHandler)).Methods("GET")
r.Handle("/group/{id}", http.HandlerFunc(groupViewHandler)).Methods("GET")
// API Routes
r.Handle("/api", authenticated(apiIndexHandler, false))
@ -163,7 +164,7 @@ func Router() *mux.Router {
r.Handle("/api/checkin/{api}", authenticated(apiCheckinHandler, false)).Methods("GET")
r.Handle("/api/checkin", authenticated(checkinCreateHandler, false)).Methods("POST")
r.Handle("/api/checkin/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE")
r.Handle("/checkin/{api}", sendLog(checkinHitHandler))
r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler))
// Static Files Routes
r.PathPrefix("/files/postman.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox())))
@ -172,10 +173,10 @@ func Router() *mux.Router {
// API Generic Routes
r.Handle("/metrics", readOnly(prometheusHandler, false))
r.Handle("/health", sendLog(healthCheckHandler))
r.Handle("/health", http.HandlerFunc(healthCheckHandler))
r.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir(dir+"/.well-known"))))
r.NotFoundHandler = sendLog(error404Handler)
r.NotFoundHandler = http.HandlerFunc(error404Handler)
return r
}

View File

@ -117,12 +117,6 @@ func (u *mobilePush) OnSuccess(s *types.Service) {
// OnSave triggers when this notifier has been saved
func (u *mobilePush) OnSave() error {
msg := &pushArray{
Message: "The Mobile Notifier has been saved",
Title: "Notification Saved",
Topic: mobileIdentifier,
}
u.AddQueue("saved", msg)
return nil
}

View File

@ -1 +1 @@
0.80.69
0.80.70