health: use blocking queries for near query parameter

This commit is contained in:
Daniel Nephin 2021-04-19 14:34:30 -04:00
parent 2a26085b2c
commit 0558586dbd
4 changed files with 16 additions and 19 deletions

View File

@ -378,10 +378,10 @@ func New(bd BaseDeps) (*Agent, error) {
cacheName = cachetype.StreamingHealthServicesName cacheName = cachetype.StreamingHealthServicesName
} }
a.rpcClientHealth = &health.Client{ a.rpcClientHealth = &health.Client{
Cache: bd.Cache, Cache: bd.Cache,
NetRPC: &a, NetRPC: &a,
CacheName: cacheName, CacheName: cacheName,
CacheNameIngress: cachetype.HealthServicesName, CacheNameNotStreaming: cachetype.HealthServicesName,
} }
a.serviceManager = NewServiceManager(&a) a.serviceManager = NewServiceManager(&a)

View File

@ -219,13 +219,9 @@ func (s *HTTPHandlers) healthServiceNodes(resp http.ResponseWriter, req *http.Re
return nil, nil 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) 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) out, md, err := s.agent.rpcClientHealth.ServiceNodes(req.Context(), args)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -15,9 +15,9 @@ type Client struct {
MaterializerDeps MaterializerDeps MaterializerDeps MaterializerDeps
// CacheName to use for service health. // CacheName to use for service health.
CacheName string CacheName string
// CacheNameIngress is the name of the cache type to use for ingress // CacheNameNotStreaming is the name of the cache type to use for any requests
// service health. // that are not supported by the streaming backend (ex: Ingress=true).
CacheNameIngress string CacheNameNotStreaming string
} }
type NetRPC interface { type NetRPC interface {
@ -81,8 +81,8 @@ func (c *Client) getServiceNodes(
} }
cacheName := c.CacheName cacheName := c.CacheName
if req.Ingress { if req.Ingress || req.Source.Node != "" {
cacheName = c.CacheNameIngress cacheName = c.CacheNameNotStreaming
} }
raw, md, err := c.Cache.Get(ctx, cacheName, &req) raw, md, err := c.Cache.Get(ctx, cacheName, &req)
@ -105,8 +105,8 @@ func (c *Client) Notify(
ch chan<- cache.UpdateEvent, ch chan<- cache.UpdateEvent,
) error { ) error {
cacheName := c.CacheName cacheName := c.CacheName
if req.Ingress { if req.Ingress || req.Source.Node != "" {
cacheName = c.CacheNameIngress cacheName = c.CacheNameNotStreaming
} }
return c.Cache.Notify(ctx, cacheName, &req, correlationID, ch) 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 - `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 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 `?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 part of the URL as a query parameter. **Note** that using `near` will ignore
[`use_streaming_backend`](/docs/agent/options#use_streaming_backend) [`use_streaming_backend`](/docs/agent/options#use_streaming_backend) and always
is enabled, because the data is not available to sort the results. 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. - `tag` `(string: "")` **Deprecated** - Use `filter` with the `Service.Tags` selector instead.
This parameter will be removed in a future version of Consul. This parameter will be removed in a future version of Consul.