Skip to content

Commit d3bc46b

Browse files
moscherjernst
andauthored
Log system information early during startup (#124926) (#131853)
Information about the system, and in particular the running JVM, is logged relatively late in startup. When problems occur in low level initialization, it is often useful to have this information. This commit moves logging of system information to right after logging has been initialized. Note that it no longer utilizes the JvmInfo class as most was already easily available and the static init of JvmInfo does a lot. (cherry picked from commit 789eb2f) # Conflicts: # server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java # server/src/main/java/org/elasticsearch/node/NodeConstruction.java Co-authored-by: Ryan Ernst <[email protected]>
1 parent 5ff4ab9 commit d3bc46b

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

distribution/src/bin/elasticsearch-cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exec \
1919
-Des.path.home="$ES_HOME" \
2020
-Des.path.conf="$ES_PATH_CONF" \
2121
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
22+
-Des.java.type="$JAVA_TYPE" \
2223
-cp "$LAUNCHER_CLASSPATH" \
2324
org.elasticsearch.launcher.CliToolLauncher \
2425
"$@"

distribution/src/bin/elasticsearch-cli.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set LAUNCHER_CLASSPATH=%ES_HOME%/lib/*;%ES_HOME%/lib/cli-launcher/*
1818
-Des.path.home="%ES_HOME%" ^
1919
-Des.path.conf="%ES_PATH_CONF%" ^
2020
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
21+
-Des.java.type="%JAVA_TYPE%" ^
2122
-cp "%LAUNCHER_CLASSPATH%" ^
2223
org.elasticsearch.launcher.CliToolLauncher ^
2324
%*

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.logging.log4j.core.LoggerContext;
1515
import org.apache.logging.log4j.core.config.Configurator;
16+
import org.apache.lucene.util.Constants;
1617
import org.apache.lucene.util.StringHelper;
1718
import org.apache.lucene.util.VectorUtil;
1819
import org.elasticsearch.Build;
@@ -55,6 +56,7 @@
5556
import java.io.InputStream;
5657
import java.io.PrintStream;
5758
import java.lang.invoke.MethodHandles;
59+
import java.lang.management.ManagementFactory;
5860
import java.lang.reflect.InvocationTargetException;
5961
import java.nio.file.Files;
6062
import java.nio.file.Path;
@@ -64,6 +66,7 @@
6466
import java.util.HashMap;
6567
import java.util.HashSet;
6668
import java.util.List;
69+
import java.util.Locale;
6770
import java.util.Map;
6871
import java.util.Objects;
6972
import java.util.Set;
@@ -176,6 +179,9 @@ public void checkPermission(Permission perm) {
176179
* <p> Phase 2 consists of everything that must occur up to and including security manager initialization.
177180
*/
178181
private static void initPhase2(Bootstrap bootstrap) throws IOException {
182+
// always start by dumping what we know about the process to the log
183+
logSystemInfo();
184+
179185
final ServerArgs args = bootstrap.args();
180186
final SecureSettings secrets = args.secrets();
181187
bootstrap.setSecureSettings(secrets);
@@ -289,6 +295,35 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
289295
bootstrap.setPluginsLoader(pluginsLoader);
290296
}
291297

298+
private static void logSystemInfo() {
299+
final Logger logger = LogManager.getLogger(Elasticsearch.class);
300+
logger.info(
301+
"version[{}], pid[{}], build[{}/{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
302+
Build.current().qualifiedVersion(),
303+
ProcessHandle.current().pid(),
304+
Build.current().type().displayName(),
305+
Build.current().hash(),
306+
Build.current().date(),
307+
Constants.OS_NAME,
308+
Constants.OS_VERSION,
309+
Constants.OS_ARCH,
310+
Constants.JVM_VENDOR,
311+
Constants.JVM_NAME,
312+
System.getProperty("java.version"),
313+
Runtime.version().toString()
314+
);
315+
boolean isBundledJdk = System.getProperty("es.java.type", "").equals("bundled JDK");
316+
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), isBundledJdk);
317+
logger.info("JVM arguments {}", ManagementFactory.getRuntimeMXBean().getInputArguments());
318+
logger.info("Default Locale [{}]", Locale.getDefault());
319+
if (Build.current().isProductionRelease() == false) {
320+
logger.warn(
321+
"version [{}] is a pre-release version of Elasticsearch and is not suitable for production",
322+
Build.current().qualifiedVersion()
323+
);
324+
}
325+
}
326+
292327
private static Map<String, String> collectPluginPolicyPatches(
293328
Set<PluginBundle> modulesBundles,
294329
Set<PluginBundle> pluginsBundles,

server/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99

1010
package org.elasticsearch.monitor.jvm;
1111

12-
import org.apache.lucene.util.Constants;
1312
import org.elasticsearch.TransportVersions;
1413
import org.elasticsearch.common.io.stream.StreamInput;
1514
import org.elasticsearch.common.io.stream.StreamOutput;
1615
import org.elasticsearch.common.io.stream.Writeable;
1716
import org.elasticsearch.common.unit.ByteSizeValue;
18-
import org.elasticsearch.core.PathUtils;
19-
import org.elasticsearch.core.SuppressForbidden;
2017
import org.elasticsearch.node.ReportingService;
2118
import org.elasticsearch.xcontent.XContentBuilder;
2219

@@ -168,19 +165,8 @@ public class JvmInfo implements ReportingService.Info {
168165
);
169166
}
170167

