mirror of
https://github.com/taylanbakircioglu/haproxy-openmanager.git
synced 2026-09-24 19:32:01 +00:00
feat: Add random and first balance methods support
- Add 'random' and 'first' options to backend balance method selector - Add balance method validation in config parser with warning for unknown methods - Update API documentation with all supported balance algorithms
This commit is contained in:
@@ -193,10 +193,13 @@ async def get_backends(cluster_id: Optional[int] = None, include_inactive: bool
|
||||
```
|
||||
|
||||
## Load Balancing Methods
|
||||
- **roundrobin**: Each server used in turn
|
||||
- **roundrobin**: Each server used in turn (default)
|
||||
- **leastconn**: Server with least connections
|
||||
- **source**: Based on source IP hash
|
||||
- **uri**: Based on URI hash
|
||||
- **static-rr**: Static round-robin (no dynamic weight)
|
||||
- **random**: Random server selection (HAProxy 1.9+)
|
||||
- **first**: First server with available slots
|
||||
"""
|
||||
try:
|
||||
conn = await get_database_connection()
|
||||
|
||||
@@ -563,10 +563,35 @@ class HAProxyConfigParser:
|
||||
if mode_match:
|
||||
backend.mode = mode_match.group(1).lower()
|
||||
|
||||
# Parse balance method
|
||||
# Parse balance method with validation
|
||||
balance_match = re.match(r'^balance\s+(\S+)', line, re.IGNORECASE)
|
||||
if balance_match:
|
||||
backend.balance_method = balance_match.group(1)
|
||||
balance_value = balance_match.group(1).lower()
|
||||
|
||||
# HAProxy supported balance algorithms
|
||||
supported_balance_methods = [
|
||||
'roundrobin', # Each server used in turn
|
||||
'static-rr', # Static round-robin (no dynamic weight)
|
||||
'leastconn', # Server with least connections
|
||||
'first', # First server with available slots
|
||||
'source', # Based on source IP hash
|
||||
'uri', # Based on URI hash
|
||||
'url_param', # Based on URL parameter
|
||||
'hdr', # Based on HTTP header
|
||||
'random', # Random server selection (HAProxy 1.9+)
|
||||
'rdp-cookie', # Based on RDP cookie
|
||||
]
|
||||
|
||||
if balance_value in supported_balance_methods:
|
||||
backend.balance_method = balance_value
|
||||
else:
|
||||
# Unknown balance method - use default and warn
|
||||
self.warnings.append(
|
||||
f"Backend '{name}': Unknown balance method '{balance_value}' detected. "
|
||||
f"Supported methods: {', '.join(supported_balance_methods)}. "
|
||||
f"Using default 'roundrobin' instead."
|
||||
)
|
||||
backend.balance_method = 'roundrobin'
|
||||
|
||||
# Parse timeout directives
|
||||
timeout_connect_match = re.match(r'^timeout\s+connect\s+(\d+)(ms|s|m|h)?', line, re.IGNORECASE)
|
||||
|
||||
@@ -1614,6 +1614,8 @@ const BackendServers = () => {
|
||||
<Option value="source">Source IP</Option>
|
||||
<Option value="uri">URI</Option>
|
||||
<Option value="static-rr">Static Round Robin</Option>
|
||||
<Option value="random">Random</Option>
|
||||
<Option value="first">First Available</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
Reference in New Issue
Block a user