Skip to content

Commit ca5fa40

Browse files
authored
Add startup and liveness probe, change readiness probe (#67)
1 parent 4f90edf commit ca5fa40

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

internal/healthcheck/fullnode.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func (h *Healthcheck) fullNodeReceive(resp *types.WebsocketResponse) {
3131
return
3232
}
3333

34+
if block.BlockchainState.Sync.Synced {
35+
h.lastSyncedTime = time.Now()
36+
}
37+
3438
h.lastHeight = blockHeight
3539
h.lastHeightTime = time.Now()
3640
}
@@ -62,9 +66,23 @@ func (h *Healthcheck) fullNodeHealthcheck() func(http.ResponseWriter, *http.Requ
6266
}
6367
}
6468

65-
// Healthcheck endpoint for the full node service as a whole
69+
// Startup endpoint will be successful when the full node is running and the peak height is increasing
70+
func (h *Healthcheck) fullNodeStartup() func(http.ResponseWriter, *http.Request) {
71+
return func(w http.ResponseWriter, r *http.Request) {
72+
timeMetricHealthcheckHelper(h.lastHeightTime, w, r)
73+
}
74+
}
75+
76+
// Readiness endpoint will be successful when the full node is synced
6677
func (h *Healthcheck) fullNodeReadiness() func(http.ResponseWriter, *http.Request) {
6778
return func(w http.ResponseWriter, r *http.Request) {
68-
timeMetricHealthcheckHelper(h.lastFullNodeActivity, w, r)
79+
timeMetricHealthcheckHelper(h.lastSyncedTime, w, r)
80+
}
81+
}
82+
83+
// Liveness endpoint will be successful when the full node is running and the peak height is increasing
84+
func (h *Healthcheck) fullNodeLiveness() func(http.ResponseWriter, *http.Request) {
85+
return func(w http.ResponseWriter, r *http.Request) {
86+
timeMetricHealthcheckHelper(h.lastHeightTime, w, r)
6987
}
7088
}

internal/healthcheck/healthcheck.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type Healthcheck struct {
2121
client *rpc.Client
2222
chiaConfig *config.ChiaConfig
2323

24+
// Last time the full node was synced
25+
lastSyncedTime time.Time
26+
2427
// Last block height we received
2528
lastHeight uint32
2629

@@ -88,7 +91,9 @@ func (h *Healthcheck) StartServer() error {
8891
log.Printf("Starting healthcheck server on port %d", h.healthcheckPort)
8992

9093
http.HandleFunc("/full_node", h.fullNodeHealthcheck())
94+
http.HandleFunc("/full_node/startup", h.fullNodeStartup())
9195
http.HandleFunc("/full_node/readiness", h.fullNodeReadiness())
96+
http.HandleFunc("/full_node/liveness", h.fullNodeLiveness())
9297
http.HandleFunc("/seeder", h.seederHealthcheck())
9398
http.HandleFunc("/seeder/readiness", h.seederReadiness())
9499
http.HandleFunc("/timelord", h.timelordHealthcheck())

0 commit comments

Comments
 (0)