WIP: prep for 1.0 #1

Draft
sneak wants to merge 9 commits from next into master
Showing only changes of commit ebe241ac3e - Show all commits

View File

@ -9,7 +9,6 @@ import (
u "git.eeqj.de/sneak/goutil"
"github.com/flosch/pongo2"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/labstack/echo"
)
@ -23,7 +22,12 @@ func (a *Server) instances() []hash {
i := make(hash)
// TODO move this locking onto a method on Instance that just
// returns a new hash
// FIXME figure out why a very short lock here deadlocks
//this only locks the FSM, not the whole instance struct
i["status"] = v.Status()
// now do a quick lock of the whole instance just to copy out the
// attrs
v.Lock()
i["hostname"] = v.Hostname
i["uuid"] = v.UUID.String()
@ -31,9 +35,8 @@ func (a *Server) instances() []hash {
i["nextCheckAfter"] = (-1 * now.Sub(v.NextFetch)).String()
i["successCount"] = v.SuccessCount
i["errorCount"] = v.ErrorCount
i["consecutiveErrorCount"] = v.ConsecutiveErrorCount
i["identified"] = v.Identified
//this only locks the FSM, not the whole instance struct
i["status"] = v.Status()
i["software"] = "unknown"
i["version"] = "unknown"
if v.Identified {
@ -41,6 +44,7 @@ func (a *Server) instances() []hash {
i["version"] = v.ServerVersionString
}
v.Unlock()
resp = append(resp, i)
}
@ -54,7 +58,7 @@ func (a *Server) instances() []hash {
return resp
}
func (a *Server) instanceSummary() map[string]int {
func (a *Server) instanceStatusSummary() map[string]int {
resp := make(map[string]int)
for _, v := range a.feta.manager.ListInstances() {
v.Lock()
@ -68,26 +72,6 @@ func (a *Server) instanceSummary() map[string]int {
return resp
}
/*
func (a *Server) getInstanceListHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
result := &gin.H{
"instances": a.instances(),
}
json, err := json.Marshal(result)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(json)
}
}
*/
func (a *Server) notFoundHandler(c echo.Context) error {
return c.String(http.StatusNotFound, "404 not found")
}
@ -117,17 +101,33 @@ func (a *Server) instanceHandler(c echo.Context) error {
}
func (a *Server) indexHandler(c echo.Context) error {
count, err := a.feta.dbm.TotalTootCount()
if err != nil {
count = 0
}
tc := pongo2.Context{
"time": time.Now().UTC().Format(time.RFC3339Nano),
"gitrev": a.feta.version,
"instances": a.instances(),
"time": time.Now().UTC().Format(time.RFC3339Nano),
"gitrev": a.feta.version,
"tootCount": count,
"instances": a.instances(),
"instanceStatusSummary": a.instanceStatusSummary(),
}
return c.Render(http.StatusOK, "index.html", tc)
}
func (a *Server) instanceListHandler(c echo.Context) error {
il := a.instances()
tc := pongo2.Context{
"time": time.Now().UTC().Format(time.RFC3339Nano),
"gitrev": a.feta.version,
"instances": il,
}
return c.Render(http.StatusOK, "instancelist.html", tc)
}
func (a *Server) statsHandler(c echo.Context) error {
index := &gin.H{
"server": &gin.H{
index := &hash{
"server": &hash{
"now": time.Now().UTC().Format(time.RFC3339),
"uptime": a.feta.uptime().String(),
"goroutines": runtime.NumGoroutine(),
@ -135,14 +135,14 @@ func (a *Server) statsHandler(c echo.Context) error {
"version": a.feta.version,
"buildarch": a.feta.buildarch,
},
"instanceSummary": a.instanceSummary(),
"instanceStatusSummary": a.instanceStatusSummary(),
}
return c.JSONPretty(http.StatusOK, index, " ")
}
func (a *Server) healthCheckHandler(c echo.Context) error {
resp := &gin.H{
resp := &hash{
"status": "ok",
"now": time.Now().UTC().Format(time.RFC3339),
"uptime": a.feta.uptime().String(),