Update aggregate API to use binary megabytes and enhance documentation
Publish telemt-api gateway Docker image / test (push) Successful in 27s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 1m26s

- Changed API responses and internal calculations to use binary megabytes (MiB) instead of octets for traffic metrics.
- Updated relevant endpoints in AGGREGATE.md to reflect the new metric units.
- Modified handler and merge logic to accommodate the new data structure and ensure accurate traffic reporting.
- Enhanced tests to validate the changes in traffic calculations and summary data.
- Deprecated the use of total_octets in favor of total_megabytes for consistency across the API.
This commit is contained in:
Denozordec
2026-03-30 01:04:00 +07:00
parent fb35107b82
commit 4a4f15bd0b
7 changed files with 89 additions and 35 deletions
+14 -5
View File
@@ -35,7 +35,7 @@ func TestBuildTraffic(t *testing.T) {
if u1 == nil {
t.Fatal("missing u1")
}
if u1.Servers["a"].TotalOctets != 100 || u1.Servers["b"].TotalOctets != 30 {
if u1.Servers["a"].TotalMegabytes != octetsToMegabytes(100) || u1.Servers["b"].TotalMegabytes != octetsToMegabytes(30) {
t.Fatalf("u1 servers: %+v", u1.Servers)
}
}
@@ -98,15 +98,24 @@ func TestBuildUniqueIPsPrimary(t *testing.T) {
func TestBuildSummary(t *testing.T) {
results := []ServerFetchResult{
{Alias: "a", OK: true, Users: []UserInfo{{Username: "x", TotalOctets: 100, CurrentConnections: 2}}},
{
Alias: "a", OK: true,
Users: []UserInfo{
{Username: "x", TotalOctets: 100, CurrentConnections: 2, ActiveUniqueIPs: 3},
{Username: "y", TotalOctets: 500, CurrentConnections: 0, ActiveUniqueIPs: 1},
},
},
{Alias: "b", OK: false, Error: "down"},
}
s := BuildSummary(results, 5)
if s.ServersOK != 1 || s.ServersFailed != 1 || s.FleetTotalOctets != 100 || s.FleetTotalConnections != 2 {
if s.ServersOK != 1 || s.ServersFailed != 1 || s.FleetTotalMegabytes != octetsToMegabytes(600) || s.FleetTotalConnections != 2 {
t.Fatalf("summary: %+v", s)
}
if len(s.TopUsers) != 1 || s.TopUsers[0].Username != "x" {
t.Fatalf("top: %+v", s.TopUsers)
if len(s.TopUsers) != 2 || s.TopUsers[0].Username != "y" || s.TopUsers[0].TotalMegabytes != octetsToMegabytes(500) {
t.Fatalf("top traffic: %+v", s.TopUsers)
}
if len(s.TopUsersByUniqueIPs) != 2 || s.TopUsersByUniqueIPs[0].Username != "x" || s.TopUsersByUniqueIPs[0].UniqueIPs != 3 {
t.Fatalf("top unique ips: %+v", s.TopUsersByUniqueIPs)
}
}