Limits support for large query results in Consul catalog API
0 reputation · 31 Jan 2020, 18:08 UTC
0 reputation · 31 Jan 2020, 18:08 UTC
To retrieve large service or key/value listings from Consul without exhausting client memory or network bandwidth while preserving the ability to react to changes in real time.
The HTTP API exposes blocking queries via index and wait parameters, which throttle request frequency but still return the full payload. Catalog endpoints such as /v1/catalog/services and KV endpoints like /v1/kv/<prefix>?recurse=true lack any documented limit, offset, or cursor parameters. Clients must either filter aggressively or perform client‑side pagination after the entire result set is received.
HashiCorp’s documentation does not indicate any plan to introduce native pagination for catalog or KV queries. This leaves large datasets as a consumer‑side implementation detail and raises questions about how a future pagination feature would coexist with existing blocking query semantics.
limit or cursor‑based paging mechanism to catalog and KV endpoints?index and wait?Consul’s catalog and KV endpoints do not support limit, offset, or cursor‑based pagination because the server is designed to return a complete, consistent snapshot with minimal internal state. Adding pagination would require the server to maintain a stable view of the key space across multiple requests, which conflicts with Consul’s goal of low‑latency, stateless reads.
index and wait parameters rely on a single global index to signal any change in the queried set. If pagination were added, each page would need to carry the same index; otherwise a change occurring between pages could be missed, breaking the guarantee of the blocking query.A feasible design would return a next-token that encodes both the current global index and a position within the sorted result set (e.g., the hash of the last key returned). The client would reuse that token with the same wait value, allowing the server to resume the scan from where it left off while still honoring the blocking semantics: a change to any entry in the paginated set would increment the global index, causing the waiting request to return.
Introducing pagination adds a small amount of state (either token‑based or short‑lived server session) to an otherwise stateless, HTTP‑only interface. The trade‑off is modest implementation complexity versus the benefit of bounded response sizes for large catalogs or KV trees. For most deployments the current approach—client‑side filtering or incremental key prefixes—is sufficient, but for very large service meshes pagination would reduce memory and bandwidth pressure.
consul 1.14) and confirm that the catalog and KV endpoint descriptions omit limit, offset, or cursor parameters.curl -s http://localhost:8500/v1/catalog/services?limit=5 and verify that the response contains all services, not just five, and that no pagination links or headers are present.curl -s "http://localhost:8500/v1/catalog/services?index=10&wait=10s". Observe that the full payload is returned when the index changes; adding ?limit=5 to the same request shows the limit is ignored, confirming pagination does not affect blocking behavior.Note: The above verification assumes you are running a recent Consul release (1.12+). If you are on an older version, the behavior may differ; please confirm your Consul version before proceeding.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.