Conversation
084699d to
5eb4933
Compare
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!
|
@dkliban I addressed your comments! Thanks for the review! |
gerrod3
left a comment
There was a problem hiding this comment.
I also think this needs a changelog
|
|
||
| Counts how many WAITING/RUNNING tasks older than five seconds can run at the | ||
| same time given exclusive/shared resource reservations, then subtracts | ||
| ``num_workers``. This value is published as the OpenTelemetry ``waiting_tasks`` |
There was a problem hiding this comment.
Use single ticks for comments and changelogs.
| if conflicts: | ||
| continue |
There was a problem hiding this comment.
Tasks are FIFO. So if Task 1 takes resource A & B and Task 2 requires B & C and Task 3 requires C, then both Task 2 & 3 will be blocked even though resource C hasn't been taken yet.
So update the taken_exclusive and taken_shared for each task no matter the conflict.
| taken_exclusive.update(exclusive_resources) | ||
| taken_shared.update(shared_resources) | ||
|
|
||
| return parallel_count - num_workers |
There was a problem hiding this comment.
Does this need to do the minus num_workers? Why can't the calling function do this math?
There was a problem hiding this comment.
Thanks, good point. I'll make the caller do the math
| Counts how many WAITING/RUNNING tasks older than five seconds can run at the | ||
| same time given exclusive/shared resource reservations, then subtracts | ||
| ``num_workers``. This value is published as the OpenTelemetry ``waiting_tasks`` | ||
| gauge used by KEDA. |
There was a problem hiding this comment.
What is KEDA? If it is operator related, not sure it should be in the pulpcore comment docs.
There was a problem hiding this comment.
You're right. I am removing that terminology. I am replacing it by OpenTelemetry as this metric will serve OpenTelemetry
Note: KEDA = Kubernetes Event-Driven Autoscaling
| Setup: hold one exclusive resource with a long-running sleep, then enqueue many | ||
| more sleeps that need the same exclusive resource (they stay waiting). After the | ||
| metric's age cutoff, the published demand for this contention must rise by one | ||
| (a single runnable lane), not by one plus every waiter. | ||
|
|
||
| That is the signal KEDA should scale on: workers help only when work is | ||
| runnable, not when it is blocked on a held lock. |
There was a problem hiding this comment.
Not sure we need this long comment before the test. The test should self-describe what it is doing.
There was a problem hiding this comment.
I made sure the long comments are gone
| def test_waiting_tasks_metric_exclusive_blocks_shared_waiters( | ||
| dispatch_task, pulpcore_bindings, _read_waiting_tasks_metric_value | ||
| ): |
There was a problem hiding this comment.
Not sure this needs another test. We could just move it inside one of the previous test and have some of the queued tasks use shared_resources.
5313198 to
d07fa10
Compare
|
@gerrod3 thanks for your review. I think I addressed all your comments. Thanks again! |
gerrod3
left a comment
There was a problem hiding this comment.
Looks good, squash then lgtm.
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
d07fa10 to
ce7d292
Compare
@gerrod3 commits squashed! Thanks a lot! |
Backport to 3.115: 💚 backport PR created✅ Backport PR branch: Backported as #7943 🤖 @patchback |
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