8000 Impl RetryBudget in DestinationRule by zirain · Pull Request #56782 · istio/istio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Impl RetryBudget in DestinationRule #56782

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

Merged
merged 3 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pilot/pkg/networking/core/cluster_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (cb *ClusterBuilder) buildDefaultPassthroughCluster() *cluster.Cluster {
},
}
cluster.AltStatName = util.DelimitedStatsPrefix(util.PassthroughCluster)
cb.applyConnectionPool(cb.req.Push.Mesh, newClusterWrapper(cluster), &networking.ConnectionPoolSettings{})
cb.applyConnectionPool(cb.req.Push.Mesh, newClusterWrapper(cluster), &networking.ConnectionPoolSettings{}, nil)
cb.applyMetadataExchange(cluster)
return cluster
}
Expand Down
226 changes: 214 additions & 12 deletions pilot/pkg/networking/core/cluster_builder_test.go
10000 341A
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package core

import (
"fmt"
"math"
"reflect"
"sort"
"strings"
Expand All @@ -29,6 +30,7 @@ import (
cares "github.com/envoyproxy/go-control-plane/envoy/extensions/network/dns_resolver/cares/v3"
tls "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
xdstype "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/durationpb"
Expand Down Expand Up @@ -784,6 +786,103 @@ func TestApplyDestinationRule(t *testing.T) {
EdsClusterConfig: &cluster.Cluster_EdsClusterConfig{ServiceName: "outbound|8080|v1|foo.default.svc.cluster.local"},
}},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is empty retry budget that sets default values. Can you change name like that and also add a test case when it has actual values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

name: "destination rule with empty retry budget",
cluster: &cluster.Cluster{Name: "foo", ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS}},
clusterMode: DefaultClusterMode,
service: service,
port: servicePort[0],
proxyView: model.ProxyViewAll,
destRule: &networking.DestinationRule{
Host: "foo.default.svc.cluster.local",
Subsets: []*networking.Subset{
{
Name: "foobar",
Labels: map[string]string{"foo": "bar"},
TrafficPolicy: &networking.TrafficPolicy{
ConnectionPool: &networking.ConnectionPoolSettings{
Http: &networking.ConnectionPoolSettings_HTTPSettings{
MaxRetries: 10,
},
},
RetryBudget: &networking.TrafficPolicy_RetryBudget{},
},
},
},
},
expectedSubsetClusters: []*cluster.Cluster{
{
Name: "outbound|8080|foobar|foo.default.svc.cluster.local",
ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS},
EdsClusterConfig: &cluster.Cluster_EdsClusterConfig{
ServiceName: "outbound|8080|foobar|foo.default.svc.cluster.local",
},
CircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{
{
MaxRetries: &wrappers.UInt32Value{
Value: 10,
},
RetryBudget: &cluster.CircuitBreakers_Thresholds_RetryBudget{
BudgetPercent: &xdstype.Percent{Value: 0.2},
MinRetryConcurrency: &wrappers.UInt32Value{Value: 3},
},
},
},
},
},
},
},
{
name: "destination rule with retry budget",
cluster: &cluster.Cluster{Name: "foo", ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS}},
clusterMode: DefaultClusterMode,
service: service,
port: servicePort[0],
proxyView: model.ProxyViewAll,
destRule: &networking.DestinationRule{
Host: "foo.default.svc.cluster.local",
Subsets: []*networking.Subset{
{
Name: "foobar",
Labels: map[string]string{"foo": "bar"},
TrafficPolicy: &networking.TrafficPolicy{
ConnectionPool: &networking.ConnectionPoolSettings{
Http: &networking.ConnectionPoolSettings_HTTPSettings{
MaxRetries: 10,
},
},
RetryBudget: &networking.TrafficPolicy_RetryBudget{
Percent: wrappers.Double(0.3),
MinRetryConcurrency: uint32(4),
},
},
},
},
},
expectedSubsetClusters: []*cluster.Cluster{
{
Name: "outbound|8080|foobar|foo.default.svc.cluster.local",
ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS},
EdsClusterConfig: &cluster.Cluster_EdsClusterConfig{
ServiceName: "outbound|8080|foobar|foo.default.svc.cluster.local",
},
CircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{
{
MaxRetries: &wrappers.UInt32Value{
Value: 10,
},
RetryBudget: &cluster.CircuitBreakers_Thresholds_RetryBudget{
BudgetPercent: &xdstype.Percent{Value: 0.3},
MinRetryConcurrency: &wrappers.UInt32Value{Value: 4},
},
},
},
},
},
},
},
}

