Skip to content

Commit

Permalink
Add timelord healthcheck (#41)
Browse files Browse the repository at this point in the history
* Add timelord healthcheck

* Fmt
  • Loading branch information
cmmarslender authored Sep 7, 2024
1 parent 108090a commit 3636588
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Healthcheck struct {

// Last time we got a successful DNS response
lastDNSTime time.Time

// Time we got a good response from the timelord
lastTimelordTime time.Time
}

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

http.HandleFunc("/full_node", h.fullNodeHealthcheck())
http.HandleFunc("/seeder", h.seederHealthcheck())
http.HandleFunc("/timelord", h.timelordHealthcheck())
return http.ListenAndServe(fmt.Sprintf(":%d", h.healthcheckPort), nil)
}

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

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

func (h *Healthcheck) timelordReceive(resp *types.WebsocketResponse) {}

func (h *Healthcheck) harvesterReceive(resp *types.WebsocketResponse) {}

func (h *Healthcheck) farmerReceive(resp *types.WebsocketResponse) {}
Expand Down Expand Up @@ -139,4 +141,3 @@ func timeMetricHealthcheckHelper(lastTime time.Time, w http.ResponseWriter, r *h
}
}
}

27 changes: 27 additions & 0 deletions internal/healthcheck/timelord.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package healthcheck

import (
"net/http"
"time"

"github.com/chia-network/go-chia-libs/pkg/types"
)

// timelordReceive gets timelord events
func (h *Healthcheck) timelordReceive(resp *types.WebsocketResponse) {
switch resp.Command {
case "finished_pot":
h.lastTimelordTime = time.Now()
case "skipping_peak":
// Fastest timelord
case "new_peak":
// Not Fastest Timelord
}
}

// timelordHealthcheck endpoint for the timelord service as a whole
func (h *Healthcheck) timelordHealthcheck() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
timeMetricHealthcheckHelper(h.lastTimelordTime, w, r)
}
}

0 comments on commit 3636588

Please sign in to comment.