Skip to content

Commit 3636588

Browse files
authored
Add timelord healthcheck (#41)
* Add timelord healthcheck * Fmt
1 parent 108090a commit 3636588

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

internal/healthcheck/healthcheck.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type Healthcheck struct {
2626

2727
// Last time we got a successful DNS response
2828
lastDNSTime time.Time
29+
30+
// Time we got a good response from the timelord
31+
lastTimelordTime time.Time
2932
}
3033

3134
// NewHealthcheck returns a new instance of healthcheck
@@ -73,6 +76,7 @@ func (h *Healthcheck) StartServer() error {
7376

7477
http.HandleFunc("/full_node", h.fullNodeHealthcheck())
7578
http.HandleFunc("/seeder", h.seederHealthcheck())
79+
http.HandleFunc("/timelord", h.timelordHealthcheck())
7680
return http.ListenAndServe(fmt.Sprintf(":%d", h.healthcheckPort), nil)
7781
}
7882

@@ -105,8 +109,6 @@ func (h *Healthcheck) walletReceive(resp *types.WebsocketResponse) {}
105109

106110
func (h *Healthcheck) crawlerReceive(resp *types.WebsocketResponse) {}
107111

108-
func (h *Healthcheck) timelordReceive(resp *types.WebsocketResponse) {}
109-
110112
func (h *Healthcheck) harvesterReceive(resp *types.WebsocketResponse) {}
111113

112114
func (h *Healthcheck) farmerReceive(resp *types.WebsocketResponse) {}
@@ -139,4 +141,3 @@ func timeMetricHealthcheckHelper(lastTime time.Time, w http.ResponseWriter, r *h
139141
}
140142
}
141143
}
142-

internal/healthcheck/timelord.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package healthcheck
2+
3+
import (
4+
"net/http"
5+
"time"
6+
7+
"github.com/chia-network/go-chia-libs/pkg/types"
8+
)
9+
10+
// timelordReceive gets timelord events
11+
func (h *Healthcheck) timelordReceive(resp *types.WebsocketResponse) {
12+
switch resp.Command {
13+
case "finished_pot":
14+
h.lastTimelordTime = time.Now()
15+
case "skipping_peak":
16+
// Fastest timelord
17+
case "new_peak":
18+
// Not Fastest Timelord
19+
}
20+
}
21+
22+
// timelordHealthcheck endpoint for the timelord service as a whole
23+
func (h *Healthcheck) timelordHealthcheck() func(http.ResponseWriter, *http.Request) {
24+
return func(w http.ResponseWriter, r *http.Request) {
25+
timeMetricHealthcheckHelper(h.lastTimelordTime, w, r)
26+
}
27+
}

0 commit comments

Comments
 (0)