diff --git a/bin/performance-analyzer-agent b/bin/performance-analyzer-agent index b9c3a77ee..6ce79cbaa 100755 --- a/bin/performance-analyzer-agent +++ b/bin/performance-analyzer-agent @@ -28,12 +28,19 @@ fi echo "Using JAVA_HOME: $JAVA_HOME" export JAVA_HOME=$JAVA_HOME +if [[ -z "$OPENSEARCH_PATH_CONF" ]]; then + echo "OPENSEARCH_PATH_CONF needs to be set." + exit 1 +fi + +echo "Using OPENSEARCH_PATH_CONF: $OPENSEARCH_PATH_CONF" + if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then - export JAVA_OPTS=-Dopensearch.path.home=$OPENSEARCH_HOME\ -Dlog4j.configurationFile=$OPENSEARCH_HOME/performance-analyzer-rca/config/log4j2.xml\ -XX:+ExitOnOutOfMemoryError + export JAVA_OPTS=-Dopensearch.path.home=$OPENSEARCH_HOME\ -Dopensearch.path.conf=$OPENSEARCH_PATH_CONF\ -Dlog4j.configurationFile=$OPENSEARCH_HOME/performance-analyzer-rca/config/log4j2.xml\ -XX:+ExitOnOutOfMemoryError exec $OPENSEARCH_HOME/performance-analyzer-rca/bin/performance-analyzer-rca else echo 'Starting deamon' - export JAVA_OPTS=-Dopensearch.path.home=$OPENSEARCH_HOME\ -Dlog4j.configurationFile=$OPENSEARCH_HOME/performance-analyzer-rca/config/log4j2.xml\ -XX:+ExitOnOutOfMemoryError + export JAVA_OPTS=-Dopensearch.path.home=$OPENSEARCH_HOME\ -Dopensearch.path.conf=$OPENSEARCH_PATH_CONF\ -Dlog4j.configurationFile=$OPENSEARCH_HOME/performance-analyzer-rca/config/log4j2.xml\ -XX:+ExitOnOutOfMemoryError exec $OPENSEARCH_HOME/performance-analyzer-rca/bin/performance-analyzer-rca & pid=$! diff --git a/docker/Dockerfile b/docker/Dockerfile index 13296e076..3fe4288cb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -88,6 +88,7 @@ RUN yum update -y && \ COPY CENTOS_LICENSING.txt /root COPY --from=prep_open_search_files --chown=1000:0 /opt/jdk-11.0.1 /opt/jdk-11.0.1 ENV OPENSEARCH_JAVA_HOME /opt/jdk-11.0.1 +ENV OPENSEARCH_PATH_CONF /usr/share/opensearch/config # Replace OpenJDK's built-in CA certificate keystore with the one from the OS # vendor. The latter is superior in several ways. diff --git a/src/main/java/org/opensearch/performanceanalyzer/collectors/StatsCollector.java b/src/main/java/org/opensearch/performanceanalyzer/collectors/StatsCollector.java index c8fa24288..20d4c3ce7 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/collectors/StatsCollector.java +++ b/src/main/java/org/opensearch/performanceanalyzer/collectors/StatsCollector.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.Logger; import org.opensearch.performanceanalyzer.PerformanceAnalyzerApp; import org.opensearch.performanceanalyzer.config.PluginSettings; -import org.opensearch.performanceanalyzer.core.Util; import org.opensearch.performanceanalyzer.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.rca.Version; import org.opensearch.performanceanalyzer.rca.formatter.StatsCollectorFormatter; @@ -146,13 +145,15 @@ private static Map loadMetadata(String fileLocation) { try (InputStream input = new FileInputStream( - Util.PLUGIN_LOCATION - + PluginSettings.CONFIG_FILES_PATH - + fileLocation); ) { + PluginSettings.instance().getConfigFolderPath() + fileLocation); ) { // load properties file props.load(input); } catch (Exception ex) { - GENERAL_LOG.error("Error in loading metadata for fileLocation: {}", fileLocation); + GENERAL_LOG.error( + "Error in loading metadata for folderLocation: {}, fileLocation: {}", + PluginSettings.instance().getConfigFolderPath(), + fileLocation, + ex); } props.forEach((key, value) -> retVal.put((String) key, (String) value)); diff --git a/src/main/java/org/opensearch/performanceanalyzer/config/PluginSettings.java b/src/main/java/org/opensearch/performanceanalyzer/config/PluginSettings.java index 43dba0fdc..73060bc39 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/config/PluginSettings.java +++ b/src/main/java/org/opensearch/performanceanalyzer/config/PluginSettings.java @@ -23,14 +23,15 @@ public class PluginSettings { private static PluginSettings instance; public static final String CONFIG_FILES_PATH = "config/"; - private static final String DEFAULT_CONFIG_FILE_PATH = + public static final String DEFAULT_CONFIG_FOLDER_PATH = OPENSEARCH_HOME + File.separator + "config" + File.separator + "opensearch-performance-analyzer" - + File.separator - + "performance-analyzer.properties"; + + File.separator; + private static final String DEFAULT_CONFIG_FILE_PATH = + DEFAULT_CONFIG_FOLDER_PATH + "performance-analyzer.properties"; private static final String METRICS_LOCATION_KEY = "metrics-location"; private static final String METRICS_LOCATION_DEFAULT = "/dev/shm/performanceanalyzer/"; private static final String DELETION_INTERVAL_KEY = "metrics-deletion-interval"; @@ -64,6 +65,7 @@ public class PluginSettings { private boolean httpsEnabled; private Properties settings; + private final String configFolderPath; private final String configFilePath; /** @@ -79,6 +81,10 @@ public class PluginSettings { Util.invokePrivilegedAndLogError(PluginSettings::createInstance); } + public String getConfigFolderPath() { + return configFolderPath; + } + public String getMetricsLocation() { return metricsLocation; } @@ -170,9 +176,12 @@ private PluginSettings(String cfPath) { rpcPort = RPC_DEFAULT_PORT; webServicePort = WEBSERVICE_DEFAULT_PORT; if (cfPath == null || cfPath.isEmpty()) { + this.configFolderPath = DEFAULT_CONFIG_FOLDER_PATH; this.configFilePath = DEFAULT_CONFIG_FILE_PATH; } else { - this.configFilePath = cfPath; + this.configFolderPath = + cfPath + File.separator + "opensearch-performance-analyzer" + File.separator; + this.configFilePath = configFolderPath + "performance-analyzer.properties"; } settings = new Properties(); @@ -216,7 +225,7 @@ public static PluginSettings instance() { } private static void createInstance() { - String cfPath = System.getProperty("configFilePath"); + String cfPath = System.getProperty("opensearch.path.conf"); instance = new PluginSettings(cfPath); }