Skip to content

Commit 3fe708f

Browse files
authored
Log system information early during startup (elastic#124926) (elastic#124946)
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.
1 parent 9da7f0b commit 3fe708f

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
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
%*

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/SystemJvmOptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class SystemJvmOptions {
2626

2727
static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, String> sysprops) {
2828
String distroType = sysprops.get("es.distribution.type");
29+
String javaType = sysprops.get("es.java.type");
2930
boolean isHotspot = sysprops.getOrDefault("sun.management.compiler", "").contains("HotSpot");
3031
boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(sysprops.getOrDefault("es.entitlements.enabled", "true"));
3132
// java 24+ only supports entitlements, but it may be enabled on earlier versions explicitly
@@ -68,8 +69,9 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
6869
"-Djava.locale.providers=CLDR",
6970
// Enable vectorization for whatever version we are running. This ensures we use vectorization even when running EA builds.
7071
"-Dorg.apache.lucene.vectorization.upperJavaFeatureVersion=" + Runtime.version().feature(),
71-
// Pass through distribution type
72-
"-Des.distribution.type=" + distroType
72+
// Pass through distribution type and java type
73+
"-Des.distribution.type=" + distroType,
74+
"-Des.java.type=" + javaType
7375
),
7476
maybeEnableNativeAccess(useEntitlements),
7577
maybeOverrideDockerCgroup(distroType),

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;
@@ -57,6 +58,7 @@
5758
import java.io.InputStream;
5859
import java.io.PrintStream;
5960
import java.lang.invoke.MethodHandles;
61+
import java.lang.management.ManagementFactory;
6062
import java.lang.reflect.InvocationTargetException;
6163
import java.nio.file.Files;
6264
import java.nio.file.Path;
@@ -66,6 +68,7 @@
6668
import java.util.HashMap;
6769
import java.util.HashSet;
6870
import java.util.List;
71+
import java.util.Locale;
6972
import java.util.Map;
7073
import java.util.Objects;
7174
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);
@@ -285,6 +291,35 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
285291
bootstrap.setPluginsLoader(pluginsLoader);
286292
}
287293

294+
private static void logSystemInfo() {
295+
final Logger logger = LogManager.getLogger(Elasticsearch.class);
296+
logger.info(
297+
"version[{}], pid[{}], build[{}/{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
298+
Build.current().qualifiedVersion(),
299+
ProcessHandle.current().pid(),
300+
Build.current().type().displayName(),
301+
Build.current().hash(),
302+
Build.current().date(),
303+
Constants.OS_NAME,
304+
Constants.OS_VERSION,
305+
Constants.OS_ARCH,
306+
Constants.JVM_VENDOR,
307+
Constants.JVM_NAME,
308+
System.getProperty("java.version"),
309+
Runtime.version().toString()
310+
);
311+
boolean isBundledJdk = System.getProperty("es.java.type", "").equals("bundled JDK");
312+
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), isBundledJdk);
313+
logger.info("JVM arguments {}", ManagementFactory.getRuntimeMXBean().getInputArguments());
314+
logger.info("Default Locale [{}]", Locale.getDefault());
315+
if (Build.current().isProductionRelease() == false) {
316+
logger.warn(
317+
"version [{}] is a pre-release version of Elasticsearch and is not suitable for production",
318+
Build.current().qualifiedVersion()
319+
);
320+
}
321+
}
322+
288323
private static Map<String, String> collectPluginPolicyOverrides(
289324
Set<PluginBundle> modulesBundles,
290325
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;
@@ -411,30 +408,6 @@ private Settings createEnvironment(Environment initialEnvironment, NodeServicePr
411408
DeprecationLogger.initialize(envSettings);
412409

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

0 commit comments

Comments
 (0)