Turn Limits and PassiveHealthChecks into pointers

This commit is contained in:
freddygv 2021-03-11 11:04:40 -07:00
parent acec711a6a
commit e3dc2a49df
9 changed files with 51 additions and 43 deletions

View File

@ -469,7 +469,7 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
// usConfigs stores the opaque config map for each upstream and is keyed on the upstream's ID. // usConfigs stores the opaque config map for each upstream and is keyed on the upstream's ID.
usConfigs := make(map[structs.ServiceID]map[string]interface{}) usConfigs := make(map[structs.ServiceID]map[string]interface{})
for upstream, _ := range seenUpstreams { for upstream := range seenUpstreams {
resolvedCfg := make(map[string]interface{}) resolvedCfg := make(map[string]interface{})
// The protocol of an upstream is resolved in this order: // The protocol of an upstream is resolved in this order:

View File

@ -1069,7 +1069,7 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) {
UpstreamDefaults: &structs.UpstreamConfig{ UpstreamDefaults: &structs.UpstreamConfig{
Protocol: "http", Protocol: "http",
MeshGateway: structs.MeshGatewayConfig{Mode: structs.MeshGatewayModeRemote}, MeshGateway: structs.MeshGatewayConfig{Mode: structs.MeshGatewayModeRemote},
PassiveHealthCheck: structs.PassiveHealthCheck{ PassiveHealthCheck: &structs.PassiveHealthCheck{
Interval: 10, Interval: 10,
MaxFailures: 2, MaxFailures: 2,
}, },

View File

@ -660,11 +660,11 @@ type UpstreamConfig struct {
// Limits are the set of limits that are applied to the proxy for a specific upstream of a // Limits are the set of limits that are applied to the proxy for a specific upstream of a
// service instance. // service instance.
Limits UpstreamLimits Limits *UpstreamLimits `json:",omitempty"`
// PassiveHealthCheck configuration determines how upstream proxy instances will // PassiveHealthCheck configuration determines how upstream proxy instances will
// be monitored for removal from the load balancing pool. // be monitored for removal from the load balancing pool.
PassiveHealthCheck PassiveHealthCheck `json:",omitempty" alias:"passive_health_check"` PassiveHealthCheck *PassiveHealthCheck `json:",omitempty" alias:"passive_health_check"`
// MeshGatewayConfig controls how Mesh Gateways are configured and used // MeshGatewayConfig controls how Mesh Gateways are configured and used
MeshGateway MeshGatewayConfig `json:",omitempty" alias:"mesh_gateway" ` MeshGateway MeshGatewayConfig `json:",omitempty" alias:"mesh_gateway" `
@ -697,10 +697,10 @@ func (cfg UpstreamConfig) MergeInto(dst map[string]interface{}, legacy bool) {
if !cfg.MeshGateway.IsZero() { if !cfg.MeshGateway.IsZero() {
dst["mesh_gateway"] = cfg.MeshGateway dst["mesh_gateway"] = cfg.MeshGateway
} }
if !cfg.Limits.IsZero() { if cfg.Limits != nil {
dst["limits"] = cfg.Limits dst["limits"] = cfg.Limits
} }
if !cfg.PassiveHealthCheck.IsZero() { if cfg.PassiveHealthCheck != nil {
dst["passive_health_check"] = cfg.PassiveHealthCheck dst["passive_health_check"] = cfg.PassiveHealthCheck
} }
} }
@ -720,11 +720,18 @@ func (cfg *UpstreamConfig) Normalize() {
func (cfg UpstreamConfig) Validate() error { func (cfg UpstreamConfig) Validate() error {
var validationErr error var validationErr error
if err := cfg.PassiveHealthCheck.Validate(); err != nil { if cfg.PassiveHealthCheck != nil {
validationErr = multierror.Append(validationErr, err) err := cfg.PassiveHealthCheck.Validate()
if err != nil {
validationErr = multierror.Append(validationErr, err)
}
} }
if err := cfg.Limits.Validate(); err != nil {
validationErr = multierror.Append(validationErr, err) if cfg.Limits != nil {
err := cfg.Limits.Validate()
if err != nil {
validationErr = multierror.Append(validationErr, err)
}
} }
return validationErr return validationErr

View File

@ -196,7 +196,7 @@ func TestDecodeConfigEntry(t *testing.T) {
Connect: &ConnectConfiguration{ Connect: &ConnectConfiguration{
UpstreamConfigs: map[string]*UpstreamConfig{ UpstreamConfigs: map[string]*UpstreamConfig{
"redis": { "redis": {
PassiveHealthCheck: PassiveHealthCheck{ PassiveHealthCheck: &PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -210,7 +210,7 @@ func TestDecodeConfigEntry(t *testing.T) {
ClusterJSON: "bar", ClusterJSON: "bar",
ConnectTimeoutMs: 5, ConnectTimeoutMs: 5,
Protocol: "http", Protocol: "http",
Limits: UpstreamLimits{ Limits: &UpstreamLimits{
MaxConnections: intPointer(3), MaxConnections: intPointer(3),
MaxPendingRequests: intPointer(4), MaxPendingRequests: intPointer(4),
MaxConcurrentRequests: intPointer(5), MaxConcurrentRequests: intPointer(5),
@ -1613,12 +1613,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
ClusterJSON: "bar", ClusterJSON: "bar",
ConnectTimeoutMs: 5, ConnectTimeoutMs: 5,
Protocol: "http", Protocol: "http",
Limits: UpstreamLimits{ Limits: &UpstreamLimits{
MaxConnections: intPointer(3), MaxConnections: intPointer(3),
MaxPendingRequests: intPointer(4), MaxPendingRequests: intPointer(4),
MaxConcurrentRequests: intPointer(5), MaxConcurrentRequests: intPointer(5),
}, },
PassiveHealthCheck: PassiveHealthCheck{ PassiveHealthCheck: &PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -1630,12 +1630,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
"cluster_json": "bar", "cluster_json": "bar",
"connect_timeout_ms": 5, "connect_timeout_ms": 5,
"protocol": "http", "protocol": "http",
"limits": UpstreamLimits{ "limits": &UpstreamLimits{
MaxConnections: intPointer(3), MaxConnections: intPointer(3),
MaxPendingRequests: intPointer(4), MaxPendingRequests: intPointer(4),
MaxConcurrentRequests: intPointer(5), MaxConcurrentRequests: intPointer(5),
}, },
"passive_health_check": PassiveHealthCheck{ "passive_health_check": &PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -1650,12 +1650,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
ClusterJSON: "bar", ClusterJSON: "bar",
ConnectTimeoutMs: 5, ConnectTimeoutMs: 5,
Protocol: "http", Protocol: "http",
Limits: UpstreamLimits{ Limits: &UpstreamLimits{
MaxConnections: intPointer(3), MaxConnections: intPointer(3),
MaxPendingRequests: intPointer(4), MaxPendingRequests: intPointer(4),
MaxConcurrentRequests: intPointer(5), MaxConcurrentRequests: intPointer(5),
}, },
PassiveHealthCheck: PassiveHealthCheck{ PassiveHealthCheck: &PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -1666,12 +1666,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
"cluster_json": "zap", "cluster_json": "zap",
"connect_timeout_ms": 10, "connect_timeout_ms": 10,
"protocol": "grpc", "protocol": "grpc",
"limits": UpstreamLimits{ "limits": &UpstreamLimits{
MaxConnections: intPointer(10), MaxConnections: intPointer(10),
MaxPendingRequests: intPointer(11), MaxPendingRequests: intPointer(11),
MaxConcurrentRequests: intPointer(12), MaxConcurrentRequests: intPointer(12),
}, },
"passive_health_check": PassiveHealthCheck{ "passive_health_check": &PassiveHealthCheck{
MaxFailures: 13, MaxFailures: 13,
Interval: 14 * time.Second, Interval: 14 * time.Second,
}, },
@ -1682,12 +1682,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
"cluster_json": "bar", "cluster_json": "bar",
"connect_timeout_ms": 5, "connect_timeout_ms": 5,
"protocol": "http", "protocol": "http",
"limits": UpstreamLimits{ "limits": &UpstreamLimits{
MaxConnections: intPointer(3), MaxConnections: intPointer(3),
MaxPendingRequests: intPointer(4), MaxPendingRequests: intPointer(4),
MaxConcurrentRequests: intPointer(5), MaxConcurrentRequests: intPointer(5),
}, },
"passive_health_check": PassiveHealthCheck{ "passive_health_check": &PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -1716,12 +1716,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
"cluster_json": "zap", "cluster_json": "zap",
"connect_timeout_ms": 10, "connect_timeout_ms": 10,
"protocol": "grpc", "protocol": "grpc",
"limits": UpstreamLimits{ "limits": &UpstreamLimits{
MaxConnections: intPointer(10), MaxConnections: intPointer(10),
MaxPendingRequests: intPointer(11), MaxPendingRequests: intPointer(11),
MaxConcurrentRequests: intPointer(12), MaxConcurrentRequests: intPointer(12),
}, },
"passive_health_check": PassiveHealthCheck{ "passive_health_check": &PassiveHealthCheck{
MaxFailures: 13, MaxFailures: 13,
Interval: 14 * time.Second, Interval: 14 * time.Second,
}, },
@ -1732,12 +1732,12 @@ func TestUpstreamConfig_MergeInto(t *testing.T) {
"cluster_json": "zap", "cluster_json": "zap",
"connect_timeout_ms": 10, "connect_timeout_ms": 10,
"protocol": "grpc", "protocol": "grpc",
"limits": UpstreamLimits{ "limits": &UpstreamLimits{
MaxConnections: intPointer(10), MaxConnections: intPointer(10),
MaxPendingRequests: intPointer(11), MaxPendingRequests: intPointer(11),
MaxConcurrentRequests: intPointer(12), MaxConcurrentRequests: intPointer(12),
}, },
"passive_health_check": PassiveHealthCheck{ "passive_health_check": &PassiveHealthCheck{
MaxFailures: 13, MaxFailures: 13,
Interval: 14 * time.Second, Interval: 14 * time.Second,
}, },
@ -1845,7 +1845,7 @@ func TestParseUpstreamConfig(t *testing.T) {
want: UpstreamConfig{ want: UpstreamConfig{
ConnectTimeoutMs: 5000, ConnectTimeoutMs: 5000,
Protocol: "tcp", Protocol: "tcp",
Limits: UpstreamLimits{ Limits: &UpstreamLimits{
MaxConnections: intPointer(50), MaxConnections: intPointer(50),
MaxPendingRequests: intPointer(60), MaxPendingRequests: intPointer(60),
MaxConcurrentRequests: intPointer(70), MaxConcurrentRequests: intPointer(70),
@ -1864,7 +1864,7 @@ func TestParseUpstreamConfig(t *testing.T) {
want: UpstreamConfig{ want: UpstreamConfig{
ConnectTimeoutMs: 5000, ConnectTimeoutMs: 5000,
Protocol: "tcp", Protocol: "tcp",
Limits: UpstreamLimits{ Limits: &UpstreamLimits{
MaxConnections: intPointer(0), MaxConnections: intPointer(0),
MaxPendingRequests: intPointer(0), MaxPendingRequests: intPointer(0),
MaxConcurrentRequests: intPointer(0), MaxConcurrentRequests: intPointer(0),
@ -1882,7 +1882,7 @@ func TestParseUpstreamConfig(t *testing.T) {
want: UpstreamConfig{ want: UpstreamConfig{
ConnectTimeoutMs: 5000, ConnectTimeoutMs: 5000,
Protocol: "tcp", Protocol: "tcp",
PassiveHealthCheck: PassiveHealthCheck{ PassiveHealthCheck: &PassiveHealthCheck{
Interval: 22 * time.Second, Interval: 22 * time.Second,
MaxFailures: 7, MaxFailures: 7,
}, },

View File

@ -734,11 +734,8 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC
return cluster return cluster
} }
func makeThresholdsIfNeeded(limits structs.UpstreamLimits) []*envoy_cluster_v3.CircuitBreakers_Thresholds { func makeThresholdsIfNeeded(limits *structs.UpstreamLimits) []*envoy_cluster_v3.CircuitBreakers_Thresholds {
var empty structs.UpstreamLimits if limits == nil {
// Make sure to not create any thresholds when passed the zero-value in order
// to rely on Envoy defaults
if limits == empty {
return nil return nil
} }

View File

@ -151,8 +151,12 @@ func ParseGatewayConfig(m map[string]interface{}) (GatewayConfig, error) {
// Return an envoy.OutlierDetection populated by the values from this struct. // Return an envoy.OutlierDetection populated by the values from this struct.
// If all values are zero a default empty OutlierDetection will be returned to // If all values are zero a default empty OutlierDetection will be returned to
// enable outlier detection with default values. // enable outlier detection with default values.
func ToOutlierDetection(p structs.PassiveHealthCheck) *envoy_cluster_v3.OutlierDetection { func ToOutlierDetection(p *structs.PassiveHealthCheck) *envoy_cluster_v3.OutlierDetection {
od := &envoy_cluster_v3.OutlierDetection{} od := &envoy_cluster_v3.OutlierDetection{}
if p == nil {
return od
}
if p.Interval != 0 { if p.Interval != 0 {
od.Interval = ptypes.DurationProto(p.Interval) od.Interval = ptypes.DurationProto(p.Interval)
} }

View File

@ -127,11 +127,11 @@ type UpstreamConfig struct {
// Limits are the set of limits that are applied to the proxy for a specific upstream of a // Limits are the set of limits that are applied to the proxy for a specific upstream of a
// service instance. // service instance.
Limits UpstreamLimits Limits *UpstreamLimits
// PassiveHealthCheck configuration determines how upstream proxy instances will // PassiveHealthCheck configuration determines how upstream proxy instances will
// be monitored for removal from the load balancing pool. // be monitored for removal from the load balancing pool.
PassiveHealthCheck PassiveHealthCheck `json:",omitempty" alias:"passive_health_check"` PassiveHealthCheck *PassiveHealthCheck `json:",omitempty" alias:"passive_health_check"`
// MeshGatewayConfig controls how Mesh Gateways are configured and used // MeshGatewayConfig controls how Mesh Gateways are configured and used
MeshGateway MeshGatewayConfig `json:",omitempty" alias:"mesh_gateway" ` MeshGateway MeshGatewayConfig `json:",omitempty" alias:"mesh_gateway" `

View File

@ -380,7 +380,7 @@ func TestDecodeConfigEntry(t *testing.T) {
Connect: ConnectConfiguration{ Connect: ConnectConfiguration{
UpstreamConfigs: map[string]UpstreamConfig{ UpstreamConfigs: map[string]UpstreamConfig{
"redis": { "redis": {
PassiveHealthCheck: PassiveHealthCheck{ PassiveHealthCheck: &PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -394,12 +394,12 @@ func TestDecodeConfigEntry(t *testing.T) {
ListenerJSON: "zop", ListenerJSON: "zop",
Protocol: "http", Protocol: "http",
ConnectTimeoutMs: 5000, ConnectTimeoutMs: 5000,
Limits: UpstreamLimits{ Limits: &UpstreamLimits{
MaxConnections: 3, MaxConnections: 3,
MaxPendingRequests: 4, MaxPendingRequests: 4,
MaxConcurrentRequests: 5, MaxConcurrentRequests: 5,
}, },
PassiveHealthCheck: PassiveHealthCheck{ PassiveHealthCheck: &PassiveHealthCheck{
MaxFailures: 5, MaxFailures: 5,
Interval: 4 * time.Second, Interval: 4 * time.Second,
}, },

View File

@ -615,7 +615,7 @@ func TestParseConfigEntry(t *testing.T) {
Connect: api.ConnectConfiguration{ Connect: api.ConnectConfiguration{
UpstreamConfigs: map[string]api.UpstreamConfig{ UpstreamConfigs: map[string]api.UpstreamConfig{
"redis": { "redis": {
PassiveHealthCheck: api.PassiveHealthCheck{ PassiveHealthCheck: &api.PassiveHealthCheck{
MaxFailures: 3, MaxFailures: 3,
Interval: 2 * time.Second, Interval: 2 * time.Second,
}, },
@ -631,12 +631,12 @@ func TestParseConfigEntry(t *testing.T) {
ListenerJSON: "zop", ListenerJSON: "zop",
Protocol: "http", Protocol: "http",
ConnectTimeoutMs: 5000, ConnectTimeoutMs: 5000,
Limits: api.UpstreamLimits{ Limits: &api.UpstreamLimits{
MaxConnections: 3, MaxConnections: 3,
MaxPendingRequests: 4, MaxPendingRequests: 4,
MaxConcurrentRequests: 5, MaxConcurrentRequests: 5,
}, },
PassiveHealthCheck: api.PassiveHealthCheck{ PassiveHealthCheck: &api.PassiveHealthCheck{
MaxFailures: 5, MaxFailures: 5,
Interval: 4 * time.Second, Interval: 4 * time.Second,
}, },