Control-plane requests follow the lease but take no slot and write no row
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -16,8 +16,9 @@ import (
|
||||
// forward builds the reverse proxy for one host, tees the response, records the accounting row, and
|
||||
// logs. leaseState is "new" or "reused"; waited is the time spent in the queue. ctxEst is the
|
||||
// prompt size the context guard estimated (0 when the guard did not run); ctxHeader is the
|
||||
// "moved:…<host>" header to set when the guard relocated the conversation.
|
||||
func (p *Handler) forward(w http.ResponseWriter, r *http.Request, route, host, leaseState, rest, fp, model string, started time.Time, waited time.Duration, ctxEst int, ctxHeader string) {
|
||||
// "moved:…<host>" header to set when the guard relocated the conversation. control is true for a
|
||||
// control-plane call: it takes no slot, so forward writes no row and logs at Debug for it.
|
||||
func (p *Handler) forward(w http.ResponseWriter, r *http.Request, route, host, leaseState, rest, fp, model string, started time.Time, waited time.Duration, ctxEst int, ctxHeader string, control bool) {
|
||||
hostCfg, ok := p.cfg.Hosts[host]
|
||||
if !ok {
|
||||
p.writeError(w, http.StatusBadGateway, "upstream failed")
|
||||
@@ -45,7 +46,9 @@ func (p *Handler) forward(w http.ResponseWriter, r *http.Request, route, host, l
|
||||
} else {
|
||||
req.Err = "upstream error"
|
||||
}
|
||||
p.writeRecord(req)
|
||||
if !control {
|
||||
p.writeRecord(req)
|
||||
}
|
||||
panic(pv)
|
||||
}
|
||||
}()
|
||||
@@ -58,12 +61,29 @@ func (p *Handler) forward(w http.ResponseWriter, r *http.Request, route, host, l
|
||||
req.Status = 499
|
||||
req.Err = "client cancelled"
|
||||
}
|
||||
p.writeRecord(req)
|
||||
if !control {
|
||||
p.writeRecord(req)
|
||||
}
|
||||
|
||||
fp8 := fp
|
||||
if len(fp8) > 8 {
|
||||
fp8 = fp8[:8]
|
||||
}
|
||||
if control {
|
||||
p.log.Debug("request",
|
||||
"route", route,
|
||||
"host", host,
|
||||
"method", r.Method,
|
||||
"path", rest,
|
||||
"status", rec.status,
|
||||
"lease", leaseState,
|
||||
"queued_ms", waited.Milliseconds(),
|
||||
"fp", fp8,
|
||||
"ctx_est", ctxEst,
|
||||
"ms", total.Milliseconds(),
|
||||
)
|
||||
return
|
||||
}
|
||||
p.log.Info("request",
|
||||
"route", route,
|
||||
"host", host,
|
||||
|
||||
Reference in New Issue
Block a user