Skip to content

Conversation

LukeAVanDrie
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:
This PR introduces several cleanups and a critical performance improvement to the Flow Control layer:

  1. Performance: Significantly reduces memory allocations and GC pressure on the hot path in ShardProcessor.dispatchCycle by avoiding logger.WithValues. Structured log fields are now passed directly to the logging methods, minimizing temporary object creation.
  2. Robustness: Removes a potential panic in FlowController.selectDistributionCandidates when a ManagedQueue cannot be retrieved from a shard. The controller now logs an error and safely skips the problematic shard.
  3. Robustness: Improves error handling in ShardProcessor.dispatchItem when an item is not found during removal. This is now treated as a non-fatal condition as it indicates a benign race with the expiry cleanup loop.
  4. Cleanup: Removes the nil check for the request in FlowController.EnqueueAndWait, trusting the caller to provide a valid instance. The associated test case has also been removed.
  5. Documentation: Updates to package and internal documentation for clarity and consistency.

Does this PR introduce a user-facing change?:

NONE

This commit completes the refactoring of the request lifecycle by
making context management explicit and adapting the FlowController to
the new internal components.

This is the final commit in a series:
1. Harden FlowItem for concurrent finalization.
2. Adapt ShardProcessor to new FlowItem lifecycle.
3. This commit: Introduce explicit context handling.

Key changes:
- The `FlowControlRequest` interface no longer includes `Context()`.
- `FlowController.EnqueueAndWait` now accepts a `context.Context` as
  its first argument, making the request lifecycle explicit and
  caller-controlled.
- The controller now actively monitors this context and will initiate
  an "asynchronous finalization" if the context expires after an item
  has been handed off to a processor.
- Adds extensive integration and concurrency tests to validate the new
  end-to-end lifecycle management under contention.
- Overhaul package-level documentation in doc.go files for controller
  and internal packages to clarify architecture, concurrency, and
	ownership.
- Refine GoDoc and inline comments across all files for clarity,
  consistency, and to better explain intent.
- Remove low signal-to-noise inline comments.
- Adjust log levels for better signal-to-noise ratio (e.g., TRACE for
  high-frequency events).
- Remove unnecessary logger.WithValues calls in hot paths within the
  ShardProcessor to reduce allocation overhead.
- Remove overly defensive nil check in EnqueueAndWait.
- Remove config deep copy in NewFlowController (we already pass by
  value)
- Replace a panic with logger.Error in distributeRequest for a
  ManagedQueue invariant violation.
@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Oct 14, 2025
Copy link

netlify bot commented Oct 14, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 62a5ec4
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/68eecb78ca2c6900082c8ee7
😎 Deploy Preview https://deploy-preview-1726--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 14, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @LukeAVanDrie. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 14, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Oct 14, 2025

/ok-to-test
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot 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 Oct 14, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 14, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahg-g, LukeAVanDrie

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 14, 2025
@k8s-ci-robot k8s-ci-robot merged commit 7adf09e into kubernetes-sigs:main Oct 14, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants