Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for remote jmx rules file. #12775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -17,8 +17,7 @@
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.net.URL;
import java.time.Duration;
import java.util.List;

Expand Down Expand Up @@ -78,13 +77,37 @@ private static void buildFromDefaultRules(
}
}

private static void buildFromUserRules(
MetricConfiguration conf, ConfigProperties configProperties) {
static void buildFromUserRules(MetricConfiguration conf, ConfigProperties configProperties) {

List<String> configFiles = configProperties.getList("otel.jmx.config");

// current working directory path
String currentWorkingDirectory = System.getProperty("user.dir");

for (String configFile : configFiles) {
JmxMetricInsight.getLogger().log(FINE, "JMX config file name: {0}", configFile);
String configFileUrlString = configFile;

if (configFile != null) {

// handle relative path case
if (!configFile.startsWith("/") && !configFile.contains("://")) {
configFile = currentWorkingDirectory + "/" + configFile;
}

// handle relative path URL case
if (configFile.startsWith("file://") && !configFile.startsWith("file:///")) {
String configFileRelativePath = configFile.replaceFirst("^file://", "");
configFile = "file://" + currentWorkingDirectory + "/" + configFileRelativePath;
}

// handle absolute path
if (!configFile.contains("://")) {
configFileUrlString = "file://" + configFile;
}
}
JmxMetricInsight.getLogger().log(FINE, "JMX config file name: {0}", configFileUrlString);
RuleParser parserInstance = RuleParser.get();
try (InputStream inputStream = Files.newInputStream(Paths.get(configFile))) {
try (InputStream inputStream = new URL(configFileUrlString).openStream()) {
luigidemasi marked this conversation as resolved.
Show resolved Hide resolved
parserInstance.addMetricDefsTo(conf, inputStream, configFile);
} catch (Exception e) {
// yaml parsing errors are caught and logged inside of addMetricDefsTo
Expand Down