Skip to content

Commit 196d0f1

Browse files
tsuzukayamaTiago Suzukayama
andauthored
add disable postgres check flag on healthcheck (#700)
Co-authored-by: Tiago Suzukayama <tiago.suzukayama@wildlifestudios.com>
1 parent 43f7257 commit 196d0f1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

config/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internalApi:
1414
enabled: true
1515
healthcheck:
1616
enabled: true
17+
skipPostgresCheck: false
1718

1819
adapters:
1920
redis:

internal/service/internal_api.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ func RunInternalServer(ctx context.Context, configs config.Config, healthDeps *H
4040
mux := http.NewServeMux()
4141
if configs.GetBool("internalApi.healthcheck.enabled") {
4242
zap.L().Info("adding healthcheck handler to internal API")
43+
if configs.GetBool("internalApi.healthcheck.skipPostgresCheck") {
44+
zap.L().Warn("PostgreSQL health check is DISABLED - /readyz will not check database connectivity")
45+
}
4346
mux.HandleFunc("/health", handleHealth)
4447
mux.HandleFunc("/healthz", handleHealth)
45-
mux.HandleFunc("/readyz", handleReadyz(healthDeps))
48+
mux.HandleFunc("/readyz", handleReadyz(configs, healthDeps))
4649
}
4750
if configs.GetBool("internalApi.metrics.enabled") {
4851
zap.L().Info("adding metrics handler to internal API")
@@ -70,11 +73,14 @@ func RunInternalServer(ctx context.Context, configs config.Config, healthDeps *H
7073
}
7174
}
7275

73-
func handleReadyz(deps *HealthDependencies) http.HandlerFunc {
76+
func handleReadyz(c config.Config, deps *HealthDependencies) http.HandlerFunc {
7477
return func(w http.ResponseWriter, r *http.Request) {
7578
healthy := true
7679

77-
if deps.PostgresDB != nil {
80+
// Skip PostgreSQL check if configured
81+
skipPostgresCheck := c.GetBool("internalApi.healthcheck.skipPostgresCheck")
82+
83+
if !skipPostgresCheck && deps.PostgresDB != nil {
7884
if err := checkPostgres(r.Context(), deps.PostgresDB); err != nil {
7985
healthy = false
8086
}
@@ -86,11 +92,14 @@ func handleReadyz(deps *HealthDependencies) http.HandlerFunc {
8692
}
8793
}
8894

95+
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
96+
8997
if !healthy {
9098
w.WriteHeader(http.StatusServiceUnavailable)
99+
_, _ = w.Write([]byte("Service Unavailable"))
100+
return
91101
}
92102

93-
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
94103
w.WriteHeader(http.StatusOK)
95104
_, _ = w.Write([]byte("OK"))
96105
}

0 commit comments

Comments
 (0)