|
27 | 27 | import java.io.InputStream; |
28 | 28 | import java.nio.charset.StandardCharsets; |
29 | 29 | import java.nio.file.Files; |
30 | | -import java.nio.file.Path; |
31 | 30 | import java.nio.file.Paths; |
32 | | -import java.nio.file.StandardCopyOption; |
33 | 31 | import java.util.ArrayList; |
34 | 32 | import java.util.Arrays; |
35 | 33 | import java.util.List; |
@@ -240,30 +238,16 @@ private static JmxTelemetry createJmxTelemetry( |
240 | 238 | JmxTelemetryBuilder builder = JmxTelemetry.builder(openTelemetry); |
241 | 239 | builder.beanDiscoveryDelay(config.getSamplingInterval()); |
242 | 240 |
|
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)); |
267 | 251 | return builder.build(); |
268 | 252 | } |
269 | 253 |
|
|
0 commit comments