[MM-17554] Health Check: improves enhanced health check with a DB write check. (#11851)
* Add db write check to enhanced ping check function (#11813) * fix misspelling * improve logging (#11813) * MM-17554: update logging to uppercase * MM17554: log DB read/write success (#11813)
Этот коммит содержится в:
коммит произвёл
Gabe Jackson
родитель
a9ed8fab28
Коммит
f753819a66
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
@@ -64,11 +65,32 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if r.FormValue("get_server_status") != "" {
|
||||
dbStatusKey := "database_status"
|
||||
s[dbStatusKey] = model.STATUS_OK
|
||||
_, appErr := c.App.Srv.Store.System().Get()
|
||||
if appErr != nil {
|
||||
mlog.Debug(fmt.Sprintf("Unable to get database status: %s", appErr.Error()))
|
||||
|
||||
// Database Write/Read Check
|
||||
currentTime := fmt.Sprintf("%d", time.Now().Unix())
|
||||
healthCheckKey := "health_check"
|
||||
|
||||
writeErr := c.App.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
Name: healthCheckKey,
|
||||
Value: currentTime,
|
||||
})
|
||||
if writeErr != nil {
|
||||
mlog.Debug(fmt.Sprintf("Unable to write to database: %s", writeErr.Error()))
|
||||
s[dbStatusKey] = model.STATUS_UNHEALTHY
|
||||
s[model.STATUS] = model.STATUS_UNHEALTHY
|
||||
} else {
|
||||
healthCheck, readErr := c.App.Srv.Store.System().GetByName(healthCheckKey)
|
||||
if readErr != nil {
|
||||
mlog.Debug(fmt.Sprintf("Unable to read from database: %s", readErr.Error()))
|
||||
s[dbStatusKey] = model.STATUS_UNHEALTHY
|
||||
s[model.STATUS] = model.STATUS_UNHEALTHY
|
||||
} else if healthCheck.Value != currentTime {
|
||||
mlog.Debug(fmt.Sprintf("Incorrect healthcheck value, expected %s, got %s", currentTime, healthCheck.Value))
|
||||
s[dbStatusKey] = model.STATUS_UNHEALTHY
|
||||
s[model.STATUS] = model.STATUS_UNHEALTHY
|
||||
} else {
|
||||
mlog.Debug("Able to write/read files to database")
|
||||
}
|
||||
}
|
||||
|
||||
filestoreStatusKey := "filestore_status"
|
||||
|
||||
@@ -2888,7 +2888,7 @@ func (c *Client4) GetPing() (string, *Response) {
|
||||
}
|
||||
|
||||
// GetPingWithServerStatus will return ok if several basic server health checks
|
||||
// all psss successfully.
|
||||
// all pass successfully.
|
||||
func (c *Client4) GetPingWithServerStatus() (string, *Response) {
|
||||
r, err := c.DoApiGet(c.GetSystemRoute()+"/ping?get_server_status=true", "")
|
||||
if r != nil && r.StatusCode == 500 {
|
||||
|
||||
Ссылка в новой задаче
Block a user