From 72890d900baef160497a1d25f7135f86aec271b1 Mon Sep 17 00:00:00 2001 From: satoshi Date: Mon, 11 May 2026 02:18:14 +0300 Subject: [PATCH] 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. --- api/internal/httpapi/server.go | 6 ++++++ api/internal/state/blocks.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/api/internal/httpapi/server.go b/api/internal/httpapi/server.go index b48063a..fd8d969 100644 --- a/api/internal/httpapi/server.go +++ b/api/internal/httpapi/server.go @@ -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}) +} diff --git a/api/internal/state/blocks.go b/api/internal/state/blocks.go index f5a351b..c2344a4 100644 --- a/api/internal/state/blocks.go +++ b/api/internal/state/blocks.go @@ -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) {