Skip to content

Commit 4e18806

Browse files
authored
jmx scraper remove usage of deprecated API (#2526)
1 parent 73f0c5c commit 4e18806

File tree

1 file changed

+10
-26
lines changed
  • jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper

1 file changed

+10
-26
lines changed

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

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import java.io.InputStream;
2828
import java.nio.charset.StandardCharsets;
2929
import java.nio.file.Files;
30-
import java.nio.file.Path;
3130
import java.nio.file.Paths;
32-
import java.nio.file.StandardCopyOption;
3331
import java.util.ArrayList;
3432
import java.util.Arrays;
3533
import java.util.List;
@@ -240,30 +238,16 @@ private static JmxTelemetry createJmxTelemetry(
240238
JmxTelemetryBuilder builder = JmxTelemetry.builder(openTelemetry);
241239
builder.beanDiscoveryDelay(config.getSamplingInterval());
242240

243-
// Unfortunately we can't use the convenient 'addClassPathRules' here as it does not yet
244-
// allow to customize the path of the yaml resources in classpath.
245-
// config.getTargetSystems().forEach(builder::addClassPathRules);
246-
//
247-
// As a temporary workaround we load configuration through temporary files and register them
248-
// as if they were custom rules.
249-
config
250-
.getTargetSystems()
251-
.forEach(
252-
system -> {
253-
try (InputStream input = config.getTargetSystemYaml(system)) {
254-
Path tempFile = Files.createTempFile("jmx-scraper-" + system, ".yaml");
255-
try {
256-
Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING);
257-
builder.addCustomRules(tempFile);
258-
} finally {
259-
Files.delete(tempFile);
260-
}
261-
} catch (IOException e) {
262-
throw new IllegalStateException(e);
263-
}
264-
});
265-
266-
config.getJmxConfig().stream().map(Paths::get).forEach(builder::addCustomRules);
241+
for (String system : config.getTargetSystems()) {
242+
try (InputStream input = config.getTargetSystemYaml(system)) {
243+
builder.addRules(input);
244+
} catch (IOException e) {
245+
// can only be triggered by close(), thus very unlikely to be triggered in practice
246+
throw new IllegalStateException("IO error loading rules for system: " + system, e);
247+
}
248+
}
249+
250+
config.getJmxConfig().stream().map(Paths::get).forEach(path -> builder.addRules(path));
267251
return builder.build();
268252
}
269253

0 commit comments

Comments
 (0)