Merge pull request #11461 from deblasis/feature/empty_client_addr_warning
config: warn the user if client_addr is empty
This commit is contained in:
commit
14591de8d2
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
config: warn the user if client_addr is empty because client services won't be listening
|
||||
```
|
|
@ -552,6 +552,9 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
|
|||
|
||||
// determine client addresses
|
||||
clientAddrs := b.expandIPs("client_addr", c.ClientAddr)
|
||||
if len(clientAddrs) == 0 {
|
||||
b.warn("client_addr is empty, client services (DNS, HTTP, HTTPS, GRPC) will not be listening for connections")
|
||||
}
|
||||
dnsAddrs := b.makeAddrs(b.expandAddrs("addresses.dns", c.Addresses.DNS), clientAddrs, dnsPort)
|
||||
httpAddrs := b.makeAddrs(b.expandAddrs("addresses.http", c.Addresses.HTTP), clientAddrs, httpPort)
|
||||
httpsAddrs := b.makeAddrs(b.expandAddrs("addresses.https", c.Addresses.HTTPS), clientAddrs, httpsPort)
|
||||
|
|
|
@ -247,3 +247,47 @@ func TestLoad_HTTPMaxConnsPerClientExceedsRLimit(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "but limits.http_max_conns_per_client: 16777217 needs at least 16777237")
|
||||
}
|
||||
|
||||
func TestLoad_EmptyClientAddr(t *testing.T) {
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
clientAddr *string
|
||||
expectedWarningMessage *string
|
||||
}
|
||||
|
||||
fn := func(t *testing.T, tc testCase) {
|
||||
opts := LoadOpts{
|
||||
FlagValues: Config{
|
||||
ClientAddr: tc.clientAddr,
|
||||
DataDir: pString("dir"),
|
||||
},
|
||||
}
|
||||
patchLoadOptsShims(&opts)
|
||||
result, err := Load(opts)
|
||||
require.NoError(t, err)
|
||||
if tc.expectedWarningMessage != nil {
|
||||
require.Len(t, result.Warnings, 1)
|
||||
require.Contains(t, result.Warnings[0], *tc.expectedWarningMessage)
|
||||
}
|
||||
}
|
||||
|
||||
var testCases = []testCase{
|
||||
{
|
||||
name: "empty string",
|
||||
clientAddr: pString(""),
|
||||
expectedWarningMessage: pString("client_addr is empty, client services (DNS, HTTP, HTTPS, GRPC) will not be listening for connections"),
|
||||
},
|
||||
{
|
||||
name: "nil pointer",
|
||||
clientAddr: nil, // defaults to 127.0.0.1
|
||||
expectedWarningMessage: nil, // expecting no warnings
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
fn(t, tc)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue