Skip to content

Commit

Permalink
SOLR-15960 Unified use of system properties and environment variables (
Browse files Browse the repository at this point in the history
  • Loading branch information
janhoy authored Jan 5, 2024
1 parent 53eba0a commit 10bbabb
Show file tree
Hide file tree
Showing 19 changed files with 540 additions and 78 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Improvements
using the `withDefaultCollection` method. This is preferable to including the collection
in the base URL accepted by certain client implementations. (Jason Gerlowski)

* SOLR-15960: Unified use of system properties and environment variables (janhoy)

Optimizations
---------------------
* SOLR-17084: LBSolrClient (used by CloudSolrClient) now returns the count of core tracked as not live AKA zombies
Expand Down
40 changes: 8 additions & 32 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ elif [ -r "$SOLR_INCLUDE" ]; then
. "$SOLR_INCLUDE"
fi

# Export variables we want to make visible to Solr sub-process
for var in $(compgen -e); do
if [[ "$var" =~ ^(SOLR_.*|DEFAULT_CONFDIR|ZK_.*|GCS_BUCKET|GCS_.*|S3_.*|OTEL_.*|AWS_.*)$ ]]; then
export "${var?}"
fi
done

# if pid dir is unset, default to $solr_tip/bin
: "${SOLR_PID_DIR:=$SOLR_TIP/bin}"

Expand Down Expand Up @@ -1357,12 +1364,10 @@ if [ $# -gt 0 ]; then
;;
-v)
SOLR_LOG_LEVEL=DEBUG
PASS_TO_RUN_EXAMPLE+=("-Dsolr.log.level=$SOLR_LOG_LEVEL")
shift
;;
-q)
SOLR_LOG_LEVEL=WARN
PASS_TO_RUN_EXAMPLE+=("-Dsolr.log.level=$SOLR_LOG_LEVEL")
shift
;;
-all)
Expand Down Expand Up @@ -1396,15 +1401,6 @@ if [ $# -gt 0 ]; then
done
fi

if [[ -n ${SOLR_LOG_LEVEL:-} ]] ; then
SOLR_LOG_LEVEL_OPT="-Dsolr.log.level=$SOLR_LOG_LEVEL"
fi

# Solr modules option
if [[ -n "${SOLR_MODULES:-}" ]] ; then
SCRIPT_SOLR_OPTS+=("-Dsolr.modules=$SOLR_MODULES")
fi

# Default placement plugin
if [[ -n "${SOLR_PLACEMENTPLUGIN_DEFAULT:-}" ]] ; then
SCRIPT_SOLR_OPTS+=("-Dsolr.placementplugin.default=$SOLR_PLACEMENTPLUGIN_DEFAULT")
Expand All @@ -1418,26 +1414,6 @@ if [ "${SOLR_ENABLE_STREAM_BODY:-false}" == "true" ]; then
SCRIPT_SOLR_OPTS+=("-Dsolr.enableStreamBody=true")
fi

# Parse global circuit breaker env vars and convert to dot separated, lowercase properties
if [ -n "${SOLR_CIRCUITBREAKER_UPDATE_CPU:-}" ]; then
SOLR_OPTS+=("-Dsolr.circuitbreaker.update.cpu=$SOLR_CIRCUITBREAKER_UPDATE_CPU")
fi
if [ -n "${SOLR_CIRCUITBREAKER_UPDATE_MEM:-}" ]; then
SOLR_OPTS+=("-Dsolr.circuitbreaker.update.mem=$SOLR_CIRCUITBREAKER_UPDATE_MEM")
fi
if [ -n "${SOLR_CIRCUITBREAKER_UPDATE_LOADAVG:-}" ]; then
SOLR_OPTS+=("-Dsolr.circuitbreaker.update.loadavg=$SOLR_CIRCUITBREAKER_UPDATE_LOADAVG")
fi
if [ -n "${SOLR_CIRCUITBREAKER_QUERY_CPU:-}" ]; then
SOLR_OPTS+=("-Dsolr.circuitbreaker.query.cpu=$SOLR_CIRCUITBREAKER_QUERY_CPU")
fi
if [ -n "${SOLR_CIRCUITBREAKER_QUERY_MEM:-}" ]; then
SOLR_OPTS+=("-Dsolr.circuitbreaker.query.mem=$SOLR_CIRCUITBREAKER_QUERY_MEM")
fi
if [ -n "${SOLR_CIRCUITBREAKER_QUERY_LOADAVG:-}" ]; then
SOLR_OPTS+=("-Dsolr.circuitbreaker.query.loadavg=$SOLR_CIRCUITBREAKER_QUERY_LOADAVG")
fi

: ${SOLR_SERVER_DIR:=$DEFAULT_SERVER_DIR}

if [ ! -e "$SOLR_SERVER_DIR" ]; then
Expand Down Expand Up @@ -1915,7 +1891,7 @@ function start_solr() {
fi

SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE_ARR[@]}" "${GC_LOG_OPTS[@]}" "${IP_ACL_OPTS[@]}" \
"${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" ${SOLR_LOG_LEVEL_OPT:-} -Dsolr.log.dir="$SOLR_LOGS_DIR" \
"${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" -Dsolr.log.dir="$SOLR_LOGS_DIR" \
"-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \
# '-OmitStackTraceInFastThrow' ensures stack traces in errors,
# users who don't care about useful error msgs can override in SOLR_OPTS with +OmitStackTraceInFastThrow
Expand Down
8 changes: 0 additions & 8 deletions solr/bin/solr.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,11 @@ goto parse_args

:set_debug
set SOLR_LOG_LEVEL=DEBUG
set "PASS_TO_RUN_EXAMPLE=!PASS_TO_RUN_EXAMPLE! -Dsolr.log.level=%SOLR_LOG_LEVEL%"
SHIFT
goto parse_args

:set_warn
set SOLR_LOG_LEVEL=WARN
set "PASS_TO_RUN_EXAMPLE=!PASS_TO_RUN_EXAMPLE! -Dsolr.log.level=%SOLR_LOG_LEVEL%"
SHIFT
goto parse_args

Expand Down Expand Up @@ -830,11 +828,6 @@ IF NOT "%SOLR_HOST%"=="" (

set SCRIPT_SOLR_OPTS=

REM Solr modules option
IF DEFINED SOLR_MODULES (
set "SCRIPT_SOLR_OPTS=%SCRIPT_SOLR_OPTS% -Dsolr.modules=%SOLR_MODULES%"
)

REM Default placement plugin
IF DEFINED SOLR_PLACEMENTPLUGIN_DEFAULT (
set "SCRIPT_SOLR_OPTS=%SCRIPT_SOLR_OPTS% -Dsolr.placementplugin.default=%SOLR_PLACEMENTPLUGIN_DEFAULT%"
Expand Down Expand Up @@ -1238,7 +1231,6 @@ IF "%SOLR_SSL_ENABLED%"=="true" (
set "SSL_PORT_PROP=-Dsolr.jetty.https.port=%SOLR_PORT%"
set "START_OPTS=%START_OPTS% %SOLR_SSL_OPTS% !SSL_PORT_PROP!"
)
IF NOT "%SOLR_LOG_LEVEL%"=="" set "START_OPTS=%START_OPTS% -Dsolr.log.level=%SOLR_LOG_LEVEL%"

set SOLR_LOGS_DIR_QUOTED="%SOLR_LOGS_DIR%"
set SOLR_DATA_HOME_QUOTED="%SOLR_DATA_HOME%"
Expand Down
5 changes: 4 additions & 1 deletion solr/bin/solr.in.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ REM start command line as-is, in ADDITION to other options. If you specify the
REM -a option on start script, those options will be appended as well. Examples:
REM set SOLR_OPTS=%SOLR_OPTS% -Dsolr.autoSoftCommit.maxTime=3000
REM set SOLR_OPTS=%SOLR_OPTS% -Dsolr.autoCommit.maxTime=60000
REM set SOLR_OPTS=%SOLR_OPTS% -Dsolr.clustering.enabled=true

REM Most properties have an environment variable equivalent.
REM A naming convention is that SOLR_FOO_BAR maps to solr.foo.bar
REM SOLR_CLUSTERING_ENABLED=true

REM Path to a directory for Solr to store cores and their data. By default, Solr will use server\solr
REM If solr.xml is not stored in ZooKeeper, this directory needs to contain solr.xml
Expand Down
5 changes: 4 additions & 1 deletion solr/bin/solr.in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
# -a option on start script, those options will be appended as well. Examples:
#SOLR_OPTS="$SOLR_OPTS -Dsolr.autoSoftCommit.maxTime=3000"
#SOLR_OPTS="$SOLR_OPTS -Dsolr.autoCommit.maxTime=60000"
#SOLR_OPTS="$SOLR_OPTS -Dsolr.clustering.enabled=true"

# Most properties have an environment variable equivalent.
# A naming convention is that SOLR_FOO_BAR maps to solr.foo.bar
#SOLR_CLUSTERING_ENABLED=true

# Location where the bin/solr script will save PID files for running instances
# If not set, the script will create PID files in $SOLR_TIP/bin
Expand Down
16 changes: 4 additions & 12 deletions solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.util.EnvUtils;
import org.apache.solr.util.StartupLoggingUtils;
import org.apache.solr.util.configuration.SSLConfigurationsFactory;
import org.slf4j.Logger;
Expand Down Expand Up @@ -197,18 +198,9 @@ public static CommandLine parseCmdLine(String toolName, String[] args, List<Opti
}

public static String getDefaultSolrUrl() {
String scheme = System.getenv("SOLR_URL_SCHEME");
if (scheme == null) {
scheme = "http";
}
String host = System.getenv("SOLR_TOOL_HOST");
if (host == null) {
host = "localhost";
}
String port = System.getenv("SOLR_PORT");
if (port == null) {
port = "8983";
}
String scheme = EnvUtils.getEnv("SOLR_URL_SCHEME", "http");
String host = EnvUtils.getEnv("SOLR_TOOL_HOST", "localhost");
String port = EnvUtils.getEnv("SOLR_PORT", "8983");
return String.format(Locale.ROOT, "%s://%s:%s", scheme.toLowerCase(Locale.ROOT), host, port);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.util.EnvUtils;
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
import org.apache.solr.util.tracing.SimplePropagator;
import org.apache.solr.util.tracing.TraceUtils;
Expand All @@ -37,10 +38,10 @@
public abstract class TracerConfigurator implements NamedListInitializedPlugin {

public static final boolean TRACE_ID_GEN_ENABLED =
Boolean.parseBoolean(System.getProperty("solr.alwaysOnTraceId", "true"));
Boolean.parseBoolean(EnvUtils.getProp("solr.alwaysOnTraceId", "true"));

private static final String DEFAULT_CLASS_NAME =
System.getProperty(
EnvUtils.getProp(
"solr.otelDefaultConfigurator", "org.apache.solr.opentelemetry.OtelTracerConfigurator");

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/pkg/PackageAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.solr.filestore.FileStoreAPI;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.EnvUtils;
import org.apache.solr.util.SolrJacksonAnnotationInspector;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
Expand All @@ -57,8 +58,7 @@

/** This implements the public end points (/api/cluster/package) of package API. */
public class PackageAPI {
public final boolean enablePackages =
Boolean.parseBoolean(System.getProperty("enable.packages", "false"));
public final boolean enablePackages = EnvUtils.getPropAsBool("enable.packages", false);
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String ERR_MSG =
Expand Down
Loading

0 comments on commit 10bbabb

Please sign in to comment.