diff --git a/go/vt/vtadmin/api.go b/go/vt/vtadmin/api.go index aef57176ea9..9ee6790c13c 100644 --- a/go/vt/vtadmin/api.go +++ b/go/vt/vtadmin/api.go @@ -133,14 +133,27 @@ func (api *API) GetGates(ctx context.Context, req *vtadminpb.GetGatesRequest) (* go func(c *cluster.Cluster) { defer wg.Done() - g, err := c.Discovery.DiscoverVTGates(ctx, []string{}) + gs, err := c.Discovery.DiscoverVTGates(ctx, []string{}) if err != nil { er.RecordError(err) return } m.Lock() - gates = append(gates, g...) + + for _, g := range gs { + gates = append(gates, &vtadminpb.VTGate{ + Cell: g.Cell, + Cluster: &vtadminpb.Cluster{ + Id: c.ID, + Name: c.Name, + }, + Hostname: g.Hostname, + Keyspaces: g.Keyspaces, + Pool: g.Pool, + }) + } + m.Unlock() }(c) } diff --git a/go/vt/vtadmin/api_test.go b/go/vt/vtadmin/api_test.go index d2f7840d579..64ac898a489 100644 --- a/go/vt/vtadmin/api_test.go +++ b/go/vt/vtadmin/api_test.go @@ -69,9 +69,32 @@ func TestGetGates(t *testing.T) { Hostname: "cluster1-gate3", }, } - fakedisco1.AddTaggedGates(nil, cluster1Gates...) + expectedCluster1Gates := []*vtadminpb.VTGate{ + { + Cluster: &vtadminpb.Cluster{ + Id: cluster1.ID, + Name: cluster1.Name, + }, + Hostname: "cluster1-gate1", + }, + { + Cluster: &vtadminpb.Cluster{ + Id: cluster1.ID, + Name: cluster1.Name, + }, + Hostname: "cluster1-gate2", + }, + { + Cluster: &vtadminpb.Cluster{ + Id: cluster1.ID, + Name: cluster1.Name, + }, + Hostname: "cluster1-gate3", + }, + } + fakedisco2 := fakediscovery.New() cluster2 := &cluster.Cluster{ ID: "c2", @@ -83,19 +106,28 @@ func TestGetGates(t *testing.T) { Hostname: "cluster2-gate1", }, } - fakedisco2.AddTaggedGates(nil, cluster2Gates...) + expectedCluster2Gates := []*vtadminpb.VTGate{ + { + Cluster: &vtadminpb.Cluster{ + Id: cluster2.ID, + Name: cluster2.Name, + }, + Hostname: "cluster2-gate1", + }, + } + api := NewAPI([]*cluster.Cluster{cluster1, cluster2}, grpcserver.Options{}, http.Options{}) ctx := context.Background() resp, err := api.GetGates(ctx, &vtadminpb.GetGatesRequest{}) assert.NoError(t, err) - assert.ElementsMatch(t, append(cluster1Gates, cluster2Gates...), resp.Gates) + assert.ElementsMatch(t, append(expectedCluster1Gates, expectedCluster2Gates...), resp.Gates) resp, err = api.GetGates(ctx, &vtadminpb.GetGatesRequest{ClusterIds: []string{cluster1.ID}}) assert.NoError(t, err) - assert.ElementsMatch(t, cluster1Gates, resp.Gates) + assert.ElementsMatch(t, expectedCluster1Gates, resp.Gates) fakedisco1.SetGatesError(true)