Skip to content

Commit

Permalink
Backport of NET-2903 Normalize weight for http routes into release/1.…
Browse files Browse the repository at this point in the history
…15.x (#16532)

* backport of commit 10ef73a

* backport of commit 99f5b72

* NET-2903 Normalize weight for http routes (#16512)

* NET-2903 Normalize weight for http routes

* Update website/content/docs/connect/gateways/api-gateway/configuration/http-route.mdx

Co-authored-by: trujillo-adam <[email protected]>

---------

Co-authored-by: Melisa Griffin <[email protected]>
Co-authored-by: Melisa Griffin <[email protected]>
Co-authored-by: trujillo-adam <[email protected]>
  • Loading branch information
4 people committed Mar 3, 2023
1 parent 388fef8 commit 2f8de3c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/16512.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
gateways: fix HTTPRoute bug where service weights could be less than or equal to 0 and result in a downstream envoy protocol error
```
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`, the weight is normalized to `1`. The
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

0 comments on commit 2f8de3c

Please sign in to comment.