Health check answers 503 while report files cannot be written (closes #142)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The health check answered 200 "status":"ok" whatever happened, so a container whose report files could not be written stayed healthy while every report was refused with 500. The report buffer now says whether its last write of a report file failed. While it has, the health check's status is "error" and the handler answers 503 with the same fields, which fails the image's HEALTHCHECK. At start no write has failed, and the first write that succeeds brings back 200. A test removes DATA_DIR to make a write fail and checks the 503, then the 200 once a write succeeds again. Model: opus-5-5
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"sneak.berlin/go/netwatch/internal/config"
|
||||
"sneak.berlin/go/netwatch/internal/globals"
|
||||
"sneak.berlin/go/netwatch/internal/logger"
|
||||
"sneak.berlin/go/netwatch/internal/reportbuf"
|
||||
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
type Params struct {
|
||||
fx.In
|
||||
|
||||
Buffer *reportbuf.Buffer
|
||||
Config *config.Config
|
||||
Globals *globals.Globals
|
||||
Logger *logger.Logger
|
||||
@@ -68,12 +70,18 @@ func New(
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Healthcheck returns the current health status of the application.
|
||||
// Healthcheck returns the current health status of the application:
|
||||
// "ok", or "error" while report files cannot be written.
|
||||
func (s *Healthcheck) Healthcheck() *HealthcheckResponse {
|
||||
status := "ok"
|
||||
if s.params.Buffer.LastWriteFailed() {
|
||||
status = "error"
|
||||
}
|
||||
|
||||
return &HealthcheckResponse{
|
||||
Appname: s.params.Globals.Appname,
|
||||
Now: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Status: "ok",
|
||||
Status: status,
|
||||
UptimeHuman: s.uptime().String(),
|
||||
UptimeSeconds: int64(s.uptime().Seconds()),
|
||||
Version: s.params.Globals.Version,
|
||||
|
||||
Reference in New Issue
Block a user