[TT-15595] temporarily remove upstream target from load balancing#7524
Conversation
…able to keep them in the db on saving
…t-from-load-balancing
…t-from-load-balancing
…y-remove-upstream-target-from-load-balancing
🎯 Recommended Merge TargetsBased on JIRA ticket TT-15595: Temporarily remove upstream target from load balancing Fix Version: Tyk 5.11.0
Required:
📋 Workflow
|
|
API Changes --- prev.txt 2025-11-07 15:07:50.598875916 +0000
+++ current.txt 2025-11-07 15:07:40.626795263 +0000
@@ -128,6 +128,8 @@
ErrUpstreamOAuthAuthorizationTypeRequired = errors.New("upstream OAuth authorization type is required")
// ErrInvalidUpstreamOAuthAuthorizationType is the error to return when configured OAuth authorization type is invalid.
ErrInvalidUpstreamOAuthAuthorizationType = errors.New("invalid OAuth authorization type")
+ // ErrAllLoadBalancingTargetsZeroWeight is the error to return when all load balancing targets have weight 0.
+ ErrAllLoadBalancingTargetsZeroWeight = errors.New("all load balancing targets have weight 0, at least one target must have weight > 0")
)
var DefaultValidationRuleSet = ValidationRuleSet{
&RuleUniqueDataSourceNames{},
@@ -135,6 +137,7 @@
&RuleValidateIPList{},
&RuleValidateEnforceTimeout{},
&RuleUpstreamAuth{},
+ &RuleLoadBalancingTargets{},
}
var ErrAllAuthSourcesDisabled = "all auth sources are disabled for %s, at least one of header/cookie/query must be enabled"
var ErrDuplicateDataSourceName = errors.New("duplicate data source names are not allowed")
@@ -1242,6 +1245,14 @@
func (r *RuleAtLeastEnableOneAuthSource) Validate(apiDef *APIDefinition, validationResult *ValidationResult)
+type RuleLoadBalancingTargets struct{}
+ RuleLoadBalancingTargets implements validations for load balancing target
+ configurations.
+
+func (r *RuleLoadBalancingTargets) Validate(apiDef *APIDefinition, validationResult *ValidationResult)
+ Validate validates that when load balancing is enabled, at least one target
+ has weight > 0.
+
type RuleUniqueDataSourceNames struct{}
func (r *RuleUniqueDataSourceNames) Validate(apiDef *APIDefinition, validationResult *ValidationResult) |
🔍 Code Analysis ResultsThis PR introduces a validation rule to prevent creating or updating an API with load balancing enabled where all upstream targets have a weight of 0. This configuration previously led to a runtime panic ( Files Changed Analysis
Architecture & Impact Assessment
The following diagram illustrates how the new validation rule intercepts an invalid API configuration: sequenceDiagram
participant Client as (e.g., Dashboard/API)
participant Gateway Admin API
participant APIDef Validator
participant Datastore
Client->>+Gateway Admin API: POST /tyk/apis (Create API with all target weights=0)
Gateway Admin API->>+APIDef Validator: Validate(apiDefinition)
APIDef Validator->>APIDef Validator: Run RuleLoadBalancingTargets
Note over APIDef Validator: Detects load balancing is enabled<br/>but target list is empty.
APIDef Validator-->>-Gateway Admin API: Validation Failed: ErrAllLoadBalancingTargetsZeroWeight
Gateway Admin API-->>-Client: HTTP 400 Bad Request
Note over Gateway Admin API, Datastore: Invalid API is not saved
Scope Discovery & Context ExpansionThe change is well-contained within the API definition validation module. By adding the rule to the The primary impact extends to any tool or process that relies on the gateway's API management endpoints, enforcing a stricter configuration standard for load balancing. This could be a breaking change for any automation (e.g., CI/CD scripts, Tyk Operator) that may have been creating these invalid (albeit non-functional) API definitions. The provided tests are sufficient, and no further code exploration is necessary to understand the scope and impact of this change. Metadata
Powered by Visor from Probelabs Last updated: 2025-11-07T15:10:40.316Z | Triggered by: synchronize | Commit: eaeede1 💡 TIP: You can chat with Visor using |
🔍 Code Analysis Results✅ Security Check PassedNo security issues found – changes LGTM. ✅ Architecture Check PassedNo architecture issues found – changes LGTM. ✅ Performance Check PassedNo performance issues found – changes LGTM. Quality Issues (1)
Dependency Issues (3)
✅ Connectivity Check PassedNo connectivity issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2025-11-07T15:10:41.582Z | Triggered by: synchronize | Commit: eaeede1 💡 TIP: You can chat with Visor using |
…t-from-load-balancing
|
All probelabs issues are invalid as the all 0 targets did not exist before this feature. |
|



Description
This PR adds validation to prevent creating or updating APIs with load balancing enabled where all targets have weight 0. Previously, this configuration would be accepted but cause runtime errors (index
out of range) when traffic was sent to the API. The new RuleLoadBalancingTargets validation rule is added to the DefaultValidationRuleSet and checks if load balancing is enabled with an empty targets
list (which occurs when all weights are 0). The validation triggers on both Classic and OAS API endpoints (POST/PUT) and returns a clear HTTP 400 error: "all load balancing targets have weight 0, at
least one target must have weight > 0". This catches the edge case at API configuration time rather than failing at request time, improving the developer experience and preventing invalid configurations
from being saved.
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Ticket Details
TT-15595
Generated at: 2025-11-07 15:07:19