for _, tt := range cases {
Expand Down Expand Up @@ -2575,11 +2674,11 @@ func TestIsHttp2Cluster(t *testing.T) {
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
isHttp2Cluster := isHttp2Cluster(test.cluster) // revive:disable-line
if isHttp2Cluster != test.isHttp2Cluster {
t.Errorf("got: %t, want: %t", isHttp2Cluster, test.isHttp2Cluster)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
isHttp2Cluster := isHttp2Cluster(tt.cluster) // revive:disable-line
if isHttp2Cluster != tt.isHttp2Cluster {
t.Errorf("got: %t, want: %t", isHttp2Cluster, tt.isHttp2Cluster)
}
})
}
Expand Down Expand Up @@ -2768,7 +2867,7 @@ func TestApplyTCPKeepalive(t *testing.T) {
cluster: &cluster.Cluster{Name: "foo", ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS}},
}

cb.applyConnectionPool(tt.mesh, mc, tt.connectionPool)
cb.applyConnectionPool(tt.mesh, mc, tt.connectionPool, nil)

if !reflect.DeepEqual(tt.wantConnOpts, mc.cluster.UpstreamConnectionOptions) {
t.Errorf("unexpected tcp keepalive settings, want %v, got %v", tt.wantConnOpts,
Expand All @@ -2780,11 +2879,13 @@ func TestApplyTCPKeepalive(t *testing.T) {

func TestApplyConnectionPool(t *testing.T) {
cases := []struct {
name string
cluster *cluster.Cluster
httpProtocolOptions *http.HttpProtocolOptions
connectionPool *networking.ConnectionPoolSettings
expectedHTTPPOpt *http.HttpProtocolOptions
name string
cluster *cluster.Cluster
httpProtocolOptions *http.HttpProtocolOptions
connectionPool *networking.ConnectionPoolSettings
retryBudget *networking.TrafficPolicy_RetryBudget
expectedHTTPPOpt *http.HttpProtocolOptions
expectedCircuitBreakers *cluster.CircuitBreakers
}{
{
name: "only update IdleTimeout",
Expand Down Expand Up @@ -2812,6 +2913,9 @@ func TestApplyConnectionPool(t *testing.T) {
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 10},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{getDefaultCircuitBreakerThresholds()},
},
},
{
name: "set TCP idle timeout",
Expand Down Expand Up @@ -2839,6 +2943,9 @@ func TestApplyConnectionPool(t *testing.T) {
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 10},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{getDefaultCircuitBreakerThresholds()},
},
},
{
name: "ignore TCP idle timeout when HTTP idle timeout is specified",
Expand Down Expand Up @@ -2868,6 +2975,9 @@ func TestApplyConnectionPool(t *testing.T) {
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 10},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{getDefaultCircuitBreakerThresholds()},
},
},
{
name: "only update MaxRequestsPerConnection ",
Expand All @@ -2893,6 +3003,9 @@ func TestApplyConnectionPool(t *testing.T) {
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 22},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{getDefaultCircuitBreakerThresholds()},
},
},
{
name: "update multiple fields",
Expand Down Expand Up @@ -2929,6 +3042,94 @@ func TestApplyConnectionPool(t *testing.T) {
},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{getDefaultCircuitBreakerThresholds()},
},
},
{
name: "default retry budget",
cluster: &cluster.Cluster{Name: "foo", ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS}},
httpProtocolOptions: &http.HttpProtocolOptions{
CommonHttpProtocolOptions: &core.HttpProtocolOptions{
IdleTimeout: &durationpb.Duration{
Seconds: 10,
},
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 10},
},
},
connectionPool: &networking.ConnectionPoolSettings{
Http: &networking.ConnectionPoolSettings_HTTPSettings{
MaxRequestsPerConnection: 22,
},
},
retryBudget: &networking.TrafficPolicy_RetryBudget{},
expectedHTTPPOpt: &http.HttpProtocolOptions{
CommonHttpProtocolOptions: &core.HttpProtocolOptions{
IdleTimeout: &durationpb.Duration{
Seconds: 10,
},
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 22},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{
{
MaxRetries: &wrappers.UInt32Value{Value: math.MaxUint32},
MaxRequests: &wrappers.UInt32Value{Value: math.MaxUint32},
MaxConnections: &wrappers.UInt32Value{Value: math.MaxUint32},
MaxPendingRequests: &wrappers.UInt32Value{Value: math.MaxUint32},
TrackRemaining: true,
RetryBudget: &cluster.CircuitBreakers_Thresholds_RetryBudget{
BudgetPercent: &xdstype.Percent{Value: 0.2},
MinRetryConcurrency: &wrappers.UInt32Value{Value: 3},
},
},
},
},
},
{
name: "retry budget",
cluster: &cluster.Cluster{Name: "foo", ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_EDS}},
httpProtocolOptions: &http.HttpProtocolOptions{
CommonHttpProtocolOptions: &core.HttpProtocolOptions{
IdleTimeout: &durationpb.Duration{
Seconds: 10,
},
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 10},
},
},
connectionPool: &networking.ConnectionPoolSettings{
Http: &networking.ConnectionPoolSettings_HTTPSettings{
MaxRequestsPerConnection: 22,
},
},
retryBudget: &networking.TrafficPolicy_RetryBudget{
Percent: wrappers.Double(0.3),
MinRetryConcurrency: uint32(4),
},
expectedHTTPPOpt: &http.HttpProtocolOptions{
CommonHttpProtocolOptions: &core.HttpProtocolOptions{
IdleTimeout: &durationpb.Duration{
Seconds: 10,
},
MaxRequestsPerConnection: &wrappers.UInt32Value{Value: 22},
},
},
expectedCircuitBreakers: &cluster.CircuitBreakers{
Thresholds: []*cluster.CircuitBreakers_Thresholds{
{
MaxRetries: &wrappers.UInt32Value{Value: math.MaxUint32},
MaxRequests: &wrappers.UInt32Value{Value: math.MaxUint32},
MaxConnections: &wrappers.UInt32Value{Value: math.MaxUint32},
MaxPendingRequests: &wrappers.UInt32Value{Value: math.MaxUint32},
TrackRemaining: true,
RetryBudget: &cluster.CircuitBreakers_Thresholds_RetryBudget{
BudgetPercent: &xdstype.Percent{Value: 0.3},
MinRetryConcurrency: &wrappers.UInt32Value{Value: 4},
},
},
},
},
},
}

Expand All @@ -2946,14 +3147,15 @@ func TestApplyConnectionPool(t *testing.T) {
mesh: cb.req.Push.Mesh,
mutable: mc,
}
cb.applyConnectionPool(opts.mesh, opts.mutable, tt.connectionPool)
cb.applyConnectionPool(opts.mesh, opts.mutable, tt.connectionPool, tt.retryBudget)
// assert httpProtocolOptions
assert.Equal(t, opts.mutable.httpProtocolOptions.CommonHttpProtocolOptions.IdleTimeout,
tt.expectedHTTPPOpt.CommonHttpProtocolOptions.IdleTimeout)
assert.Equal(t, opts.mutable.httpProtocolOptions.CommonHttpProtocolOptions.MaxRequestsPerConnection,
tt.expectedHTTPPOpt.CommonHttpProtocolOptions.MaxRequestsPerConnection)
assert.Equal(t, opts.mutable.httpProtocolOptions.CommonHttpProtocolOptions.MaxConnectionDuration,
tt.expectedHTTPPOpt.CommonHttpProtocolOptions.MaxConnectionDuration)
assert.Equal(t, opts.mutable.cluster.CircuitBreakers, tt.expectedCircuitBreakers)
})
}
}
Expand Down
Loading
0