mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-04 04:05:04 +03:00
fix(traffic): stop adding capped counters in SQL
Per-client counters are stored up to TrafficMax, which a node can reach by reporting huge usage, and the group totals, group baselines and the per-client reset lookup added two such counters inside SQL, overflowing it: every group listing and reset failed, and no client on that reset cycle was reset. The counters are now read separately and added in Go, saturating at TrafficMax.
This commit is contained in:
@@ -227,3 +227,21 @@ func TestGroupResetStillZeroesAfterBaselineAdjustments(t *testing.T) {
|
||||
t.Fatalf("group reset did not zero adjusted baselines: got %+v", g)
|
||||
}
|
||||
}
|
||||
|
||||
// Counters are stored up to TrafficMax (a node can report that much); adding two in SQL
|
||||
// overflowed and failed every group listing, reset and baseline shift for the panel.
|
||||
func TestGroupTrafficSurvivesCountersAtTheCap(t *testing.T) {
|
||||
initTrafficTestDB(t)
|
||||
svc := &ClientService{}
|
||||
seedGroupedClient(t, "huge-a", "vip", database.TrafficMax, database.TrafficMax)
|
||||
seedGroupedClient(t, "huge-b", "vip", database.TrafficMax, database.TrafficMax)
|
||||
if g := groupByName(t, svc, "vip"); g.Up != database.TrafficMax || g.ClientCount != 2 {
|
||||
t.Fatalf("group = %+v, want its counters held at TrafficMax", g)
|
||||
}
|
||||
if err := svc.ResetGroupTraffic("vip"); err != nil {
|
||||
t.Fatalf("ResetGroupTraffic: %v", err)
|
||||
}
|
||||
if err := adjustGroupBaselinesForRemovedTraffic(database.GetDB(), []string{"huge-a", "huge-b"}); err != nil {
|
||||
t.Fatalf("shift baselines: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user