Skip to content

feat: Introduce pluggable inter-flow dispatch policy framework #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

LukeAVanDrie
Copy link
Contributor

@LukeAVanDrie LukeAVanDrie commented Jul 15, 2025

This work tracks #674

This pull request introduces the InterFlowDispatchPolicy framework, the third and final major component of the new pluggable flow control system outlined in our design proposals. This framework is responsible for inter-flow fairness, deciding which flow's queue gets the next opportunity to dispatch a request to the scheduler.

This change completes the two-tier policy engine by adding the strategic scheduling layer that complements the existing IntraFlowDispatchPolicy (which handles tactical, intra-queue scheduling). This allows operators to configure different fairness and utilization strategies based on their needs.

What this PR does

  • Introduces framework.InterFlowDispatchPolicy: The core contract that all inter-flow fairness plugins must implement. Its primary method, SelectQueue, inspects a PriorityBandAccessor and returns the chosen queue.

  • Introduces framework.PriorityBandAccessor: A safe, read-only abstraction that provides policies with a view into the state of all flow queues within a single priority level, without exposing mutable state.

  • Provides a Plugin Factory: A standard registration and instantiation mechanism (dispatch.MustRegisterPolicy, dispatch.NewPolicyFromName) allows new policies to be discovered and loaded by name, consistent with the existing SafeQueue and IntraFlowDispatchPolicy frameworks.

  • Adds a Conformance Test Suite: A new functional test (TestInterFlowDispatchPolicyConformance) automatically validates the basic interface contract for all registered policy plugins, ensuring they handle edge cases like nil or empty priority bands correctly.

  • Implements roundrobin Policy: A stateful, fair-queuing policy that cycles through non-empty queues sequentially. It is resilient to dynamic changes in the set of available flows and serves as a robust default for ensuring fairness between tenants or models.

  • Implements besthead Policy: A stateless, greedy policy that selects the queue containing the single highest-priority item (based on each queue's ItemComparator). This policy is useful for maximizing resource utilization when strict fairness is not the primary concern. It also validates that it is only comparing items with compatible priority types.

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

netlify bot commented Jul 15, 2025

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

Name Link
🔨 Latest commit b3d0cab
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/6877dda88344ba00082c4527
😎 Deploy Preview https://deploy-preview-1167--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 requested review from kfswain and robscott July 15, 2025 23:14
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 15, 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 15, 2025
@LukeAVanDrie
Copy link
Contributor Author

/assign @kfswain

/assign @ahg-g

@LukeAVanDrie LukeAVanDrie force-pushed the feat/flow-control-framework-plusings-inter-flow-dispatch branch from b7e1f13 to 568fdff Compare July 15, 2025 23:16
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Jul 16, 2025

/ok-to-test

@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 Jul 16, 2025
This commit introduces the `InterFlowDispatchPolicy` framework, the third and final major component of the new pluggable flow control system. This framework decouples the logic for selecting which flow's queue to service next (fairness between flows) from the core controller.

This completes the two-tier policy model, where the `InterFlowDispatchPolicy` makes the strategic decision about which flow to service, and the `IntraFlowDispatchPolicy` makes the tactical decision of which request to select from within that flow's queue.

Key components include:
- `framework.InterFlowDispatchPolicy`: The core interface that defines the contract for selecting a queue from a priority band.
- `framework.PriorityBandAccessor`: A read-only interface that provides policies with safe access to the state of all queues within a priority level.
- A factory and registration system for discovering and instantiating policy plugins by name.
- A comprehensive functional conformance test suite to validate the contract for all policy plugins.
- A `roundrobin` policy for fair, sequential queue selection.
- A `besthead` policy for greedy, utilization-focused queue selection.
@LukeAVanDrie LukeAVanDrie force-pushed the feat/flow-control-framework-plusings-inter-flow-dispatch branch from 568fdff to b3d0cab Compare July 16, 2025 17:13
@ahg-g
Copy link
Contributor

ahg-g commented Jul 17, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 17, 2025
This contrasts with the `framework.InterFlowDispatchPolicy` (not yet implemented), which is responsible for
**spatial fairness**: deciding *which flow's queue* gets the next opportunity to dispatch a request. The
`framework.IntraFlowDispatchPolicy` only operates *after* the inter-flow policy has selected a specific queue.
This contrasts with the `framework.InterFlowDispatchPolicy`, which is responsible for deciding *which flow's queue*
Copy link
Member

Choose a reason for hiding this comment

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

Is this file duplicated?

Clipboard_Screenshot_1752749548

Copy link
Collaborator

Choose a reason for hiding this comment

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

Luke makes a distinction between inter- & intra- flow. So those readme's would be distinct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inter and intra flow plugins have fairly similar contracts (SelectQueue vs SelectItem) and are organized similarly, but I wanted a distinct contributor guide colocated near the actual implementations for each extension point.

I could merge these all into one doc under framework or framework/plugins, but since contributors do not need to understand every extension point to implement one (e.g., adding a new inter flow fairness policy does not require understanding the intra flow policies), I thought the current approach was less overwhelming.

@kfswain
Copy link
Collaborator

kfswain commented Jul 17, 2025

/lgtm
/approve

Exciting to see this come together!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kfswain, 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 Jul 17, 2025
@k8s-ci-robot k8s-ci-robot merged commit 5c58ef2 into kubernetes-sigs:main Jul 17, 2025
9 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. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants