feat: add stats summary and timeseries API endpoints

This commit is contained in:
William Valentin
2026-03-14 11:01:40 -07:00
parent 37f9b34197
commit 9b78d65b1d
+27
View File
@@ -209,6 +209,33 @@ func main() {
httpx.WriteJSON(w, http.StatusOK, map[string]any{"run": run, "spans": spans}) httpx.WriteJSON(w, http.StatusOK, map[string]any{"run": run, "spans": spans})
}) })
r.Get("/v1/stats/summary", func(w http.ResponseWriter, r *http.Request) {
summary, err := db.GetSummary(r.Context())
if err != nil {
httpx.WriteJSON(w, http.StatusInternalServerError, map[string]any{"error": "db_error"})
return
}
httpx.WriteJSON(w, http.StatusOK, summary)
})
r.Get("/v1/stats/timeseries", func(w http.ResponseWriter, r *http.Request) {
window := r.URL.Query().Get("window")
switch window {
case "1h", "6h", "24h", "7d":
case "":
window = "1h"
default:
httpx.WriteJSON(w, http.StatusBadRequest, map[string]any{"error": "invalid_window"})
return
}
timeseries, err := db.GetTimeseries(r.Context(), window)
if err != nil {
httpx.WriteJSON(w, http.StatusInternalServerError, map[string]any{"error": "db_error"})
return
}
httpx.WriteJSON(w, http.StatusOK, timeseries)
})
log.Printf("query-api listening on %s", addr) log.Printf("query-api listening on %s", addr)
log.Fatal(http.ListenAndServe(addr, r)) log.Fatal(http.ListenAndServe(addr, r))
} }