health: use blocking queries for near query parameter

This commit is contained in:
Daniel Nephin 2021-04-19 14:34:30 -04:00
parent 18c9e73832
commit 318bbd3e30
4 changed files with 16 additions and 19 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)
}

View File

@ -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.