refactor: simplify load balancing skip logic to use parsed provider field directly - #4279
Conversation
|
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughSimplifies governance plugin provider-selection by exiting early when request ChangesGovernance & Dependency Updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Confidence Score: 4/5The governance logic change is not safe to merge as-is: the large-payload routing path builds a synthetic request without a Provider field, so the new guard silently lets provider-prefixed model strings pass through load balancing instead of being left unchanged. The simplified guard is correct for the normal HTTP path but breaks the large-payload plugins/governance/main.go — specifically the interaction between Important Files Changed
Reviews (2): Last reviewed commit: "fix: governance provider load balancing ..." | Re-trigger Greptile |
| provider, modelStr, existingFallbacks := req.GetRequestFields() | ||
| if modelStr == "" { | ||
| return nil | ||
| } | ||
|
|
||
| // Model already has provider prefix pointing to a configured provider → leave it alone. | ||
| if strings.Contains(modelStr, "/") { | ||
| provider, _ := schemas.ParseModelString(modelStr, "") | ||
| // Checking valid provider when store is available; if store is nil, | ||
| // assume the prefixed model should be left unchanged. | ||
| if p.inMemoryStore != nil { | ||
| if _, ok := p.inMemoryStore.GetConfiguredProviders()[provider]; ok { | ||
| ctx.AppendRoutingEngineLog(schemas.RoutingEngineGovernance, schemas.LogLevelInfo, fmt.Sprintf("Skipping load balancing for model %s: already prefixed with configured provider %s", modelStr, provider)) | ||
| return nil | ||
| } | ||
| } else { | ||
| ctx.AppendRoutingEngineLog(schemas.RoutingEngineGovernance, schemas.LogLevelWarn, fmt.Sprintf("Skipping load balancing for model %s: provider-prefixed and no in-memory store to validate against", modelStr)) | ||
| return nil | ||
| } | ||
| if provider != "" { | ||
| ctx.AppendRoutingEngineLog(schemas.RoutingEngineGovernance, schemas.LogLevelInfo, fmt.Sprintf("Skipping load balancing for model %s: provider %s already set", modelStr, provider)) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
No test coverage for
loadBalanceProvider skip behavior
There are no existing tests that exercise the "skip load balancing when provider is already set" path, nor the large-payload synthetic-request path through runPreRequestRouting. The PR description suggests testing go test ./plugins/governance/..., but the test files don't include a case that sends a request with a non-empty provider (or a provider-prefixed model string) to loadBalanceProvider and verifies the function returns immediately without mutating the request. Given the behavioral change introduced here, a targeted table-driven test covering both the provider != "" early exit and the synthetic-request / raw-model-string case would help prevent future regressions.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Merge activity
|
046594b to
14d6864
Compare
…ield directly (#4279) ## Summary Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from `GetRequestFields()`, and bumps several indirect dependencies in the model catalog resolver module. ## Changes - The `loadBalanceProvider` function previously discarded the provider returned by `GetRequestFields()` and re-parsed it manually from the model string when a `/` was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if `provider` is already non-empty (as returned directly by `GetRequestFields()`), skip load balancing immediately. This removes the dependency on `inMemoryStore` for this check and eliminates the `strings.Contains` slash-detection path. - Bumped `cloud.google.com/go/iam` from `v1.5.3` to `v1.7.0`. - Bumped `github.com/aws/aws-sdk-go-v2` from `v1.41.7` to `v1.41.12`. - Bumped `github.com/aws/aws-sdk-go-v2/internal/configsources` from `v1.4.23` to `v1.4.28`. - Bumped `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from `v2.7.23` to `v2.7.28`. - Bumped `github.com/aws/smithy-go` from `v1.25.1` to `v1.27.1`. ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [x] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./plugins/governance/... ``` Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected. ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Optimized load balancing logic for more efficient provider selection * **Chores** * Updated dependencies including Google Cloud IAM and AWS SDK modules to latest stable versions <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ield directly (maximhq#4279) ## Summary Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from `GetRequestFields()`, and bumps several indirect dependencies in the model catalog resolver module. ## Changes - The `loadBalanceProvider` function previously discarded the provider returned by `GetRequestFields()` and re-parsed it manually from the model string when a `/` was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if `provider` is already non-empty (as returned directly by `GetRequestFields()`), skip load balancing immediately. This removes the dependency on `inMemoryStore` for this check and eliminates the `strings.Contains` slash-detection path. - Bumped `cloud.google.com/go/iam` from `v1.5.3` to `v1.7.0`. - Bumped `github.com/aws/aws-sdk-go-v2` from `v1.41.7` to `v1.41.12`. - Bumped `github.com/aws/aws-sdk-go-v2/internal/configsources` from `v1.4.23` to `v1.4.28`. - Bumped `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from `v2.7.23` to `v2.7.28`. - Bumped `github.com/aws/smithy-go` from `v1.25.1` to `v1.27.1`. ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [x] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./plugins/governance/... ``` Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected. ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Optimized load balancing logic for more efficient provider selection * **Chores** * Updated dependencies including Google Cloud IAM and AWS SDK modules to latest stable versions <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ield directly (maximhq#4279) ## Summary Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from `GetRequestFields()`, and bumps several indirect dependencies in the model catalog resolver module. ## Changes - The `loadBalanceProvider` function previously discarded the provider returned by `GetRequestFields()` and re-parsed it manually from the model string when a `/` was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if `provider` is already non-empty (as returned directly by `GetRequestFields()`), skip load balancing immediately. This removes the dependency on `inMemoryStore` for this check and eliminates the `strings.Contains` slash-detection path. - Bumped `cloud.google.com/go/iam` from `v1.5.3` to `v1.7.0`. - Bumped `github.com/aws/aws-sdk-go-v2` from `v1.41.7` to `v1.41.12`. - Bumped `github.com/aws/aws-sdk-go-v2/internal/configsources` from `v1.4.23` to `v1.4.28`. - Bumped `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from `v2.7.23` to `v2.7.28`. - Bumped `github.com/aws/smithy-go` from `v1.25.1` to `v1.27.1`. ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [x] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./plugins/governance/... ``` Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected. ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Optimized load balancing logic for more efficient provider selection * **Chores** * Updated dependencies including Google Cloud IAM and AWS SDK modules to latest stable versions <!-- end of auto-generated comment: release notes by coderabbit.ai -->

Summary
Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from
GetRequestFields(), and bumps several indirect dependencies in the model catalog resolver module.Changes
loadBalanceProviderfunction previously discarded the provider returned byGetRequestFields()and re-parsed it manually from the model string when a/was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: ifprovideris already non-empty (as returned directly byGetRequestFields()), skip load balancing immediately. This removes the dependency oninMemoryStorefor this check and eliminates thestrings.Containsslash-detection path.cloud.google.com/go/iamfromv1.5.3tov1.7.0.github.com/aws/aws-sdk-go-v2fromv1.41.7tov1.41.12.github.com/aws/aws-sdk-go-v2/internal/configsourcesfromv1.4.23tov1.4.28.github.com/aws/aws-sdk-go-v2/internal/endpoints/v2fromv2.7.23tov2.7.28.github.com/aws/smithy-gofromv1.25.1tov1.27.1.Type of change
Affected areas
How to test
go test ./plugins/governance/...Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected.
Breaking changes
Related issues
Security considerations
None.
Checklist
docs/contributing/README.mdand followed the guidelinesSummary by CodeRabbit
Improvements
Chores