-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add load balancing to oas configuration (TT-881) #6830
Conversation
Let's make that PR title a 💯 shall we? 💪 Your PR title and story title look slightly different. Just checking in to know if it was intentional!
Check out this guide to learn more about PR best-practices. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
API Changes --- prev.txt 2025-01-15 12:56:47.271413586 +0000
+++ current.txt 2025-01-15 12:56:42.662355967 +0000
@@ -3086,6 +3086,32 @@
func (lp *ListenPath) Fill(api apidef.APIDefinition)
Fill fills *ListenPath from apidef.APIDefinition.
+type LoadBalancing struct {
+ // Enabled determines if load balancing is active.
+ Enabled bool `json:"enabled,omitempty" bson:"enabled,omitempty"`
+ // Targets defines the list of targets with their respective weights for load balancing.
+ Targets []LoadBalancingTarget `json:"targets,omitempty" bson:"targets,omitempty"`
+}
+ LoadBalancing represents the configuration for load balancing between
+ multiple upstream targets.
+
+func (l *LoadBalancing) ExtractTo(api *apidef.APIDefinition)
+ ExtractTo populates an APIDefinition's proxy load balancing configuration
+ with data from the LoadBalancing instance.
+
+func (l *LoadBalancing) Fill(api apidef.APIDefinition)
+ Fill populates the LoadBalancing structure based on the provided
+ APIDefinition, including targets and their weights.
+
+type LoadBalancingTarget struct {
+ // URL specifies the upstream target URL for load balancing, represented as a string.
+ URL string `json:"url,omitempty" bson:"url,omitempty"`
+ // Weight specifies the relative distribution factor for load balancing, determining the importance of this target.
+ Weight int `json:"weight,omitempty" bson:"weight,omitempty"`
+}
+ LoadBalancingTarget represents a single upstream target for load balancing
+ with a URL and an associated weight.
+
type Middleware struct {
// Global contains configuration for middleware that affects the whole API (all endpoints).
Global *Global `bson:"global,omitempty" json:"global,omitempty"`
@@ -4221,6 +4247,9 @@
// Authentication contains the configuration related to upstream authentication.
Authentication *UpstreamAuth `bson:"authentication,omitempty" json:"authentication,omitempty"`
+
+ // LoadBalancing contains configuration for load balancing between multiple upstream targets.
+ LoadBalancing *LoadBalancing `bson:"loadBalancing,omitempty" json:"loadBalancing,omitempty"`
}
Upstream holds configuration for the upstream server to which Tyk should
proxy requests. |
PR Code Suggestions ✨Explore these optional code suggestions:
|
858411a
to
44e24bc
Compare
Quality Gate passedIssues Measures |
User description
TT-881
This PR adds weighted load balancing to OAS configuration.
Types of changes
PR Type
Enhancement, Tests
Description
Added load balancing configuration to the OAS upstream definition.
Implemented
LoadBalancing
andLoadBalancingTarget
structures with related methods.Updated schema to include load balancing configuration.
Added comprehensive unit tests for load balancing functionality.
Changes walkthrough 📝
oas_test.go
Remove deprecated load balancing references in tests
apidef/oas/oas_test.go
upstream_test.go
Add unit tests for load balancing functionality
apidef/oas/upstream_test.go
LoadBalancing
andLoadBalancingTarget
.fill
andextractTo
methods for load balancing.upstream.go
Add load balancing logic to upstream handling
apidef/oas/upstream.go
LoadBalancing
andLoadBalancingTarget
structures.configurations.
x-tyk-api-gateway.json
Update schema to support load balancing configuration
apidef/oas/schema/x-tyk-api-gateway.json
loadBalancing
configuration.X-Tyk-LoadBalancing
andX-Tyk-LoadBalancingTarget
.