mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 16:45:55 +00:00
Merge pull request #830 from alanbernstein/metrics-json-fix
Fix panicking metrics.json endpoint
This commit is contained in:
commit
1e40af7e25
2 changed files with 18 additions and 1 deletions
|
|
@ -1632,10 +1632,10 @@ func (h *Handler) handleGetMetricsJSON(w http.ResponseWriter, r *http.Request) {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
metrics := make(map[string][]*prom2json.Family)
|
||||
mfChan := make(chan *dto.MetricFamily, 60)
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
for _, node := range h.api.Hosts(r.Context()) {
|
||||
metricsURI := node.URI.String() + "/metrics"
|
||||
mfChan := make(chan *dto.MetricFamily, 60)
|
||||
err := prom2json.FetchMetricFamilies(metricsURI, mfChan, transport)
|
||||
if err != nil {
|
||||
http.Error(w, "fetching metrics: "+err.Error(), http.StatusInternalServerError)
|
||||
|
|
|
|||
|
|
@ -381,6 +381,23 @@ func TestHandler_Endpoints(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("Metrics", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/metrics", nil))
|
||||
if w.Code != gohttp.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Metrics.json", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/metrics.json", nil))
|
||||
if w.Code != gohttp.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
}
|
||||
mustJSONDecode(t, w.Body)
|
||||
})
|
||||
|
||||
t.Run("Abort no resize job", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/cluster/resize/abort", nil))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue