From acbd6ec37ca7cf5a18482cd585de810cc5eec75b Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Thu, 10 Sep 2020 13:54:57 -0500 Subject: [PATCH 1/2] New channel per node --- http/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/handler.go b/http/handler.go index b6600b9f2..a0470139d 100644 --- a/http/handler.go +++ b/http/handler.go @@ -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) From 18a593008a5f779e7851de34283856121637cd64 Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Thu, 10 Sep 2020 14:19:55 -0500 Subject: [PATCH 2/2] Add simple tests for metrics endpoints --- server/handler_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/handler_test.go b/server/handler_test.go index 9dc38f8de..4a1323452 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -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))