diff --git a/agent/ui_endpoint.go b/agent/ui_endpoint.go index cf1206327d..6be13b3845 100644 --- a/agent/ui_endpoint.go +++ b/agent/ui_endpoint.go @@ -261,7 +261,12 @@ RPC: } summaries, _ := summarizeServices(out.Dump, s.agent.config, args.Datacenter) - return prepSummaryOutput(summaries, false), nil + + prepped := prepSummaryOutput(summaries, false) + if prepped == nil { + prepped = make([]*ServiceSummary, 0) + } + return prepped, nil } // UIServiceTopology returns the list of upstreams and downstreams for a Connect enabled service. @@ -449,6 +454,8 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig, dc s func prepSummaryOutput(summaries map[structs.ServiceName]*ServiceSummary, excludeSidecars bool) []*ServiceSummary { var resp []*ServiceSummary + // Ensure at least a zero length slice + resp = make([]*ServiceSummary, 0) // Collect and sort resp for display for _, sum := range summaries { diff --git a/agent/ui_endpoint_test.go b/agent/ui_endpoint_test.go index 280c012309..c0bb01dbbc 100644 --- a/agent/ui_endpoint_test.go +++ b/agent/ui_endpoint_test.go @@ -629,7 +629,18 @@ func TestUIGatewayServiceNodes_Terminating(t *testing.T) { }, } require.NoError(t, a.RPC("Catalog.Register", &arg, ®Output)) + } + { + // Request without having registered the config-entry, shouldn't respond with null + req, _ := http.NewRequest("GET", "/v1/internal/ui/gateway-services-nodes/terminating-gateway", nil) + resp := httptest.NewRecorder() + obj, err := a.srv.UIGatewayServicesNodes(resp, req) + require.Nil(t, err) + require.NotNil(t, obj) + } + + { // Register terminating-gateway config entry, linking it to db and redis (does not exist) args := &structs.TerminatingGatewayConfigEntry{ Name: "terminating-gateway",