From: Jacek Date: Wed, 4 Jan 2023 10:13:34 +0000 (+0100) Subject: SONAR-17781 Allow overwriting path for 'es_hs_err_pid%p.log' X-Git-Tag: 9.9.0.65466~112 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0611f1bd4d4e7132434d144a94996fe47a32e062;p=sonarqube.git SONAR-17781 Allow overwriting path for 'es_hs_err_pid%p.log' --- diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java index 19ab60e9164..89d289724a0 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java +++ b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Paths; import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Collectors; @@ -43,7 +44,7 @@ public class EsJvmOptions extends JvmOptions { // with some changes to fit running bundled in SQ private static Map mandatoryOptions(File tmpDir, Props props) { Map res = new LinkedHashMap<>(30); - fromJvmDotOptionsFile(tmpDir, res); + fromJvmDotOptionsFile(tmpDir, res, props); fromSystemJvmOptionsClass(tmpDir, res); boolean defaultDisableBootstrapChecks = props.value("sonar.jdbc.url", "").contains("jdbc:h2"); @@ -54,7 +55,7 @@ public class EsJvmOptions extends JvmOptions { return res; } - private static void fromJvmDotOptionsFile(File tmpDir, Map res) { + private static void fromJvmDotOptionsFile(File tmpDir, Map res, Props props) { // GC configuration res.put("-XX:+UseG1GC", ""); @@ -70,7 +71,8 @@ public class EsJvmOptions extends JvmOptions { // has sufficient space // res.put("-XX:HeapDumpPath", "data"); // specify an alternative path for JVM fatal error logs (ES 6.6.1 default is "logs/hs_err_pid%p.log") - res.put("-XX:ErrorFile=", "../logs/es_hs_err_pid%p.log"); + var path = Paths.get(props.value("sonar.path.logs", "logs"), "es_hs_err_pid%p.log"); + res.put("-XX:ErrorFile=", path.toAbsolutePath().toString()); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java index 1c2b634cb0a..2de7f134905 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java @@ -22,7 +22,9 @@ package org.sonar.application.command; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import java.io.File; import java.io.IOException; +import java.nio.file.Paths; import java.util.Properties; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -36,9 +38,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; @RunWith(DataProviderRunner.class) public class EsJvmOptionsTest { @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - private Properties properties = new Properties(); + private final Properties properties = new Properties(); + + @Before + public void before() { + properties.put("sonar.path.logs", "path_to_logs"); + } @Test public void constructor_sets_mandatory_JVM_options() throws IOException { @@ -49,7 +56,7 @@ public class EsJvmOptionsTest { .containsExactlyInAnyOrder( "-XX:+UseG1GC", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), - "-XX:ErrorFile=../logs/es_hs_err_pid%p.log", + "-XX:ErrorFile=" + Paths.get("path_to_logs/es_hs_err_pid%p.log").toAbsolutePath(), "-Des.networkaddress.cache.ttl=60", "-Des.networkaddress.cache.negative.ttl=10", "-XX:+AlwaysPreTouch", @@ -121,8 +128,8 @@ public class EsJvmOptionsTest { EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir); assertThat(underTest.getAll()) - .isNotEmpty() - .doesNotContain("-Des.enforce.bootstrap.checks=true"); + .isNotEmpty() + .doesNotContain("-Des.enforce.bootstrap.checks=true"); } @Test @@ -134,8 +141,8 @@ public class EsJvmOptionsTest { EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir); assertThat(underTest.getAll()) - .isNotEmpty() - .contains("-Des.enforce.bootstrap.checks=true"); + .isNotEmpty() + .contains("-Des.enforce.bootstrap.checks=true"); } @Test @@ -147,8 +154,8 @@ public class EsJvmOptionsTest { EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir); assertThat(underTest.getAll()) - .isNotEmpty() - .doesNotContain("-Des.enforce.bootstrap.checks=true"); + .isNotEmpty() + .doesNotContain("-Des.enforce.bootstrap.checks=true"); } @Test @@ -160,8 +167,8 @@ public class EsJvmOptionsTest { EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir); assertThat(underTest.getAll()) - .isNotEmpty() - .contains("-Des.enforce.bootstrap.checks=true"); + .isNotEmpty() + .contains("-Des.enforce.bootstrap.checks=true"); } /** @@ -185,7 +192,7 @@ public class EsJvmOptionsTest { "\n" + "-XX:+UseG1GC\n" + "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" + - "-XX:ErrorFile=../logs/es_hs_err_pid%p.log\n" + + "-XX:ErrorFile=" + Paths.get("path_to_logs/es_hs_err_pid%p.log").toAbsolutePath() + "\n" + "-Des.networkaddress.cache.ttl=60\n" + "-Des.networkaddress.cache.negative.ttl=10\n" + "-XX:+AlwaysPreTouch\n" +