diff --git a/agent/catalog_endpoint_test.go b/agent/catalog_endpoint_test.go index 64e6c3dbe4..f97b22dbcf 100644 --- a/agent/catalog_endpoint_test.go +++ b/agent/catalog_endpoint_test.go @@ -788,6 +788,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) { // Register args := structs.TestRegisterRequestProxy(t) + args.Service.Address = "127.0.0.55" var out struct{} assert.Nil(a.RPC("Catalog.Register", args, &out)) @@ -801,6 +802,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) { nodes := obj.(structs.ServiceNodes) assert.Len(nodes, 1) assert.Equal(structs.ServiceKindConnectProxy, nodes[0].ServiceKind) + assert.Equal(args.Service.Address, nodes[0].ServiceAddress) } func TestCatalogNodeServices(t *testing.T) { diff --git a/agent/consul/health_endpoint.go b/agent/consul/health_endpoint.go index 214de777d1..38b7a9c0a5 100644 --- a/agent/consul/health_endpoint.go +++ b/agent/consul/health_endpoint.go @@ -112,22 +112,14 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc } // Determine the function we'll call - var f func(memdb.WatchSet, *state.Store) (uint64, structs.CheckServiceNodes, error) + var f func(memdb.WatchSet, *state.Store, *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) switch { case args.Connect: - f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) { - return s.CheckConnectServiceNodes(ws, args.ServiceName) - } - + f = h.serviceNodesConnect case args.TagFilter: - f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) { - return s.CheckServiceTagNodes(ws, args.ServiceName, args.ServiceTag) - } - + f = h.serviceNodesTagFilter default: - f = func(ws memdb.WatchSet, s *state.Store) (uint64, structs.CheckServiceNodes, error) { - return s.CheckServiceNodes(ws, args.ServiceName) - } + f = h.serviceNodesDefault } // If we're doing a connect query, we need read access to the service @@ -149,7 +141,7 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc &args.QueryOptions, &reply.QueryMeta, func(ws memdb.WatchSet, state *state.Store) error { - index, nodes, err := f(ws, state) + index, nodes, err := f(ws, state, args) if err != nil { return err } @@ -185,3 +177,18 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc } return err } + +// The serviceNodes* functions below are the various lookup methods that +// can be used by the ServiceNodes endpoint. + +func (h *Health) serviceNodesConnect(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) { + return s.CheckConnectServiceNodes(ws, args.ServiceName) +} + +func (h *Health) serviceNodesTagFilter(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) { + return s.CheckServiceTagNodes(ws, args.ServiceName, args.ServiceTag) +} + +func (h *Health) serviceNodesDefault(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) { + return s.CheckServiceNodes(ws, args.ServiceName) +} diff --git a/agent/dns_test.go b/agent/dns_test.go index d897a921e9..d7bb2102dd 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -1052,6 +1052,7 @@ func TestDNS_ConnectServiceLookup(t *testing.T) { // Register { args := structs.TestRegisterRequestProxy(t) + args.Address = "127.0.0.55" args.Service.ProxyDestination = "db" args.Service.Address = "" args.Service.Port = 12345 @@ -1082,6 +1083,7 @@ func TestDNS_ConnectServiceLookup(t *testing.T) { assert.True(ok) assert.Equal("foo.node.dc1.consul.", cnameRec.Hdr.Name) assert.Equal(uint32(0), srvRec.Hdr.Ttl) + assert.Equal("127.0.0.55", cnameRec.A.String()) } } diff --git a/agent/health_endpoint_test.go b/agent/health_endpoint_test.go index 688924df1b..8164be4771 100644 --- a/agent/health_endpoint_test.go +++ b/agent/health_endpoint_test.go @@ -851,7 +851,7 @@ func TestHealthConnectServiceNodes_PassingFilter(t *testing.T) { assert.Nil(err) assertIndex(t, resp) - // Should be 0 health check for consul + // Should be 1 nodes := obj.(structs.CheckServiceNodes) assert.Len(nodes, 1) })