171-
@SuppressForbidden(reason = "PathUtils#get")
172168
private static boolean usingBundledJdk() {
173-
/*
174-
* We are using the bundled JDK if java.home is the jdk sub-directory of our working directory. This is because we always set
175-
* the working directory of Elasticsearch to home, and the bundled JDK is in the jdk sub-directory there.
176-
*/
177-
final String javaHome = System.getProperty("java.home");
178-
final String userDir = System.getProperty("user.dir");
179-
if (Constants.MAC_OS_X) {
180-
return PathUtils.get(javaHome).equals(PathUtils.get(userDir).resolve("jdk.app/Contents/Home").toAbsolutePath());
181-
} else {
182-
return PathUtils.get(javaHome).equals(PathUtils.get(userDir).resolve("jdk").toAbsolutePath());
183-
}
169+
return System.getProperty("es.java.type", "").equals("bundled JDK");
184170
}
185171

186172
public static JvmInfo jvmInfo() {

server/src/main/java/org/elasticsearch/node/NodeConstruction.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.lucene.search.IndexSearcher;
15-
import org.apache.lucene.util.Constants;
1615
import org.apache.lucene.util.SetOnce;
17-
import org.elasticsearch.Build;
1816
import org.elasticsearch.ElasticsearchException;
1917
import org.elasticsearch.TransportVersion;
2018
import org.elasticsearch.action.ActionModule;
@@ -229,7 +227,6 @@
229227
import java.util.IdentityHashMap;
230228
import java.util.LinkedHashSet;
231229
import java.util.List;
232-
import java.util.Locale;
233230
import java.util.Map;
234231
import java.util.Objects;
235232
import java.util.Optional;
@@ -410,30 +407,6 @@ private Settings createEnvironment(Environment initialEnvironment, NodeServicePr
410407
DeprecationLogger.initialize(envSettings);
411408

412409
JvmInfo jvmInfo = JvmInfo.jvmInfo();
413-
logger.info(
414-
"version[{}], pid[{}], build[{}/{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
415-
Build.current().qualifiedVersion(),
416-
jvmInfo.pid(),
417-
Build.current().type().displayName(),
418-
Build.current().hash(),
419-
Build.current().date(),
420-
Constants.OS_NAME,
421-
Constants.OS_VERSION,
422-
Constants.OS_ARCH,
423-
Constants.JVM_VENDOR,
424-
Constants.JVM_NAME,
425-
Constants.JAVA_VERSION,
426-
Constants.JVM_VERSION
427-
);
428-
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), jvmInfo.getUsingBundledJdk());
429-
logger.info("JVM arguments {}", Arrays.toString(jvmInfo.getInputArguments()));
430-
logger.info("Default Locale [{}]", Locale.getDefault());
431-
if (Build.current().isProductionRelease() == false) {
432-
logger.warn(
433-
"version [{}] is a pre-release version of Elasticsearch and is not suitable for production",
434-
Build.current().qualifiedVersion()
435-
);
436-
}
437410
if (Environment.PATH_SHARED_DATA_SETTING.exists(envSettings)) {
438411
// NOTE: this must be done with an explicit check here because the deprecation property on a path setting will
439412
// cause ES to fail to start since logging is not yet initialized on first read of the setting

0 commit comments

Comments
 (0)