Repository navigation
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
The metrics port answers `GET /task-queue/{queue}/demand?class=<name>` with the due, heartbeat-expired and running tasks of a queue and their sum, `demand`, for autoscalers such as KEDA. Queues name their resource demand ranges with `TaskQueueRegistry::register_demand_classes`; without a class the whole queue is counted. An unknown queue or class is a 404 without a query, read-only maintenance mode reports 0 for any queue and class, and each process keeps a count for 5 seconds per queue and class. The count is one statement on the read pool and resolves heartbeat timeouts like the pick.
The metrics port is an axum router now: `/health` answers `OK`, `/metrics` and every other path return the Prometheus text as before, and Lakekeeper runs the histogram upkeep itself.
`task_queue_name_status_idx` becomes `(queue_name, status, scheduled_for, task_id, COALESCE(resource_demand, 0))`, and the pick passes both range bounds as non-null values, so a worker whose range has nothing due skips the due tasks of other ranges in the index, also in a generic plan, and the index order is the pick's order. The index is rebuilt in `20261015120000`, which is not in a release; a development database that already applied it must be dropped and created again.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
c-thiel
force-pushed
the
ct/task-queue-demand
branch
from
October 26, 2026 07:43
ddc542c to
286ce37
Compare
Contributor
✅ PR Title Formatted CorrectlyThe title of this PR match the correct format. Thank you! |
Member
Author
|
Replaced by #2187, which carries the same change on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2183.
An autoscaler such as KEDA can now ask how many workers a task queue needs, per demand class. The metrics port (default
9000) answersGET /task-queue/{queue}/demand?class=<name>with counts only:{"demand": 7, "due": 4, "heartbeat-expired": 1, "running": 2}due: scheduled and due, what a pick can take now.running: running or asked to stop with a live heartbeat.heartbeat-expired: running or asked to stop with an expired heartbeat (per-project and per-warehouse timeouts as in the pick).demandis the sum, the value KEDA scales on.TaskQueueRegistry::register_demand_classes; withoutclassthe whole queue is counted. Legacy queue names are counted and accepted in the path.404without a query. Database error:503. Read-only maintenance mode: all counts0for any queue and class (such a process registers no built-in queues)./metrics; the answer has no project, warehouse or table names.The metrics port is now an axum router:
/healthanswersOK,/metricsand every other path still return the Prometheus text, so scrape configs do not change. Lakekeeper runs the histogram upkeep itself, which the exporter's own listener did before.Index:
task_queue_name_status_idxbecomes(queue_name, status, scheduled_for, task_id, (COALESCE(resource_demand, 0))), and the pick passes both range bounds as non-null values. A worker whose class has nothing due no longer reads the due tasks of all other classes from the table on every poll (measured 190-620 ms → 10 ms with 200 k due tasks), also in a generic plan. Withtask_idin the key the index order is the pick's order, so a batch of tasks with onescheduled_forneeds no sort (10-12 ms → 0.06 ms per pick).Migration: the index is rebuilt in
20261015120000, which is not in a release. A development database that already applied it fails the checksum check at startup and must be dropped and created again.Tests: sqlx test with exact counts at the range edges, NULL demand, due vs. not yet due,
running/should-stop/ expired heartbeats, a second project with its own heartbeat timeout, legacy names and an empty range;EXPLAINof the pick and the due count as generic plans (range inIndex Cond, noFilter, noSortin the pick); endpoint tests (JSON shape, cache per class, 404 without a query, read-only, 503 not cached); registry lookup and class validation; metrics router paths.Release notes
GET /task-queue/{queue}/demandon the metrics port, optionally per demand class (?class=<name>). The answer is JSON withdemand,due,heartbeat-expiredandrunning, cached for 5 seconds per replica. See Monitoring → Task Queue Demand.Downstream follow-up
CatalogStore::task_queue_demand_impl(required) andCatalogTaskOps::task_queue_demand. Plus usesPostgresBackendonly, so nothing to implement there.TaskQueueRegistry::register_demand_classesand the typesTaskDemandClass,TaskQueueDemand,TaskQueueDemandRequest. Plus registers its size classes with it afterregister_queuefor compaction (the catalog registers the compaction queue even with 0 workers, so the catalog pods answer for every class).QueueRegistrationis unchanged.lakekeeper::metrics::get_axum_layer_and_install_recorder(port)loses its cancellation-token argument and returns aMetricsServer(serve it withMetricsServer::serve(routes, token)) instead of anExporterFuture. Plus does not call it.