diff --git a/agent/agent.go b/agent/agent.go index 493c9bd11..f7c2dff81 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -378,10 +378,10 @@ func New(bd BaseDeps) (*Agent, error) { cacheName = cachetype.StreamingHealthServicesName } a.rpcClientHealth = &health.Client{ - Cache: bd.Cache, - NetRPC: &a, - CacheName: cacheName, - CacheNameIngress: cachetype.HealthServicesName, + Cache: bd.Cache, + NetRPC: &a, + CacheName: cacheName, + CacheNameNotStreaming: cachetype.HealthServicesName, } a.serviceManager = NewServiceManager(&a) diff --git a/agent/health_endpoint.go b/agent/health_endpoint.go index cdfccd39f..6afd70528 100644 --- a/agent/health_endpoint.go +++ b/agent/health_endpoint.go @@ -219,13 +219,9 @@ func (s *HTTPHandlers) healthServiceNodes(resp http.ResponseWriter, req *http.Re return nil, nil } - useStreaming := s.agent.config.UseStreamingBackend && args.MinQueryIndex > 0 && !args.Ingress + useStreaming := s.agent.config.UseStreamingBackend && args.MinQueryIndex > 0 && !args.Ingress && args.Source.Node == "" args.QueryOptions.UseCache = s.agent.config.HTTPUseCache && (args.QueryOptions.UseCache || useStreaming) - if args.QueryOptions.UseCache && useStreaming && args.Source.Node != "" { - return nil, BadRequestError{Reason: "'near' query param can not be used with streaming"} - } - out, md, err := s.agent.rpcClientHealth.ServiceNodes(req.Context(), args) if err != nil { return nil, err diff --git a/agent/rpcclient/health/health.go b/agent/rpcclient/health/health.go index 547777337..f37626498 100644 --- a/agent/rpcclient/health/health.go +++ b/agent/rpcclient/health/health.go @@ -15,9 +15,9 @@ type Client struct { MaterializerDeps MaterializerDeps // CacheName to use for service health. CacheName string - // CacheNameIngress is the name of the cache type to use for ingress - // service health. - CacheNameIngress string + // CacheNameNotStreaming is the name of the cache type to use for any requests + // that are not supported by the streaming backend (ex: Ingress=true). + CacheNameNotStreaming string } type NetRPC interface { @@ -81,8 +81,8 @@ func (c *Client) getServiceNodes( } cacheName := c.CacheName - if req.Ingress { - cacheName = c.CacheNameIngress + if req.Ingress || req.Source.Node != "" { + cacheName = c.CacheNameNotStreaming } raw, md, err := c.Cache.Get(ctx, cacheName, &req) @@ -105,8 +105,8 @@ func (c *Client) Notify( ch chan<- cache.UpdateEvent, ) error { cacheName := c.CacheName - if req.Ingress { - cacheName = c.CacheNameIngress + if req.Ingress || req.Source.Node != "" { + cacheName = c.CacheNameNotStreaming } return c.Cache.Notify(ctx, cacheName, &req, correlationID, ch) } diff --git a/website/content/api-docs/health.mdx b/website/content/api-docs/health.mdx index 4a3f1b759..220244dc6 100644 --- a/website/content/api-docs/health.mdx +++ b/website/content/api-docs/health.mdx @@ -229,9 +229,10 @@ The table below shows this endpoint's support for - `near` `(string: "")` - Specifies a node name to sort the node list in ascending order based on the estimated round trip time from that node. Passing `?near=_agent` will use the agent's node for the sort. This is specified as - part of the URL as a query parameter. **Note** that `near` can not be used if - [`use_streaming_backend`](/docs/agent/options#use_streaming_backend) - is enabled, because the data is not available to sort the results. + part of the URL as a query parameter. **Note** that using `near` will ignore + [`use_streaming_backend`](/docs/agent/options#use_streaming_backend) and always + use blocking queries, because the data required to sort the results is not available + to the streaming backend. - `tag` `(string: "")` **Deprecated** - Use `filter` with the `Service.Tags` selector instead. This parameter will be removed in a future version of Consul.