mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-24 22:11:40 +02:00
Update the healthcheck endpoint so it also writes to the DB to detect future cases of #38
This commit is contained in:
parent
4eda871232
commit
0bd9249df3
@ -351,15 +351,26 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
panic(fmt.Sprintf("failed to ping DB: %v", err))
|
panic(fmt.Sprintf("failed to ping DB: %v", err))
|
||||||
}
|
}
|
||||||
if isProductionEnvironment(r) {
|
if isProductionEnvironment(r) {
|
||||||
|
// Check that we have a reasonable looking set of devices/entries in the DB
|
||||||
var count int64
|
var count int64
|
||||||
checkGormResult(GLOBAL_DB.Model(&shared.EncHistoryEntry{}).Count(&count))
|
checkGormResult(GLOBAL_DB.Model(&shared.EncHistoryEntry{}).Count(&count))
|
||||||
if count < 100 {
|
if count < 1000 {
|
||||||
panic("Suspiciously few enc history entries!")
|
panic("Suspiciously few enc history entries!")
|
||||||
}
|
}
|
||||||
checkGormResult(GLOBAL_DB.Model(&shared.Device{}).Count(&count))
|
checkGormResult(GLOBAL_DB.Model(&shared.Device{}).Count(&count))
|
||||||
if count < 50 {
|
if count < 100 {
|
||||||
panic("Suspiciously few devices!")
|
panic("Suspiciously few devices!")
|
||||||
}
|
}
|
||||||
|
// Check that we can write to the DB. This entry will get written and then eventually cleaned by the cron.
|
||||||
|
checkGormResult(GLOBAL_DB.Create(&shared.EncHistoryEntry{
|
||||||
|
EncryptedData: []byte("data"),
|
||||||
|
Nonce: []byte("nonce"),
|
||||||
|
DeviceId: "healthcheck_device_id",
|
||||||
|
UserId: "healthcheck_user_id",
|
||||||
|
Date: time.Now(),
|
||||||
|
EncryptedId: "healthcheck_enc_id",
|
||||||
|
ReadCount: 10000,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
ok := "OK"
|
ok := "OK"
|
||||||
w.Write([]byte(ok))
|
w.Write([]byte(ok))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user