diff --git a/.changelog/14395.txt b/.changelog/14395.txt new file mode 100644 index 000000000..3caa76401 --- /dev/null +++ b/.changelog/14395.txt @@ -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 +``` diff --git a/agent/configentry/resolve.go b/agent/configentry/resolve.go index ec85f34d2..f6090e98f 100644 --- a/agent/configentry/resolve.go +++ b/agent/configentry/resolve.go @@ -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 } diff --git a/agent/configentry/resolve_test.go b/agent/configentry/resolve_test.go index 30a03aae6..301472c1c 100644 --- a/agent/configentry/resolve_test.go +++ b/agent/configentry/resolve_test.go @@ -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) { diff --git a/agent/structs/config_entry.go b/agent/structs/config_entry.go index 23c5c8e47..72efbffce 100644 --- a/agent/structs/config_entry.go +++ b/agent/structs/config_entry.go @@ -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"` diff --git a/api/config_entry.go b/api/config_entry.go index 7fe128958..63115b0a6 100644 --- a/api/config_entry.go +++ b/api/config_entry.go @@ -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 diff --git a/api/config_entry_test.go b/api/config_entry_test.go index a897cdeb0..49b3d0d01 100644 --- a/api/config_entry_test.go +++ b/api/config_entry_test.go @@ -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" diff --git a/website/content/docs/connect/config-entries/service-defaults.mdx b/website/content/docs/connect/config-entries/service-defaults.mdx index 2ce58c271..b49224b15 100644 --- a/website/content/docs/connect/config-entries/service-defaults.mdx +++ b/website/content/docs/connect/config-entries/service-defaults.mdx @@ -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: ',