Add gateway implementations for custom LLM provider feature#2456
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
gateway/gateway-controller/api/management-openapi.yaml (1)
5569-5588: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winConsider adding a
patternconstraint onversion.Other version fields in this spec (
APIConfigData.version,LLMProviderConfigData.version,LLMProxyConfigData.version) enforcepattern: '^v\d+\.\d+$', andPolicy.versionenforces'^v\d+$'. The newLLMProviderTemplateData.versionfield has no format constraint, so malformed values (e.g.,1.0,latest) could be accepted and persisted as template metadata.📝 Suggested diff
version: type: string description: | Template content version (e.g. v1.0). Multiple versions of the same groupId can coexist; defaults to v1.0 when omitted. + pattern: '^v\d+\.\d+$' example: v1.0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@gateway/gateway-controller/api/management-openapi.yaml` around lines 5569 - 5588, The new LLMProviderTemplateData.version field is missing the same format validation used by other version fields in the OpenAPI spec. Update the version property in management-openapi.yaml to add a pattern constraint consistent with the existing version schema (matching the other template/config version fields), so only valid version strings are accepted and persisted; keep the change localized to the LLMProviderTemplateData.version definition.gateway/gateway-controller/pkg/models/llm_provider_template.go (1)
46-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCorrect fallback behavior; consider extracting shared helper.
GetGroupID,GetVersion, andGetManagedByeach repeat the same nil-check/trim/fallback pattern. A shared private helper would reduce duplication and keep the trimming semantics consistent if this logic changes later.♻️ Suggested refactor
+func stringOrDefault(v *string, fallback string) string { + if v != nil { + if trimmed := strings.TrimSpace(*v); trimmed != "" { + return trimmed + } + } + return fallback +} + func (t *StoredLLMProviderTemplate) GetGroupID() string { - if t.Configuration.Spec.GroupId != nil { - if v := strings.TrimSpace(*t.Configuration.Spec.GroupId); v != "" { - return v - } - } - return t.Configuration.Metadata.Name + return stringOrDefault(t.Configuration.Spec.GroupId, t.Configuration.Metadata.Name) } func (t *StoredLLMProviderTemplate) GetVersion() string { - if t.Configuration.Spec.Version != nil { - if v := strings.TrimSpace(*t.Configuration.Spec.Version); v != "" { - return v - } - } - return DefaultTemplateVersion + return stringOrDefault(t.Configuration.Spec.Version, DefaultTemplateVersion) } func (t *StoredLLMProviderTemplate) GetManagedBy() string { - if t.Configuration.Spec.ManagedBy != nil { - if p := strings.TrimSpace(*t.Configuration.Spec.ManagedBy); p != "" { - return p - } - } - return DefaultTemplateManagedBy + return stringOrDefault(t.Configuration.Spec.ManagedBy, DefaultTemplateManagedBy) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@gateway/gateway-controller/pkg/models/llm_provider_template.go` around lines 46 - 72, GetGroupID, GetVersion, and GetManagedBy all duplicate the same nil-check, trim, and fallback logic in StoredLLMProviderTemplate. Extract that shared behavior into a private helper on StoredLLMProviderTemplate that accepts the optional string pointer and fallback value, then have all three methods delegate to it so the trimming semantics stay consistent and future changes only need to be made in one place.gateway/gateway-controller/pkg/utils/llm_deployment.go (1)
595-616: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCorrect defaulting logic and placement.
normalizeTemplateDefaultsis invoked after parsing and before render/validation, so validation and returned config both reflect the defaults — matches the documented OpenAPI fallback contract (groupId → metadata.name, version → v1.0, managedBy → customer) and is covered by tests.Note: the nil-check/trim/fallback logic here duplicates the same pattern in
StoredLLMProviderTemplate.GetGroupID/GetVersion/GetManagedBy(gateway/gateway-controller/pkg/models/llm_provider_template.go). Consider exposing a small shared helper frommodels(e.g., aNormalizeOptionalString(v *string, fallback string) *string) that both this function and the getters can use, to avoid the fallback semantics drifting between the two packages over time.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@gateway/gateway-controller/pkg/utils/llm_deployment.go` around lines 595 - 616, The defaulting logic in normalizeTemplateDefaults is duplicated in StoredLLMProviderTemplate.GetGroupID/GetVersion/GetManagedBy, which risks the fallback behavior drifting over time. Extract the nil/trim/fallback handling into a shared helper in models, such as a NormalizeOptionalString-style function, and have both normalizeTemplateDefaults and the StoredLLMProviderTemplate getters use that shared helper so groupId, version, and managedBy stay consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@gateway/gateway-controller/api/management-openapi.yaml`:
- Around line 5569-5588: The new LLMProviderTemplateData.version field is
missing the same format validation used by other version fields in the OpenAPI
spec. Update the version property in management-openapi.yaml to add a pattern
constraint consistent with the existing version schema (matching the other
template/config version fields), so only valid version strings are accepted and
persisted; keep the change localized to the LLMProviderTemplateData.version
definition.
In `@gateway/gateway-controller/pkg/models/llm_provider_template.go`:
- Around line 46-72: GetGroupID, GetVersion, and GetManagedBy all duplicate the
same nil-check, trim, and fallback logic in StoredLLMProviderTemplate. Extract
that shared behavior into a private helper on StoredLLMProviderTemplate that
accepts the optional string pointer and fallback value, then have all three
methods delegate to it so the trimming semantics stay consistent and future
changes only need to be made in one place.
In `@gateway/gateway-controller/pkg/utils/llm_deployment.go`:
- Around line 595-616: The defaulting logic in normalizeTemplateDefaults is
duplicated in StoredLLMProviderTemplate.GetGroupID/GetVersion/GetManagedBy,
which risks the fallback behavior drifting over time. Extract the
nil/trim/fallback handling into a shared helper in models, such as a
NormalizeOptionalString-style function, and have both normalizeTemplateDefaults
and the StoredLLMProviderTemplate getters use that shared helper so groupId,
version, and managedBy stay consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 38d5cf89-042b-4b5e-bbf7-216ed87092df
📒 Files selected for processing (13)
gateway/gateway-controller/api/management-openapi.yamlgateway/gateway-controller/default-llm-provider-templates/anthropic-template.yamlgateway/gateway-controller/default-llm-provider-templates/awsbedrock-template.yamlgateway/gateway-controller/default-llm-provider-templates/azureaifoundry-template.yamlgateway/gateway-controller/default-llm-provider-templates/azureopenai-template.yamlgateway/gateway-controller/default-llm-provider-templates/gemini-template.yamlgateway/gateway-controller/default-llm-provider-templates/mistral-template.yamlgateway/gateway-controller/default-llm-provider-templates/openai-template.yamlgateway/gateway-controller/pkg/api/management/generated.gogateway/gateway-controller/pkg/models/llm_provider_template.gogateway/gateway-controller/pkg/models/llm_provider_template_test.gogateway/gateway-controller/pkg/utils/llm_deployment.gogateway/gateway-controller/pkg/utils/llm_deployment_test.go
4d2febd to
a387ee9
Compare
Dependency Validation ResultsDependency name: github.com/go-playground/validator/v10 Dependency name: github.com/go-viper/mapstructure/v2 Dependency name: github.com/golang-jwt/jwt/v5 Dependency name: github.com/google/uuid Dependency name: github.com/gorilla/websocket Dependency name: github.com/jackc/pgx/v5 Dependency name: github.com/knadh/koanf/parsers/toml/v2 Dependency name: github.com/knadh/koanf/providers/env Dependency name: github.com/knadh/koanf/providers/file Dependency name: github.com/knadh/koanf/v2 Dependency name: github.com/mattn/go-sqlite3 Dependency name: github.com/microsoft/go-mssqldb Dependency name: github.com/oapi-codegen/runtime Dependency name: github.com/pb33f/libopenapi Dependency name: github.com/stretchr/testify Dependency name: golang.org/x/crypto Dependency name: gopkg.in/yaml.v3 Next Steps
|
Dependency Validation ResultsDependency name: github.com/go-playground/validator/v10 Dependency name: github.com/go-viper/mapstructure/v2 Dependency name: github.com/golang-jwt/jwt/v5 Dependency name: github.com/google/uuid Dependency name: github.com/gorilla/websocket Dependency name: github.com/jackc/pgx/v5 Dependency name: github.com/knadh/koanf/parsers/toml/v2 Dependency name: github.com/knadh/koanf/providers/env Dependency name: github.com/knadh/koanf/providers/file Dependency name: github.com/knadh/koanf/v2 Dependency name: github.com/mattn/go-sqlite3 Dependency name: github.com/microsoft/go-mssqldb Dependency name: github.com/oapi-codegen/runtime Dependency name: github.com/pb33f/libopenapi Dependency name: github.com/stretchr/testify Dependency name: golang.org/x/crypto Dependency name: gopkg.in/yaml.v3 Next Steps
|
20807ac to
6805b3d
Compare
Dependency Validation ResultsDependency name: github.com/oapi-codegen/runtime Dependency name: github.com/go-playground/validator/v10 Dependency name: github.com/oapi-codegen/runtime Next Steps
|
Dependency Validation ResultsDependency name: github.com/oapi-codegen/runtime Dependency name: github.com/pb33f/libopenapi Dependency name: github.com/go-playground/validator/v10 Dependency name: github.com/oapi-codegen/runtime Next Steps
|
6805b3d to
14a6c09
Compare
Dependency Validation ResultsDependency name: github.com/pb33f/libopenapi Dependency name: github.com/go-playground/validator/v10 |
Purpose
Extends the LLM provider template model with three new spec fields: groupId, managedBy, and version, and wires them through the gateway-controller management API.
Fixed : #2523 as well