Config-entry: Support proxy config in service-defaults (#14395)

* Config-entry: Support proxy config in service-defaults

* Update website/content/docs/connect/config-entries/service-defaults.mdx

Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>
This commit is contained in:
cskh 2022-09-12 10:41:58 -04:00 committed by GitHub
parent 9f14171f6c
commit 6196be1f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 0 deletions

4
.changelog/14395.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:feature
service-defaults: Added support for `local_request_timeout_ms` and
`local_connect_timeout_ms` in servicedefaults config entry
```

View File

@ -88,6 +88,20 @@ func ComputeResolvedServiceConfig(
thisReply.ProxyConfig["max_inbound_connections"] = serviceConf.MaxInboundConnections
}
if serviceConf.LocalConnectTimeoutMs > 0 {
if thisReply.ProxyConfig == nil {
thisReply.ProxyConfig = map[string]interface{}{}
}
thisReply.ProxyConfig["local_connect_timeout_ms"] = serviceConf.LocalConnectTimeoutMs
}
if serviceConf.LocalRequestTimeoutMs > 0 {
if thisReply.ProxyConfig == nil {
thisReply.ProxyConfig = map[string]interface{}{}
}
thisReply.ProxyConfig["local_request_timeout_ms"] = serviceConf.LocalRequestTimeoutMs
}
thisReply.Meta = serviceConf.Meta
}

View File

@ -44,6 +44,30 @@ func Test_ComputeResolvedServiceConfig(t *testing.T) {
},
},
},
{
name: "proxy with local_connect_timeout_ms and local_request_timeout_ms",
args: args{
scReq: &structs.ServiceConfigRequest{
Name: "sid",
},
entries: &ResolvedServiceConfigSet{
ServiceDefaults: map[structs.ServiceID]*structs.ServiceConfigEntry{
sid: {
MaxInboundConnections: 20,
LocalConnectTimeoutMs: 20000,
LocalRequestTimeoutMs: 30000,
},
},
},
},
want: &structs.ServiceConfigResponse{
ProxyConfig: map[string]interface{}{
"max_inbound_connections": 20,
"local_connect_timeout_ms": 20000,
"local_request_timeout_ms": 30000,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View File

@ -109,6 +109,8 @@ type ServiceConfigEntry struct {
UpstreamConfig *UpstreamConfiguration `json:",omitempty" alias:"upstream_config"`
Destination *DestinationConfig `json:",omitempty"`
MaxInboundConnections int `json:",omitempty" alias:"max_inbound_connections"`
LocalConnectTimeoutMs int `json:",omitempty" alias:"local_connect_timeout_ms"`
LocalRequestTimeoutMs int `json:",omitempty" alias:"local_request_timeout_ms"`
Meta map[string]string `json:",omitempty"`
acl.EnterpriseMeta `hcl:",squash" mapstructure:",squash"`

View File

@ -236,6 +236,8 @@ type ServiceConfigEntry struct {
UpstreamConfig *UpstreamConfiguration `json:",omitempty" alias:"upstream_config"`
Destination *DestinationConfig `json:",omitempty"`
MaxInboundConnections int `json:",omitempty" alias:"max_inbound_connections"`
LocalConnectTimeoutMs int `json:",omitempty" alias:"local_connect_timeout_ms"`
LocalRequestTimeoutMs int `json:",omitempty" alias:"local_request_timeout_ms"`
Meta map[string]string `json:",omitempty"`
CreateIndex uint64
ModifyIndex uint64

View File

@ -105,6 +105,8 @@ func TestAPI_ConfigEntries(t *testing.T) {
"gir": "zim",
},
MaxInboundConnections: 5,
LocalConnectTimeoutMs: 5000,
LocalRequestTimeoutMs: 7000,
}
dest := &DestinationConfig{
@ -146,6 +148,8 @@ func TestAPI_ConfigEntries(t *testing.T) {
require.Equal(t, service.Meta, readService.Meta)
require.Equal(t, service.Meta, readService.GetMeta())
require.Equal(t, service.MaxInboundConnections, readService.MaxInboundConnections)
require.Equal(t, service.LocalConnectTimeoutMs, readService.LocalConnectTimeoutMs)
require.Equal(t, service.LocalRequestTimeoutMs, readService.LocalRequestTimeoutMs)
// update it
service.Protocol = "tcp"

View File

@ -711,6 +711,18 @@ represents a location outside the Consul cluster. They can be dialed directly wh
type: 'int: 0',
yaml: true,
},
{
name: 'LocalConnectTimeoutMs',
description: ' The number of milliseconds allowed to make connections to the local application instance before timing out. Defaults to 5000.',
type: 'int: 0',
yaml: false,
},
{
name: 'LocalRequestTimeoutMs',
description: ' In milliseconds, the timeout for HTTP requests to the local application instance. Applies to HTTP-based protocols only. If not specified, inherits the Envoy default for route timeouts (15s).',
type: 'int: 0',
yaml: false,
},
{
name: 'MeshGateway',
type: 'MeshGatewayConfig: <optional>',