mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[PLT-5465/APIV4] GET /system/health - Improve ping health check to have limits (#6331)
* implement PLT-5465 - Improve ping health check to have limits * update /ping and delete /health * remove permission check
This commit is contained in:
committed by
Corey Hulen
parent
0e4add96ae
commit
ddc996f33f
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
@@ -17,6 +18,7 @@ func InitSystem() {
|
||||
l4g.Debug(utils.T("api.system.init.debug"))
|
||||
|
||||
BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
|
||||
|
||||
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET")
|
||||
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(updateConfig)).Methods("PUT")
|
||||
BaseRoutes.ApiRoot.Handle("/config/reload", ApiSessionRequired(configReload)).Methods("POST")
|
||||
@@ -34,7 +36,19 @@ func InitSystem() {
|
||||
}
|
||||
|
||||
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ReturnStatusOK(w)
|
||||
|
||||
actualGoroutines := runtime.NumGoroutine()
|
||||
if *utils.Cfg.ServiceSettings.GoroutineHealthThreshold <= 0 || actualGoroutines <= *utils.Cfg.ServiceSettings.GoroutineHealthThreshold {
|
||||
ReturnStatusOK(w)
|
||||
} else {
|
||||
rdata := map[string]string{}
|
||||
rdata["status"] = "unhealthy"
|
||||
|
||||
l4g.Warn(utils.T("api.system.go_routines"), actualGoroutines, *utils.Cfg.ServiceSettings.GoroutineHealthThreshold)
|
||||
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(model.MapToJson(rdata)))
|
||||
}
|
||||
}
|
||||
|
||||
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -12,13 +12,26 @@ import (
|
||||
)
|
||||
|
||||
func TestGetPing(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
b, _ := Client.GetPing()
|
||||
if b == false {
|
||||
t.Fatal()
|
||||
goRoutineHealthThreshold := *utils.Cfg.ServiceSettings.GoroutineHealthThreshold
|
||||
defer func() {
|
||||
*utils.Cfg.ServiceSettings.GoroutineHealthThreshold = goRoutineHealthThreshold
|
||||
}()
|
||||
|
||||
status, resp := Client.GetPing()
|
||||
CheckNoError(t, resp)
|
||||
if status != "OK" {
|
||||
t.Fatal("should return OK")
|
||||
}
|
||||
|
||||
*utils.Cfg.ServiceSettings.GoroutineHealthThreshold = 10
|
||||
status, resp = th.SystemAdminClient.GetPing()
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
if status != "unhealthy" {
|
||||
t.Fatal("should return unhealthy")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,5 +355,4 @@ func TestPostLog(t *testing.T) {
|
||||
if len(logMessage) == 0 {
|
||||
t.Fatal("should return the log message")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user