CI / test (push) Successful in 9m30s
Each router's per-counter request and token counts, this minute's and the last, ride the standby's two-second exchange with the leader. The leader answers each standby with everyone else's sum, its own included, and puts the standbys' sum in force on its own router; each limiter adds the others' counts to its sliding window. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
896 B
Go
28 lines
896 B
Go
package adminapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/control"
|
|
)
|
|
|
|
// registerRouting is what a standby answering requests itself reads from the
|
|
// leader, and reports back to it. Reached by the standby through the agent
|
|
// port with its control-plane certificate, like the rest of the forwarded API.
|
|
func (a *API) registerRouting(mux Mux) {
|
|
mux.HandleFunc("GET /api/v1/routing", func(w http.ResponseWriter, _ *http.Request) {
|
|
writeJSON(w, http.StatusOK, a.ctl.Routing())
|
|
})
|
|
mux.HandleFunc("POST /api/v1/routing/activity", func(w http.ResponseWriter, r *http.Request) {
|
|
var act control.Activity
|
|
if err := json.NewDecoder(io.LimitReader(r.Body, 8<<20)).Decode(&act); err != nil {
|
|
writeError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
a.ctl.RecordActivity(act)
|
|
writeJSON(w, http.StatusOK, a.ctl.RoutingFor(act.From))
|
|
})
|
|
}
|