github.com/hernad/nomad@v1.6.112/nomad/structs/config/limits.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package config 5 6 import "github.com/hernad/nomad/helper/pointer" 7 8 const ( 9 // LimitsNonStreamingConnsPerClient is the number of connections per 10 // peer to reserve for non-streaming RPC connections. Since streaming 11 // RPCs require their own TCP connection, they have their own limit 12 // this amount lower than the overall limit. This reserves a number of 13 // connections for Raft and other RPCs. 14 // 15 // TODO Remove limit once MultiplexV2 is used. 16 LimitsNonStreamingConnsPerClient = 20 17 ) 18 19 // Limits configures timeout limits similar to Consul's limits configuration 20 // parameters. Limits is the internal version with the fields parsed. 21 type Limits struct { 22 // HTTPSHandshakeTimeout is the deadline by which HTTPS TLS handshakes 23 // must complete. 24 // 25 // 0 means no timeout. 26 HTTPSHandshakeTimeout string `hcl:"https_handshake_timeout"` 27 28 // HTTPMaxConnsPerClient is the maximum number of concurrent HTTP 29 // connections from a single IP address. nil/0 means no limit. 30 HTTPMaxConnsPerClient *int `hcl:"http_max_conns_per_client"` 31 32 // RPCHandshakeTimeout is the deadline by which RPC handshakes must 33 // complete. The RPC handshake includes the first byte read as well as 34 // the TLS handshake and subsequent byte read if TLS is enabled. 35 // 36 // The deadline is reset after the first byte is read so when TLS is 37 // enabled RPC connections may take (timeout * 2) to complete. 38 // 39 // The RPC handshake timeout only applies to servers. 0 means no 40 // timeout. 41 RPCHandshakeTimeout string `hcl:"rpc_handshake_timeout"` 42 43 // RPCMaxConnsPerClient is the maximum number of concurrent RPC 44 // connections from a single IP address. nil/0 means no limit. 45 RPCMaxConnsPerClient *int `hcl:"rpc_max_conns_per_client"` 46 } 47 48 // DefaultLimits returns the default limits values. User settings should be 49 // merged into these defaults. 50 func DefaultLimits() Limits { 51 return Limits{ 52 HTTPSHandshakeTimeout: "5s", 53 HTTPMaxConnsPerClient: pointer.Of(100), 54 RPCHandshakeTimeout: "5s", 55 RPCMaxConnsPerClient: pointer.Of(100), 56 } 57 } 58 59 // Merge returns a new Limits where non-empty/nil fields in the argument have 60 // precedence. 61 func (l *Limits) Merge(o Limits) Limits { 62 m := *l 63 64 if o.HTTPSHandshakeTimeout != "" { 65 m.HTTPSHandshakeTimeout = o.HTTPSHandshakeTimeout 66 } 67 if o.HTTPMaxConnsPerClient != nil { 68 m.HTTPMaxConnsPerClient = pointer.Of(*o.HTTPMaxConnsPerClient) 69 } 70 if o.RPCHandshakeTimeout != "" { 71 m.RPCHandshakeTimeout = o.RPCHandshakeTimeout 72 } 73 if o.RPCMaxConnsPerClient != nil { 74 m.RPCMaxConnsPerClient = pointer.Of(*o.RPCMaxConnsPerClient) 75 } 76 77 return m 78 } 79 80 // Copy returns a new deep copy of a Limits struct. 81 func (l *Limits) Copy() Limits { 82 c := *l 83 if l.HTTPMaxConnsPerClient != nil { 84 c.HTTPMaxConnsPerClient = pointer.Of(*l.HTTPMaxConnsPerClient) 85 } 86 if l.RPCMaxConnsPerClient != nil { 87 c.RPCMaxConnsPerClient = pointer.Of(*l.RPCMaxConnsPerClient) 88 } 89 return c 90 }