From 2f970555d9ad241dbdf4026c2a08aed5a4ae06df Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 1 Nov 2021 13:27:50 +0000 Subject: [PATCH] config: warn the user if client_addr is empty if the provided value is empty string then the client services (DNS, HTTP, HTTPS, GRPC) are not listening and the user is not notified in any way about what's happening. Also, since a not provided client_addr defaults to 127.0.0.1, we make sure we are not getting unwanted warnings Signed-off-by: Alessandro De Blasis --- agent/config/builder.go | 3 +++ agent/config/builder_test.go | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/agent/config/builder.go b/agent/config/builder.go index 4456ff252e..b3189e923d 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -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) diff --git a/agent/config/builder_test.go b/agent/config/builder_test.go index 5e39877015..5901431a0d 100644 --- a/agent/config/builder_test.go +++ b/agent/config/builder_test.go @@ -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) + }) + } +}