Add log message about enforcing bootstrap checks

This commit adds a log message when bootstrap checks are enforced
informing the user that they are enforced because they are bound to an
external network interface. We also log if bootstrap checks are being
enforced but system checks are being ignored.

Relates #19451
This commit is contained in:
Jason Tedor 2016-07-15 14:29:36 -04:00 committed by GitHub
parent f5b5fbcf1d
commit e772b6d924
2 changed files with 29 additions and 0 deletions

View File

@ -104,6 +104,13 @@ final class BootstrapCheck {
final List<String> errors = new ArrayList<>();
final List<String> ignoredErrors = new ArrayList<>();
if (enforceLimits) {
logger.info("bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks");
}
if (enforceLimits && ignoreSystemChecks) {
logger.warn("enforcing bootstrap checks but ignoring system bootstrap checks, consider not ignoring system checks");
}
for (final Check check : checks) {
if (check.check()) {
if ((!enforceLimits || (check.isSystemCheck() && ignoreSystemChecks)) && !check.alwaysEnforce()) {

View File

@ -44,6 +44,7 @@ import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class BootstrapCheckTests extends ESTestCase {
@ -65,6 +66,23 @@ public class BootstrapCheckTests extends ESTestCase {
BootstrapCheck.check(Settings.EMPTY, boundTransportAddress);
}
public void testNoLogMessageInNonProductionMode() {
final ESLogger logger = mock(ESLogger.class);
BootstrapCheck.check(false, randomBoolean(), Collections.emptyList(), logger);
verifyNoMoreInteractions(logger);
}
public void testLogMessageInProductionMode() {
final ESLogger logger = mock(ESLogger.class);
final boolean ignoreSystemChecks = randomBoolean();
BootstrapCheck.check(true, ignoreSystemChecks, Collections.emptyList(), logger);
verify(logger).info("bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks");
if (ignoreSystemChecks) {
verify(logger).warn("enforcing bootstrap checks but ignoring system bootstrap checks, consider not ignoring system checks");
}
verifyNoMoreInteractions(logger);
}
public void testEnforceLimitsWhenBoundToNonLocalAddress() {
final List<TransportAddress> transportAddresses = new ArrayList<>();
final TransportAddress nonLocalTransportAddress = mock(TransportAddress.class);
@ -545,12 +563,16 @@ public class BootstrapCheckTests extends ESTestCase {
// nothing should happen if we ignore system checks
BootstrapCheck.check(true, true, Collections.singletonList(check), logger);
verify(logger).info("bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks");
verify(logger).warn("enforcing bootstrap checks but ignoring system bootstrap checks, consider not ignoring system checks");
verify(logger).warn("error");
verifyNoMoreInteractions(logger);
reset(logger);
// nothing should happen if we ignore all checks
BootstrapCheck.check(false, randomBoolean(), Collections.singletonList(check), logger);
verify(logger).warn("error");
verifyNoMoreInteractions(logger);
}
public void testAlwaysEnforcedChecks() {