diff --git a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java index 9537b9471..366fa48ca 100644 --- a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java +++ b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxScraper.java @@ -27,9 +27,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -240,30 +238,16 @@ private static JmxTelemetry createJmxTelemetry( JmxTelemetryBuilder builder = JmxTelemetry.builder(openTelemetry); builder.beanDiscoveryDelay(config.getSamplingInterval()); - // Unfortunately we can't use the convenient 'addClassPathRules' here as it does not yet - // allow to customize the path of the yaml resources in classpath. - // config.getTargetSystems().forEach(builder::addClassPathRules); - // - // As a temporary workaround we load configuration through temporary files and register them - // as if they were custom rules. - config - .getTargetSystems() - .forEach( - system -> { - try (InputStream input = config.getTargetSystemYaml(system)) { - Path tempFile = Files.createTempFile("jmx-scraper-" + system, ".yaml"); - try { - Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING); - builder.addCustomRules(tempFile); - } finally { - Files.delete(tempFile); - } - } catch (IOException e) { - throw new IllegalStateException(e); - } - }); - - config.getJmxConfig().stream().map(Paths::get).forEach(builder::addCustomRules); + for (String system : config.getTargetSystems()) { + try (InputStream input = config.getTargetSystemYaml(system)) { + builder.addRules(input); + } catch (IOException e) { + // can only be triggered by close(), thus very unlikely to be triggered in practice + throw new IllegalStateException("IO error loading rules for system: " + system, e); + } + } + + config.getJmxConfig().stream().map(Paths::get).forEach(path -> builder.addRules(path)); return builder.build(); }