[MM-16032] Add system ping endpoint health checks (#11267)

* Add system ping endpoint health checks

This change adds the option for additional server health checks
to be performed when the system ping endpoint is hit. An additional
field 'getserverstatus' is required to run the enhanced health
checks to ensure previous default ping behavior is not modified.

* Use snake_casing
Этот коммит содержится в:
Gabe Jackson
2019-06-20 16:06:04 -04:00
коммит произвёл Joram Wilander
родитель a9b4a7f508
Коммит 41e5ec3c5e
5 изменённых файлов: 109 добавлений и 40 удалений

Просмотреть файл

@@ -15,25 +15,47 @@ import (
func TestGetPing(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
goRoutineHealthThreshold := *th.App.Config().ServiceSettings.GoroutineHealthThreshold
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = goRoutineHealthThreshold })
}()
t.Run("basic ping", func(t *testing.T) {
status, resp := Client.GetPing()
CheckNoError(t, resp)
if status != "OK" {
t.Fatal("should return OK")
}
t.Run("healthy", func(t *testing.T) {
status, resp := th.Client.GetPing()
CheckNoError(t, resp)
assert.Equal(t, model.STATUS_OK, status)
})
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = 10 })
status, resp = th.SystemAdminClient.GetPing()
CheckInternalErrorStatus(t, resp)
if status != "unhealthy" {
t.Fatal("should return unhealthy")
}
t.Run("unhealthy", func(t *testing.T) {
goRoutineHealthThreshold := *th.App.Config().ServiceSettings.GoroutineHealthThreshold
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = goRoutineHealthThreshold })
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = 10 })
status, resp := th.Client.GetPing()
CheckInternalErrorStatus(t, resp)
assert.Equal(t, model.STATUS_UNHEALTHY, status)
})
})
t.Run("with server status", func(t *testing.T) {
t.Run("healthy", func(t *testing.T) {
status, resp := th.Client.GetPingWithServerStatus()
CheckNoError(t, resp)
assert.Equal(t, model.STATUS_OK, status)
})
t.Run("unhealthy", func(t *testing.T) {
badDriver := "badDriverName"
th.App.Config().FileSettings.DriverName = &badDriver
status, resp := th.Client.GetPingWithServerStatus()
CheckInternalErrorStatus(t, resp)
assert.Equal(t, model.STATUS_UNHEALTHY, status)
})
})
}
func TestGetAudits(t *testing.T) {