diff --git a/api.go b/api.go index 05fbb86d7..e0d7d6891 100644 --- a/api.go +++ b/api.go @@ -1600,7 +1600,7 @@ func importExistenceColumns(qcx *Qcx, index *Index, columnIDs []uint64) error { // ShardDistribution returns an object representing the distribution of shards // across nodes for each index, distinguishing between primary and replica. // The structure of this information is [indexName][nodeID][primaryOrReplica]uint64. -// This function supports a view in the UI, and +// This function supports a view in the UI. func (api *API) ShardDistribution(ctx context.Context) map[string]interface{} { distByIndex := make(map[string]interface{}) maxShards := api.MaxShards(ctx) diff --git a/server/handler_test.go b/server/handler_test.go index 4096dc970..156817f2e 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -400,6 +400,32 @@ func TestHandler_Endpoints(t *testing.T) { } }) + t.Run("UI/shard-distribution", func(t *testing.T) { + // This tests the response structure, not the shard distribution. + w := httptest.NewRecorder() + h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/ui/shard-distribution", nil)) + if w.Code != gohttp.StatusOK { + t.Fatalf("unexpected status code: %d", w.Code) + } + + ret := mustJSONDecode(t, w.Body) + + for indexName := range ret { + indexData := ret[indexName].(map[string]interface{}) + for nodeName := range indexData { + nodeData := indexData[nodeName].(map[string]interface{}) + _, hasPrimary := nodeData["primary-shards"] + _, hasReplica := nodeData["replica-shards"] + + responseOK := hasPrimary && hasReplica + if !responseOK { + t.Fatalf("unexpected response structure") + } + } + + } + }) + t.Run("Metrics", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/metrics", nil))