Skip to content

Commit

Permalink
SOLR-17481: Resolve use of -n flag in CLI commands (#2745)
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh authored Oct 10, 2024
1 parent af54816 commit a4cc580
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public String getName() {
@Override
public List<Option> getOptions() {
return List.of(
Option.builder("n")
Option.builder()
.longOpt("no-prompt")
.required(false)
.desc(
Expand Down
2 changes: 1 addition & 1 deletion solr/prometheus-exporter/bin/solr-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ if [[ -n "$SCRAPE_INTERVAL" ]]; then
fi

if [[ -n "$NUM_THREADS" ]]; then
EXPORTER_ARGS+=(-n "$NUM_THREADS")
EXPORTER_ARGS+=(--num-threads "$NUM_THREADS")
fi

if [[ -n "$ZK_HOST" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion solr/prometheus-exporter/bin/solr-exporter.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ set EXPORTER_ARGS=
IF NOT "%CONFIG_FILE%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% --config-file %CONFIG_FILE%
IF NOT "%PORT%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -p %PORT%
IF NOT "%SCRAPE_INTERVAL%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% --scrape-interval %SCRAPE_INTERVAL%
IF NOT "%NUM_THREADS%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -n %NUM_THREADS%
IF NOT "%NUM_THREADS%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% --num-threads %NUM_THREADS%
IF NOT "%ZK_HOST%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -z %ZK_HOST%
IF NOT "%SOLR_URL%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -b %SOLR_URL%
IF NOT "%CLUSTER_ID%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -i "%CLUSTER_ID%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public static void main(String[] args) {
mainOptions.addOption(clusterIdOption);

Option numThreadsOption =
Option.builder("n")
Option.builder()
.longOpt("num-threads")
.hasArg()
.argName("NUM_THREADS")
Expand All @@ -225,6 +225,23 @@ public static void main(String[] args) {
+ ".")
.build();
mainOptions.addOption(numThreadsOption);
Option numThreadsOptionDeprecated =
Option.builder("n")
.hasArg()
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --num-threads instead")
.get())
.argName("NUM_THREADS")
.type(Integer.class)
.desc(
"Specify the number of threads. solr-exporter creates a thread pools for request to Solr. If you need to improve request latency via solr-exporter, you can increase the number of threads; the default is "
+ DEFAULT_NUM_THREADS
+ ".")
.build();
mainOptions.addOption(numThreadsOptionDeprecated);

Option portOption =
Option.builder("p")
Expand Down Expand Up @@ -366,6 +383,12 @@ public static void main(String[] args) {
} else if (commandLine.hasOption(configOption)) {
configFile = commandLine.getOptionValue(configOption);
}
int numberOfThreads = DEFAULT_NUM_THREADS;
if (commandLine.hasOption("num-threads")) {
numberOfThreads = commandLine.getParsedOptionValue("num-threads");
} else if (commandLine.hasOption("n")) {
numberOfThreads = commandLine.getParsedOptionValue("n");
}

int scrapeInterval = DEFAULT_SCRAPE_INTERVAL;
if (commandLine.hasOption("s")) {
Expand All @@ -377,7 +400,7 @@ public static void main(String[] args) {
SolrExporter solrExporter =
new SolrExporter(
port,
commandLine.getParsedOptionValue(numThreadsOption, DEFAULT_NUM_THREADS),
numberOfThreads,
scrapeInterval,
scrapeConfiguration,
loadMetricsConfiguration(configFile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ Linux::
[source,bash]
----
$ cd prometheus-exporter
$ ./bin/solr-exporter -p 9854 -b http://localhost:8983/solr --config-file ./conf/solr-exporter-config.xml -n 8
$ ./bin/solr-exporter -p 9854 -b http://localhost:8983/solr --config-file ./conf/solr-exporter-config.xml --num-threads 8
----

.SolrCloud
[source,bash]
----
$ cd prometheus-exporter
$ ./bin/solr-exporter -p 9854 -z localhost:2181/solr --config-file ./conf/solr-exporter-config.xml -n 16
$ ./bin/solr-exporter -p 9854 -z localhost:2181/solr --config-file ./conf/solr-exporter-config.xml --num-threads 16
----
====
Expand All @@ -80,14 +80,14 @@ Windows::
[source,text]
----
> cd prometheus-exporter
> .\bin\solr-exporter.cmd -p 9854 -b http://localhost:8983/solr --config-file .\conf\solr-exporter-config.xml -n 8
> .\bin\solr-exporter.cmd -p 9854 -b http://localhost:8983/solr --config-file .\conf\solr-exporter-config.xml --num-threads 8
----

.SolrCloud
[source,text]
----
> cd prometheus-exporter
> .\bin\solr-exporter -p 9854 -z localhost:2181/solr --config-file .\conf\solr-exporter-config.xml -n 16
> .\bin\solr-exporter -p 9854 -z localhost:2181/solr --config-file .\conf\solr-exporter-config.xml --num-threads 16
----
====
======
Expand Down Expand Up @@ -148,7 +148,7 @@ If neither the `-b` parameter nor the `-z` parameter are defined, the `-b` param
+
The path to the configuration file that defines the Solr metrics to read.

`-n`, `--num-threads`, `$NUM_THREADS`::
`--num-threads`, `$NUM_THREADS`::
+
[%autowidth,frame=none]
|===
Expand Down Expand Up @@ -285,7 +285,7 @@ $ cd prometheus-exporter
$ export JAVA_OPTS="-Djavax.net.ssl.trustStore=truststore.p12 -Djavax.net.ssl.trustStorePassword=truststorePassword -Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory -Dsolr.httpclient.config=basicauth.properties"
$ export ZK_CREDS_AND_ACLS="-DzkCredentialsProvider=org.apache.solr.common.cloud.VMParamsSingleSetCredentialsDigestZkCredentialsProvider -DzkDigestUsername=readonly-user -DzkDigestPassword=zkUserPassword"
$ export CLASSPATH_PREFIX="../server/solr-webapp/webapp/WEB-INF/lib/commons-codec-1.11.jar"
$ ./bin/solr-exporter -p 9854 -z zk1:2181,zk2:2181,zk3:2181 --config-file ./conf/solr-exporter-config.xml -n 16
$ ./bin/solr-exporter -p 9854 -z zk1:2181,zk2:2181,zk3:2181 --config-file ./conf/solr-exporter-config.xml --num-threads 16
----

NOTE:: The Exporter needs the `commons-codec` library for SSL/BasicAuth, but does not bring it.
Expand Down

0 comments on commit a4cc580

Please sign in to comment.