Quotas: save their usage after every change
The server hooks the engine's OnChange to save what the quotas used, so a reboot soon after a change that counts a quota differently doesn't bring back its usage counted the old way (it was saved every five minutes and on stop only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8fa28d01c2
commit
aaf0ac5206
5 files changed
+33
-5
No files matched your search
@@ -141,6 +141,16 @@ func New(cfg Config, eng *engine.Engine, fw Firewall, ifaces Interfaces, log *sl
|
||||
s := &Server{cfg: cfg, eng: eng, fw: fw, ifaces: ifaces, store: eng.Store(), log: log, mux: http.NewServeMux(), limiter: newRateLimiter(),
|
||||
web: web, started: time.Now(), logs: newLogRing(2000), nowFn: time.Now, unitLinks: nftablesUnitLinks}
|
||||
s.routes()
|
||||
// What the quotas used is saved after every change too, not only every
|
||||
// five minutes: a change that counts a quota differently converts its
|
||||
// usage, and a restart must not bring back the old kind.
|
||||
prev := eng.OnChange
|
||||
eng.OnChange = func(st *model.State) {
|
||||
if prev != nil {
|
||||
prev(st)
|
||||
}
|
||||
s.SaveQuotaUsage(context.Background())
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user