- Added new API route `/api/agg/radar-telemt-dcs` to aggregate DC status data from multiple upstreams, including metrics like coverage percentage and RTT. - Implemented handler logic in `handlers.go` and corresponding tests in `handlers_test.go` to ensure correct data retrieval and response formatting. - Updated the frontend to fetch and display radar DC data, enhancing the user interface with a new section for Telemt ME snapshots. - Enhanced documentation in `AGGREGATE.md` and `README.md` to reflect the new functionality and usage details.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package aggregate
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"sort"
|
|
"sync"
|
|
|
|
"github.com/telemt/telemt-api/internal/config"
|
|
)
|
|
|
|
const statsDcsPath = "stats/dcs"
|
|
|
|
// FetchRadarTelemtDcs calls GET /v1/stats/dcs on each Telemt in parallel.
|
|
func FetchRadarTelemtDcs(ctx context.Context, client *http.Client, parsed *config.Parsed, aliases []string) RadarTelemtDcsData {
|
|
if len(aliases) == 0 {
|
|
return RadarTelemtDcsData{}
|
|
}
|
|
rows := make([]RadarTelemtDcsServer, len(aliases))
|
|
var wg sync.WaitGroup
|
|
for i, alias := range aliases {
|
|
i, alias := i, alias
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
data, meta := FetchTelemtGET[DcStatusPayload](ctx, client, parsed, alias, statsDcsPath)
|
|
row := RadarTelemtDcsServer{
|
|
Alias: alias,
|
|
OK: meta.OK,
|
|
HTTPStatus: meta.HTTPStatus,
|
|
LatencyMs: meta.LatencyMs,
|
|
Error: meta.Error,
|
|
Revision: meta.Revision,
|
|
}
|
|
if meta.OK {
|
|
row.Data = &data
|
|
}
|
|
rows[i] = row
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
sort.Slice(rows, func(i, j int) bool { return rows[i].Alias < rows[j].Alias })
|
|
return RadarTelemtDcsData{Servers: rows}
|
|
}
|