feat: add stats summary and timeseries API endpoints
This commit is contained in:
@@ -209,6 +209,33 @@ func main() {
|
||||
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.Fatal(http.ListenAndServe(addr, r))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user