Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down