prober: persist health across restarts via callback; seed from DB on startup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ica467d6db76c495a6ccadbad89276b536a6a6964
This commit is contained in:
parent
049e4202dd
commit
d599ef02a7
4 changed files with 154 additions and 6 deletions
|
|
@ -86,6 +86,23 @@ func main() {
|
|||
|
||||
p := prober.New(cfg.Cache.LatencyAlpha)
|
||||
p.InitUpstreams(cfg.Upstreams)
|
||||
|
||||
// Seed prober with persisted health data from the previous run.
|
||||
if rows, err := db.LoadAllHealth(); err == nil {
|
||||
for _, row := range rows {
|
||||
p.Seed(row.URL, row.EMALatency, row.ConsecutiveFails, int64(row.TotalQueries))
|
||||
}
|
||||
} else {
|
||||
slog.Warn("failed to load persisted health data", "error", err)
|
||||
}
|
||||
|
||||
// Persist health updates to SQLite.
|
||||
p.SetHealthPersistence(func(url string, ema float64, cf uint32, tq uint64) {
|
||||
if err := db.SaveHealth(url, ema, int(cf), int64(tq)); err != nil {
|
||||
slog.Warn("failed to save health", "url", url, "error", err)
|
||||
}
|
||||
})
|
||||
|
||||
for _, u := range cfg.Upstreams {
|
||||
go p.ProbeUpstream(u.URL)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue