test: refactor record_waiting_tasks_metric metric - #7938
Conversation
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
084699d to
5eb4933
Compare
4ca38a1 to
5eb4933
Compare
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
5eb4933 to
be2ef80
Compare
| return int(process.stdout.decode().strip()) | ||
|
|
||
|
|
||
| def test_waiting_tasks_metric_resource_contention(dispatch_task, pulpcore_bindings): |
There was a problem hiding this comment.
The pulpcore-manager shell subprocess isn't needed here. Since the functional tests already run inside a Django-initialized environment, you can import and call the function directly:
from pulpcore.tasking.redis_worker import count_waiting_tasks_for_metric
def _read_waiting_tasks_metric_value(num_workers=1):
return count_waiting_tasks_for_metric(num_workers)This avoids spawning a full Django process six times across the test suite and makes failures easier to debug (you get a real traceback instead of stderr from a subprocess).
There was a problem hiding this comment.
Done, the last commit is importing directly count_waiting_tasks_for_metric
|
|
||
| @pytest.mark.long_running | ||
| @pytest.mark.parallel | ||
| def test_worker_cleanup_on_missing_worker(dispatch_task, monitor_task, pulpcore_bindings): |
There was a problem hiding this comment.
Missing test case: shared-shared concurrency. The three tests here cover exclusive-exclusive, two independent exclusive lanes, and exclusive-blocks-shared — but none verify that multiple tasks needing only shared access to the same resource are all counted as parallel lanes.
That's the core correctness property of shared locks. If someone accidentally added shared resources to taken_exclusive in the algorithm, only this test would catch it.
Something like: dispatch N tasks all using shared_resources=[same_resource] (no exclusive holder), and assert the metric rises by N, not 1.
There was a problem hiding this comment.
Done, the last test is adding this scenario. Thank for pointing that out!
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
|
@dkliban I addressed your comments! Thanks for the review! |
Fixes: #7940
Addresses: https://redhat.atlassian.net/browse/PULP-2150
Problem
KEDA scales pulp-workers from OpenTelemetry waiting_tasks (emitted by Redis worker record_waiting_tasks_metric). Today that is roughly (WAITING + RUNNING) − workers, which ignores resource locks. Under exclusive contention, queue depth ≫ useful parallelism → over-scale → DB pool saturation → crash loops / orphan Redis locks (incident 2026-07-24).
Fix direction: the metric
pulpcore/pulpcore/tasking/redis_worker.py
Line 321 in dfd517c
Solution
📜 Checklist
See: Pull Request Walkthrough