Skip to content

Commit

Permalink
datanode preflight dns check (#20492)
Browse files Browse the repository at this point in the history
* datanode preflight dns check

* code cleanup

* better error message

* fix dns preflight check

* changelog

* Update data-node/src/main/java/org/graylog/datanode/bootstrap/preflight/DatanodeDnsPreflightCheck.java

Co-authored-by: Matthias Oesterheld <[email protected]>

---------

Co-authored-by: Matthias Oesterheld <[email protected]>
  • Loading branch information
todvora and moesterheld authored Oct 28, 2024
1 parent b966959 commit 0d94bf1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-20503.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type="c"
message="Datanode preflight check that verifies if hostname is bound to an IP"

issues=["20503"]
pulls=["20492"]
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;
import org.graylog.datanode.bootstrap.preflight.DatanodeDirectoriesLockfileCheck;
import org.graylog.datanode.bootstrap.preflight.DatanodeDnsPreflightCheck;
import org.graylog.datanode.bootstrap.preflight.DatanodeKeystoreCheck;
import org.graylog.datanode.bootstrap.preflight.OpenSearchPreconditionsCheck;
import org.graylog.datanode.bootstrap.preflight.OpensearchBinPreflightCheck;
Expand All @@ -41,6 +42,7 @@ protected void configure() {
bind(CertificateExchange.class).to(CertificateExchangeImpl.class);

addPreflightCheck(OpensearchConfigSync.class);
addPreflightCheck(DatanodeDnsPreflightCheck.class);
addPreflightCheck(OpensearchBinPreflightCheck.class);
addPreflightCheck(DatanodeDirectoriesLockfileCheck.class);
addPreflightCheck(OpenSearchPreconditionsCheck.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog.datanode.bootstrap.preflight;

import jakarta.inject.Inject;
import org.graylog.datanode.Configuration;
import org.graylog2.bootstrap.preflight.PreflightCheck;
import org.graylog2.bootstrap.preflight.PreflightCheckException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.stream.Stream;

public class DatanodeDnsPreflightCheck implements PreflightCheck {

private static final Logger LOG = LoggerFactory.getLogger(DatanodeDnsPreflightCheck.class);

private final String configuredHostname;

@Inject
public DatanodeDnsPreflightCheck(Configuration datanodeConfiguration) {
configuredHostname = datanodeConfiguration.getHostname();
}

@Override
public void runCheck() throws PreflightCheckException {
try {
final InetAddress[] addresses = InetAddress.getAllByName(configuredHostname);
final List<String> ips = Stream.of(addresses).map(InetAddress::getHostAddress).toList();
LOG.debug("Datanode host {} is available on {} addresses", configuredHostname, ips);
} catch (UnknownHostException e) {
throw new PreflightCheckException("Configured hostname " + configuredHostname + " is not bound to any address! Please configure your DNS so the hostname points to this machine");
}
}
}

0 comments on commit 0d94bf1

Please sign in to comment.