Skip to content

Commit 14c0c2d

Browse files
committed
post-review changes
1 parent c0ac43f commit 14c0c2d

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxScraperContainer.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class JmxScraperContainer extends GenericContainer<JmxScraperContainer> {
2525
private final Set<String> targetSystems;
2626
private String serviceUrl;
2727
private int intervalMillis;
28-
private final Set<String> customYaml;
28+
private final Set<String> customYamlFiles;
2929

3030
public JmxScraperContainer(String otlpEndpoint) {
3131
super("openjdk:8u272-jre-slim");
@@ -40,7 +40,7 @@ public JmxScraperContainer(String otlpEndpoint) {
4040

4141
this.endpoint = otlpEndpoint;
4242
this.targetSystems = new HashSet<>();
43-
this.customYaml = new HashSet<>();
43+
this.customYamlFiles = new HashSet<>();
4444
this.intervalMillis = 1000;
4545
}
4646

@@ -67,7 +67,7 @@ public JmxScraperContainer withService(String host, int port) {
6767

6868
@CanIgnoreReturnValue
6969
public JmxScraperContainer withCustomYaml(String yamlPath) {
70-
this.customYaml.add(yamlPath);
70+
this.customYamlFiles.add(yamlPath);
7171
return this;
7272
}
7373

@@ -88,19 +88,11 @@ public void start() {
8888
arguments.add("-Dotel.jmx.service.url=" + serviceUrl);
8989
arguments.add("-Dotel.jmx.interval.milliseconds=" + intervalMillis);
9090

91-
if (!customYaml.isEmpty()) {
92-
int i = 0;
93-
StringBuilder sb = new StringBuilder("-Dotel.jmx.config=");
94-
for (String yaml : customYaml) {
95-
String containerPath = "/custom_" + i + ".yaml";
96-
this.withCopyFileToContainer(MountableFile.forClasspathResource(yaml), containerPath);
97-
if (i > 0) {
98-
sb.append(",");
99-
}
100-
sb.append(containerPath);
101-
i++;
91+
if (!customYamlFiles.isEmpty()) {
92+
for (String yaml : customYamlFiles) {
93+
this.withCopyFileToContainer(MountableFile.forClasspathResource(yaml), yaml);
10294
}
103-
arguments.add(sb.toString());
95+
arguments.add("-Dotel.jmx.config=" + String.join(",", customYamlFiles));
10496
}
10597

10698
arguments.add("-jar");

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/TestAppContainer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public TestAppContainer withUserAuth(String login, String pwd) {
5858
return this;
5959
}
6060

61-
@Override
62-
protected void doStart() {
63-
super.doStart();
64-
}
65-
6661
@Override
6762
public void start() {
6863

jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public class JmxScraper {
3636
*/
3737
@SuppressWarnings({"SystemOut", "SystemExitOutsideMain"})
3838
public static void main(String[] args) {
39+
JmxScraperConfig config = null;
40+
JmxScraper jmxScraper = null;
3941
try {
4042
JmxScraperConfigFactory factory = new JmxScraperConfigFactory();
41-
JmxScraperConfig config = JmxScraper.createConfigFromArgs(Arrays.asList(args), factory);
42-
43-
JmxScraper jmxScraper = new JmxScraper(config);
44-
jmxScraper.start();
43+
config = JmxScraper.createConfigFromArgs(Arrays.asList(args), factory);
44+
jmxScraper = new JmxScraper(config);
4545

4646
} catch (ArgumentsParsingException e) {
4747
System.err.println(
@@ -52,6 +52,13 @@ public static void main(String[] args) {
5252
System.err.println(e.getMessage());
5353
System.exit(1);
5454
}
55+
56+
try {
57+
jmxScraper.start();
58+
} catch (IOException e) {
59+
System.err.println("Unable to connect to " + config.getServiceUrl() + " " + e.getMessage());
60+
System.exit(2);
61+
}
5562
}
5663

5764
/**
@@ -96,11 +103,7 @@ private static void loadPropertiesFromPath(Properties props, String path)
96103
}
97104

98105
JmxScraper(JmxScraperConfig config) throws ConfigurationException {
99-
100106
String serviceUrl = config.getServiceUrl();
101-
if (serviceUrl == null) {
102-
throw new ConfigurationException("missing service URL");
103-
}
104107
int interval = config.getIntervalMilliseconds();
105108
if (interval < 0) {
106109
throw new ConfigurationException("interval must be positive");
@@ -110,15 +113,12 @@ private static void loadPropertiesFromPath(Properties props, String path)
110113
// this.service = JmxMetricInsight.createService(GlobalOpenTelemetry.get(), interval);
111114
}
112115

113-
private void start() {
116+
private void start() throws IOException {
117+
118+
JMXConnector connector = client.connect();
119+
114120
@SuppressWarnings("unused")
115-
MBeanServerConnection connection;
116-
try {
117-
JMXConnector connector = client.connect();
118-
connection = connector.getMBeanServerConnection();
119-
} catch (IOException e) {
120-
throw new IllegalStateException(e);
121-
}
121+
MBeanServerConnection connection = connector.getMBeanServerConnection();
122122

123123
// TODO: depend on instrumentation 2.9.0 snapshot
124124
// MetricConfiguration metricConfig = new MetricConfiguration();

0 commit comments

Comments
 (0)