AllUserStatsRender render data for all users or return in json format.
(w http.ResponseWriter, r *http.Request, stats []UserIDStats, rf, queriedIngesterNum int)
| 96 | |
| 97 | // AllUserStatsRender render data for all users or return in json format. |
| 98 | func AllUserStatsRender(w http.ResponseWriter, r *http.Request, stats []UserIDStats, rf, queriedIngesterNum int) { |
| 99 | sort.Sort(UserStatsByTimeseries(stats)) |
| 100 | |
| 101 | if encodings, found := r.Header["Accept"]; found && |
| 102 | len(encodings) > 0 && strings.Contains(encodings[0], "json") { |
| 103 | if err := json.NewEncoder(w).Encode(stats); err != nil { |
| 104 | http.Error(w, fmt.Sprintf("Error marshalling response: %v", err), http.StatusInternalServerError) |
| 105 | } |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | util.RenderHTTPResponse(w, struct { |
| 110 | Now time.Time `json:"now"` |
| 111 | Stats []UserIDStats `json:"stats"` |
| 112 | ReplicationFactor int `json:"replicationFactor"` |
| 113 | QueriedIngesterNum int `json:"queriedIngesterNum"` |
| 114 | }{ |
| 115 | Now: time.Now(), |
| 116 | Stats: stats, |
| 117 | ReplicationFactor: rf, |
| 118 | QueriedIngesterNum: queriedIngesterNum, |
| 119 | }, UserStatsTmpl, r) |
| 120 | } |