Skip to content
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

NET-2903 Normalize weight for http routes #16512

Merged
merged 7 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion agent/structs/config_entry_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func (e *HTTPRouteConfigEntry) Normalize() error {

func normalizeHTTPService(service HTTPService) HTTPService {
service.EnterpriseMeta.Normalize()

if service.Weight <= 0 {
service.Weight = 1
}
return service
}

Expand Down
22 changes: 22 additions & 0 deletions agent/structs/config_entry_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@ func TestHTTPRoute(t *testing.T) {
}},
},
},
"rule normalizes service weight": {
entry: &HTTPRouteConfigEntry{
Kind: HTTPRoute,
Name: "route-one",
Rules: []HTTPRouteRule{{
Services: []HTTPService{
{
Name: "test",
Weight: 0,
},
{
Name: "test2",
Weight: -1,
}},
}},
},
check: func(t *testing.T, entry ConfigEntry) {
route := entry.(*HTTPRouteConfigEntry)
require.Equal(t, 1, route.Rules[0].Services[0].Weight)
require.Equal(t, 1, route.Rules[0].Services[1].Weight)
},
},
}
testConfigEntryNormalizeAndValidate(t, cases)
}
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ Specifies the Enterprise [admin partition](/consul/docs/enterprise/admin-partiti

### `Rules[].Services[].Weight`

Specifies the proportion of requests forwarded to the specified service. The
Specifies the proportion of requests forwarded to the specified service. If no weight is specified, or if the specified
weight is set to less than or equal to 0, it will be normalized to 1. The
missylbytes marked this conversation as resolved.
Show resolved Hide resolved
proportion is determined by dividing the value of the weight by the sum of all
weights in the service list. For non-zero values, there may be some deviation
from the exact proportion depending on the precision an implementation
Expand Down