Skip to content

Commit

Permalink
Merge pull request #2850 from CrowleyRajapakse/2025main
Browse files Browse the repository at this point in the history
Fixing issues related to model based round robin
  • Loading branch information
CrowleyRajapakse authored Feb 19, 2025
2 parents 75ed579 + 4b9621d commit d18adf4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion adapter/internal/oasparser/envoyconf/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func CreateVirtualHosts(vhostToRouteArrayMap map[string][]*routev3.Route, custom
}
virtualHosts = append(virtualHosts, virtualHost)
}
loggers.LoggerOasparser.Infof("VirtualHosts: %+v", virtualHosts)
loggers.LoggerOasparser.Debugf("VirtualHosts: %+v", virtualHosts)
return virtualHosts
}

Expand Down
24 changes: 10 additions & 14 deletions adapter/internal/oasparser/model/adapter_internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(httpRoute *gwap
vhost = string(hostName)
}
var modelBasedRoundRobin *InternalModelBasedRoundRobin
if extracted := extractModelBasedRoundRobinFromPolicy(resourceAPIPolicy, resourceParams.BackendMapping, adapterInternalAPI, resourcePath, vhost); extracted != nil {
if extracted := extractModelBasedRoundRobinFromPolicy(resourceAPIPolicy, resourceParams.BackendMapping, adapterInternalAPI, resourcePath, vhost, httpRoute.Namespace); extracted != nil {
loggers.LoggerAPI.Debugf("ModelBasedRoundRobin extracted %v", extracted)
modelBasedRoundRobin = extracted
}
Expand Down Expand Up @@ -1081,7 +1081,7 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(httpRoute *gwap
}

// ExtractModelBasedRoundRobinFromPolicy extracts the ModelBasedRoundRobin from the API Policy
func extractModelBasedRoundRobinFromPolicy(apiPolicy *dpv1alpha4.APIPolicy, backendMapping map[string]*dpv1alpha2.ResolvedBackend, adapterInternalAPI *AdapterInternalAPI, resourcePath string, vHost string) *InternalModelBasedRoundRobin {
func extractModelBasedRoundRobinFromPolicy(apiPolicy *dpv1alpha4.APIPolicy, backendMapping map[string]*dpv1alpha2.ResolvedBackend, adapterInternalAPI *AdapterInternalAPI, resourcePath string, vHost string, namespace string) *InternalModelBasedRoundRobin {
if apiPolicy == nil {
return nil
}
Expand All @@ -1101,10 +1101,9 @@ func extractModelBasedRoundRobinFromPolicy(apiPolicy *dpv1alpha4.APIPolicy, back
productionModels := apiPolicy.Spec.Override.ModelBasedRoundRobin.ProductionModels
for _, model := range productionModels {
if model.BackendRef.Name != "" {
namespace := ""
if apiPolicy.Namespace == "" {
if namespace == "" {
namespace = "default"
} else {
} else if apiPolicy.Namespace != "" {
namespace = apiPolicy.Namespace
}
backendNamespacedName := types.NamespacedName{
Expand Down Expand Up @@ -1133,10 +1132,9 @@ func extractModelBasedRoundRobinFromPolicy(apiPolicy *dpv1alpha4.APIPolicy, back
sandboxModels := apiPolicy.Spec.Override.ModelBasedRoundRobin.SandboxModels
for _, model := range sandboxModels {
if model.BackendRef.Name != "" {
namespace := ""
if apiPolicy.Namespace == "" {
if namespace == "" {
namespace = "default"
} else {
} else if apiPolicy.Namespace != "" {
namespace = apiPolicy.Namespace
}
backendNamespacedName := types.NamespacedName{
Expand Down Expand Up @@ -1175,10 +1173,9 @@ func extractModelBasedRoundRobinFromPolicy(apiPolicy *dpv1alpha4.APIPolicy, back
productionModels := apiPolicy.Spec.Default.ModelBasedRoundRobin.ProductionModels
for _, model := range productionModels {
if model.BackendRef.Name != "" {
namespace := ""
if apiPolicy.Namespace == "" {
if namespace == "" {
namespace = "default"
} else {
} else if apiPolicy.Namespace != "" {
namespace = apiPolicy.Namespace
}
backendNamespacedName := types.NamespacedName{
Expand Down Expand Up @@ -1207,10 +1204,9 @@ func extractModelBasedRoundRobinFromPolicy(apiPolicy *dpv1alpha4.APIPolicy, back
sandboxModels := apiPolicy.Spec.Default.ModelBasedRoundRobin.SandboxModels
for _, model := range sandboxModels {
if model.BackendRef.Name != "" {
namespace := ""
if apiPolicy.Namespace == "" {
if namespace == "" {
namespace = "default"
} else {
} else if apiPolicy.Namespace != "" {
namespace = apiPolicy.Namespace
}
backendNamespacedName := types.NamespacedName{
Expand Down
2 changes: 1 addition & 1 deletion gateway/enforcer/internal/extproc/ext_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func (s *ExternalProcessingServer) Process(srv envoy_service_proc_v3.ExternalPro
remainingRequestCount := 100
status := 200
for _, headerValue := range headerValues {
if headerValue.Key == "x-ratelimit-remaining-tokens" {
if headerValue.Key == "x-ratelimit-remaining-tokens" || headerValue.Key == "x-ratelimit-remaining" {
value, err := util.ConvertStringToInt(string(headerValue.RawValue))
if err != nil {
s.log.Error(err, "Unable to retrieve remaining token count by header")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ spec:
providerAPIVersion : "v1"
organization : "default"
supportedModels:
- "gpt-4o"
- "gpt-3.5"
- "gpt-4.5"
- "mistral-small-latest"
- "open-mistral-nemo"
- "mistral-large-latest"
requestModel:
in: "Body"
value: "model"
Expand Down

0 comments on commit d18adf4

Please sign in to comment.