Skip to content

Conversation

@git-malu
Copy link
Collaborator

What type of PR is this?
/kind enhancement

What this PR does / why we need it:
build a general abstraction layer for both ModelRoute/ModelServer and Gateway API/Inference Extension
Which issue(s) this PR fixes:
Fixes #
#546
Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from git-malu. For more information see the Kubernetes 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

@gemini-code-assist
Copy link

Summary of Changes

Hello @git-malu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a fundamental architectural enhancement by creating a generic abstraction layer for routing and backend management. This change aims to provide a unified way to handle both ModelRoute/ModelServer and Gateway API/Inference Extension resources, making the router more flexible, maintainable, and easier to extend with new routing and backend types in the future. The core routing logic is now streamlined through this abstraction, reducing duplication and improving clarity.

Highlights

  • Abstraction Layer Introduction: A new abstraction layer has been introduced to unify the representation and handling of routing and backend services, specifically for ModelRoute/ModelServer and Gateway API/Inference Extension.
  • Refactored Routing Logic: The core doLoadbalance function in the router has been significantly refactored to leverage the new abstraction layer, simplifying the logic for matching routes and selecting backends.
  • New Abstraction Package: A new abstraction package has been added, containing unified type definitions for Route and Backend, along with conversion functions to transform existing API objects into these abstract types.
  • Datastore Enhancements: The datastore interface and implementation have been extended with new methods to retrieve and match abstract routes and backends, centralizing the data access for the new abstraction.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a general abstraction layer for handling both ModelRoute/ModelServer and Gateway API/Inference Extension resources. This is a significant improvement, as it unifies the routing and backend selection logic, making the doLoadbalance function in the router much cleaner and more maintainable. The new abstraction package effectively encapsulates the differences between the various resource types.

Overall, the changes are well-structured and achieve the stated goal of building a general abstraction layer. The conversion logic in converter.go is clear, and the refactoring in router.go demonstrates the benefits of this abstraction.

return false
}
if sm.Regex != nil {
matched, _ := regexp.MatchString(*sm.Regex, value)

Choose a reason for hiding this comment

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

medium

The error returned by regexp.MatchString is ignored here. If a user provides an invalid regular expression pattern in an HTTPRoute, this could lead to unexpected routing behavior (e.g., the regex might silently fail to match when it should, or vice-versa). It's best practice to at least log such errors to aid in debugging configuration issues.

matched, err := regexp.MatchString(*sm.Regex, value)
		if err != nil {
			klog.Errorf("invalid regex pattern '%s': %v", *sm.Regex, err)
			return false // Or handle as appropriate, e.g., treat as no match
		}
		if !matched {

Comment on lines +183 to +186
port := int32(0)
if len(ip.Spec.TargetPorts) > 0 {
port = int32(ip.Spec.TargetPorts[0].Number)
}

Choose a reason for hiding this comment

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

medium

If ip.Spec.TargetPorts is empty, the port variable is initialized to 0. While this might be a valid default in some contexts, it's worth considering if a port of 0 is always a valid or intended value for a backend. If 0 is an invalid port, this could lead to connection issues downstream. It might be safer to return an error if no target ports are defined, or to ensure that 0 is handled gracefully by consumers of this Backend abstraction.

Comment on lines +320 to +327
// Get PDGroup from abstracted backend
var pdGroup *v1alpha1.PDGroup
if modelServer != nil && modelServer.Spec.WorkloadSelector != nil {
pdGroup = modelServer.Spec.WorkloadSelector.PDGroup
if backend.PDGroup != nil {
pdGroup = &v1alpha1.PDGroup{
GroupKey: backend.PDGroup.GroupKey,
PrefillLabels: backend.PDGroup.PrefillLabels,
DecodeLabels: backend.PDGroup.DecodeLabels,
}

Choose a reason for hiding this comment

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

medium

The PDGroup is converted from abstraction.PDGroupConfig back to v1alpha1.PDGroup here. This indicates a slight 'leak' in the abstraction, as the framework.Context still expects the concrete v1alpha1.PDGroup type. Ideally, the framework.Context and related scheduler components should also be updated to work with the abstract PDGroupConfig to fully leverage the abstraction layer. While functional, this conversion adds a small amount of overhead and couples the abstract layer to the concrete API type more than necessary.

Signed-off-by: Lu Ma <malu17@huawei.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

router: build a general abstraction layer for both ModelRoute/ModelServer and Gateway API/Inference Extension

2 participants