Add AI service dashboard endpoint
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ai-service/internal/config"
|
||||
)
|
||||
|
||||
type infraStatusResponse struct {
|
||||
@@ -17,15 +19,18 @@ type infraStatusResponse struct {
|
||||
}
|
||||
|
||||
func (s *Server) handleInfraStatus(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, loadInfraSnapshot(r, s.cfg))
|
||||
}
|
||||
|
||||
func loadInfraSnapshot(r *http.Request, cfg config.Config) infraStatusResponse {
|
||||
resp := infraStatusResponse{At: time.Now().UTC()}
|
||||
baseURL := strings.TrimRight(strings.TrimSpace(s.cfg.AIStatsSidecarURL), "/")
|
||||
baseURL := strings.TrimRight(strings.TrimSpace(cfg.AIStatsSidecarURL), "/")
|
||||
if baseURL == "" {
|
||||
resp.SidecarError = "AI stats sidecar is not configured"
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
return
|
||||
return resp
|
||||
}
|
||||
|
||||
timeout := s.cfg.AIStatsTimeout
|
||||
timeout := cfg.AIStatsTimeout
|
||||
if timeout <= 0 {
|
||||
timeout = 8 * time.Second
|
||||
}
|
||||
@@ -37,7 +42,7 @@ func (s *Server) handleInfraStatus(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
resp.Sidecar = sidecar
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
return resp
|
||||
}
|
||||
|
||||
func fetchAIStatsSidecar(ctx context.Context, baseURL string, timeout time.Duration) (map[string]any, error) {
|
||||
|
||||
Reference in New Issue
Block a user