add healthz endpoint to server

This commit is contained in:
Brad Rydzewski 2017-10-05 14:17:27 -07:00
parent acb6a8b02a
commit bb8c569249
3 changed files with 29 additions and 0 deletions

View file

@ -169,6 +169,9 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
)
}
e.GET("/version", server.Version)
e.GET("/healthz", server.Health)
return e
}

24
server/z.go Normal file
View file

@ -0,0 +1,24 @@
package server
import (
"github.com/drone/drone/store"
"github.com/drone/drone/version"
"github.com/gin-gonic/gin"
)
// Health endpoint returns a 500 if the server state is unhealthy.
func Health(c *gin.Context) {
if err := store.FromContext(c).Ping(); err != nil {
c.String(500, err.Error())
return
}
c.String(200, "")
}
// Version endpoint returns the server version and build information.
func Version(c *gin.Context) {
c.JSON(200, gin.H{
"source": "https://github.com/drone/drone",
"version": version.Version.String(),
})
}

View file

@ -139,6 +139,8 @@ type Store interface {
TaskList() ([]*model.Task, error)
TaskInsert(*model.Task) error
TaskDelete(string) error
Ping() error
}
// GetUser gets a user by unique ID.