Registry Mirror
Skip to content

Conversation

@alvaroaleman

Copy link
Copy Markdown
Contributor

This change replaces the two lane queue with a small wrapper around the controller-runtime priorityqueue. Having a single queue for both guarantees correct deduplication and avoid metrics issues like describes in #3253. It is also much simpler.

/assign @dprotaso

Changes

/kind

Fixes #

Release Note


Docs


@knative-prow

knative-prow Bot commented Sep 14, 2026

Copy link
Copy Markdown

@alvaroaleman: The label(s) kind/<kind> cannot be applied, because the repository doesn't have them.

Details

In response to this:

This change replaces the two lane queue with a small wrapper around the controller-runtime priorityqueue. Having a single queue for both guarantees correct deduplication and avoid metrics issues like describes in #3253. It is also much simpler.

/assign @dprotaso

Changes

/kind

Fixes #

Release Note


Docs


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow
knative-prow Bot requested review from Cali0707 and skonto September 14, 2026 02:40
@knative-prow knative-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 14, 2026
@knative-prow

knative-prow Bot commented Sep 14, 2026

Copy link
Copy Markdown

Hi @alvaroaleman. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Comment thread controller/controller.go
if logger := c.logger.Desugar(); logger.Core().Enabled(zapcore.DebugLevel) {
logger.Debug(fmt.Sprintf("Adding to the slow queue %s (depth(total/slow): %d/%d)",
safeKey(key), c.workQueue.Len(), c.workQueue.SlowLen()),
logger.Debug(fmt.Sprintf("Adding to the slow queue %s (depth: %d)",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not being able to log the lenght of the slow queue is the one behavioral change we can not avoid

@knative-prow

knative-prow Bot commented Sep 14, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: alvaroaleman
Once this PR has been reviewed and has the lgtm label, please ask for approval from dprotaso. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@alvaroaleman

Copy link
Copy Markdown
Contributor Author

/kind cleanup

@knative-prow knative-prow Bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 14, 2026
This change replaces the two lane queue with a small wrapper around the
controller-runtime priorityqueue. Having a single queue for both
guarantees correct deduplication and avoid metrics issues like describes
in knative#3253. It is also much simpler.

Signed-off-by: Alvaro Aleman <alvaroaleman@noreply.com>
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 11, 2026
@knative-prow-robot

Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@dprotaso dprotaso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The single-queue approach makes sense, but I found three compatibility regressions introduced by this PR that should be addressed before merging (inline below).

Validation: go test ./controller on this PR head fails in the TestEnqueue subtests because they drain after shutdown; TestEnqueueAfter also fails and then panics on double shutdown. I separately reproduced the retained-backlog shutdown hang and the metrics registration side effects.

Please replace, rather than simply delete, two_lane_queue_test.go, retaining coverage for fast/slow ordering, priority promotion, cross-lane deduplication, in-flight exclusion, rate limiting, and shutdown compatibility.

fastChan: make(chan any),
slowChan: make(chan any),
return &twoLaneRateLimitingQueue{
PriorityQueue: priorityqueue.New[any](name, func(o *priorityqueue.Opts[any]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve or update the controller's shutdown/draining contract.

RunContext still calls c.workQueue.ShutDown() and then waits until c.workQueue.Len() == 0. Unlike the previous queue, this priority queue immediately stops handing out items after shutdown but retains ready items in its tree. Any remaining ready backlog therefore makes RunContext wait forever, even after active reconciles finish.

I reproduced this on the PR head: after cancellation, ShuttingDown() was true, Len() remained 1, and Get() returned shutdown.

Please either update RunContext to match non-draining shutdown semantics or preserve draining in the wrapper. Switching to ShutDownWithDrain alone does not fix it: this implementation just calls ShutDown.


"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/controller/priorityqueue"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] The new import prevents Knative's global metrics providers from registering.

Importing priorityqueue transitively runs controller-runtime initialization hooks that call workqueue.SetProvider(...) and client-go metrics.Register(...). Both APIs accept only the first call, so these init-time registrations win before injection/sharedmain/main.go registers Knative's OpenTelemetry providers.

Passing globalMetricsProvider explicitly below preserves metrics for this particular controller queue, but does not prevent the global side effects: REST request latency remains a no-op, REST request counts go to controller-runtime's separate Prometheus registry, and other workqueues relying on the global provider use that registry rather than Knative's provider.

A standalone reproduction importing knative.dev/pkg/controller confirmed that subsequent client metric registration had no effect and a custom global workqueue provider was never called. Please use an implementation/version without these registration side effects, or resolve the metrics integration explicitly.

type twoLaneRateLimitingQueue struct {
q *twoLaneQueue
workqueue.TypedRateLimitingInterface[any]
priorityqueue.PriorityQueue[any]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep shutdown idempotent in the compatibility wrapper.

The old workqueue's ShutDown() was idempotent. The embedded replacement unconditionally calls close(w.done), so a second shutdown panics with close of closed channel. This already happens in TestEnqueueAfter, which shuts down explicitly and again in cleanup. Callers can also explicitly stop the exposed workqueue before RunContext performs its deferred shutdown.

Please guard shutdown with sync.Once (or equivalent), routing both ShutDown and ShutDownWithDrain through the same guard.

@dprotaso

Copy link
Copy Markdown
Member

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants