Skip to content

Commit 6b2cf02

Browse files
committed
SOLR-17638 Some CLI errors not logged when starting prometheus exporter
1 parent e668dce commit 6b2cf02

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

solr/packaging/test/bats_helper.bash

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ shutdown_all() {
6464

6565
shutdown_exporter(){
6666
EXPORTER_PID=$(ps auxww | grep org.apache.solr.prometheus.exporter.SolrExporter | awk "/-classpath/"' {print $2}' | sort -r)
67-
kill -9 $EXPORTER_PID
67+
if [[ -n $EXPORTER_PID ]]; then
68+
kill -9 $EXPORTER_PID
69+
fi
6870
}
6971

7072
delete_all_collections() {

solr/packaging/test/test_prometheus.bats

+6
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ teardown() {
4848
assert_output --partial 'core="COLL_NAME"'
4949
assert_output --partial 'bats-test'
5050
}
51+
52+
@test "unrecognized option logging" {
53+
run ! solr-exporter --unknown-option unknown-option
54+
55+
assert_output --partial 'Unrecognized option: --unknown-option'
56+
}

solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java

+23-10
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static void main(String[] args) {
148148
.argName("BASE_URL")
149149
.type(String.class)
150150
.desc(
151-
"Specify the Solr base URL when connecting to Solr in standalone mode. If omitted both the -b parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'http://localhost:8983/solr'.")
151+
"Specify the Solr base URL when connecting to Solr in standalone mode. If omitted both the -s parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'http://localhost:8983/solr'.")
152152
.build();
153153
mainOptions.addOption(solrUrlOption);
154154

@@ -241,7 +241,7 @@ public static void main(String[] args) {
241241
.argName("ZK_HOST")
242242
.type(String.class)
243243
.desc(
244-
"Specify the ZooKeeper connection string when connecting to Solr in SolrCloud mode. If omitted both the -b parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'localhost:2181/solr'.")
244+
"Specify the ZooKeeper connection string when connecting to Solr in SolrCloud mode. If omitted both the -s parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'localhost:2181/solr'.")
245245
.build();
246246
mainOptions.addOption(zkHostOption);
247247

@@ -270,13 +270,15 @@ public static void main(String[] args) {
270270
String baseUrl = commandLine.getOptionValue(solrUrlOption);
271271
defaultClusterId = makeShortHash(baseUrl);
272272
scrapeConfiguration = SolrScrapeConfiguration.standalone(baseUrl);
273-
}
274-
275-
if (scrapeConfiguration == null) {
276-
log.error(
277-
"Must provide either --{} or --{}",
273+
} else {
274+
log.info(
275+
"No --{} or --{} provided, defaulting to {}",
278276
solrUrlOption.getLongOpt(),
279-
zkHostOption.getLongOpt());
277+
zkHostOption.getLongOpt(),
278+
DEFAULT_BASE_URL);
279+
String baseUrl = DEFAULT_BASE_URL;
280+
defaultClusterId = makeShortHash(baseUrl);
281+
scrapeConfiguration = SolrScrapeConfiguration.standalone(baseUrl);
280282
}
281283

282284
int port = commandLine.getParsedOptionValue(portOption, DEFAULT_PORT);
@@ -321,9 +323,11 @@ public static void main(String[] args) {
321323
clusterId,
322324
scrapeConfiguration);
323325
} catch (IOException e) {
324-
log.error("Failed to start Solr Prometheus Exporter: ", e);
326+
log.error("Failed to start Solr Prometheus Exporter: {}", e.getMessage());
327+
exit(1);
325328
} catch (ParseException e) {
326-
log.error("Failed to parse command line arguments: ", e);
329+
log.error("Failed to parse command line arguments: {}", e.getMessage());
330+
exit(1);
327331
}
328332
}
329333

@@ -349,4 +353,13 @@ private static MetricsConfiguration loadMetricsConfiguration(String configPath)
349353
private static String getSystemVariable(String name) {
350354
return System.getProperty(name, System.getenv(name));
351355
}
356+
357+
public static void exit(int exitStatus) {
358+
try {
359+
System.exit(exitStatus);
360+
} catch (java.lang.SecurityException secExc) {
361+
if (exitStatus != 0)
362+
throw new RuntimeException("SolrExporter failed to exit with status " + exitStatus);
363+
}
364+
}
352365
}

0 commit comments

Comments
 (0)