Add POST /api/admin/reset-latency endpoint

Zeroes block-update latency counters (count, sum, last, wasted work)
in both memory and the kv store. Used by the StartOS reset-latency
action to let operators start fresh after tuning.
This commit is contained in:
satoshi
2026-05-11 02:18:14 +03:00
parent 6acff6280f
commit 72890d900b
2 changed files with 24 additions and 0 deletions
+6
View File
@@ -38,6 +38,7 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("GET /api/snapshot", s.snapshot)
mux.HandleFunc("GET /api/ws", s.handleWS)
mux.HandleFunc("GET /api/admin/debug-blocks", s.debugBlocks)
mux.HandleFunc("POST /api/admin/reset-latency", s.resetLatency)
mux.Handle("/", spaHandler(webui.FS()))
return mux
}
@@ -208,3 +209,8 @@ func (s *Server) debugBlocks(w http.ResponseWriter, r *http.Request) {
"db": db,
})
}
func (s *Server) resetLatency(w http.ResponseWriter, _ *http.Request) {
s.Agg.ResetLatency()
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
}
+18
View File
@@ -113,6 +113,24 @@ func (a *Aggregator) IngestLatencyEvents(ctx context.Context, events <-chan logm
}
}
// ResetLatency zeroes the block-update latency counters both in memory
// and in the persistent kv store.
func (a *Aggregator) ResetLatency() {
a.mu.Lock()
a.latencyCount = 0
a.latencySumMs = 0
a.latencyLastMs = 0
a.staleWorkHashes = 0
a.mu.Unlock()
if a.Store != nil {
_ = a.Store.SetKV(kvLatencyCount, "0")
_ = a.Store.SetKV(kvLatencySumMs, "0")
_ = a.Store.SetKV(kvLatencyLastMs, "0")
_ = a.Store.SetKV(kvStaleWorkHashes, "0")
}
a.Log.Info("block latency stats reset")
}
// IngestBlockEvents reads block events from the tailer and appends them
// to the snapshot's block history. Runs until ctx is cancelled.
func (a *Aggregator) IngestBlockEvents(ctx context.Context, events <-chan logmon.BlockEvent) {