From 830a18f9553d2b726b2470b822843455be1fe59c Mon Sep 17 00:00:00 2001 From: Peter Findeisen Date: Thu, 3 Nov 2022 13:57:36 -0700 Subject: [PATCH] Post-review code changes --- .../jmx/JmxMetricInsightInstaller.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java b/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java index 9abea4288e6d..5afb57697e81 100644 --- a/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java +++ b/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java @@ -5,8 +5,8 @@ package io.opentelemetry.instrumentation.javaagent.jmx; -import static java.util.logging.Level.CONFIG; import static java.util.logging.Level.FINE; +import static java.util.logging.Level.INFO; import com.google.auto.service.AutoService; import io.opentelemetry.api.GlobalOpenTelemetry; @@ -31,7 +31,7 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) { if (config.getBoolean("otel.jmx.enabled", true)) { JmxMetricInsight service = JmxMetricInsight.createService(GlobalOpenTelemetry.get(), beanDiscoveryDelay(config)); - MetricConfiguration conf = buildMetricConfiguration(); + MetricConfiguration conf = buildMetricConfiguration(config); service.start(conf); } } @@ -61,26 +61,28 @@ private static void addRulesForPlatform(String platform, MetricConfiguration con RuleParser parserInstance = RuleParser.get(); parserInstance.addMetricDefs(conf, inputStream); } else { - JmxMetricInsight.getLogger().log(CONFIG, "No support found for {0}", platform); + JmxMetricInsight.getLogger().log(INFO, "No support found for {0}", platform); } } catch (Exception e) { JmxMetricInsight.getLogger().warning(e.getMessage()); } } - private static void buildFromDefaultRules(MetricConfiguration conf) { - String targetSystem = System.getProperty("otel.jmx.target.system", "").trim(); - String[] platforms = targetSystem.length() == 0 ? new String[0] : targetSystem.split(","); + private static void buildFromDefaultRules( + MetricConfiguration conf, ConfigProperties configProperties) { + String targetSystem = configProperties.getString("otel.jmx.target.system", ""); + String[] platforms = targetSystem.isEmpty() ? new String[0] : targetSystem.split(","); for (String platform : platforms) { addRulesForPlatform(platform, conf); } } - private static void buildFromUserRules(MetricConfiguration conf) { - String jmxDir = System.getProperty("otel.jmx.config"); + private static void buildFromUserRules( + MetricConfiguration conf, ConfigProperties configProperties) { + String jmxDir = configProperties.getString("otel.jmx.config"); if (jmxDir != null) { - JmxMetricInsight.getLogger().log(CONFIG, "JMX config file name: {0}", jmxDir); + JmxMetricInsight.getLogger().log(FINE, "JMX config file name: {0}", jmxDir); RuleParser parserInstance = RuleParser.get(); try (InputStream inputStream = Files.newInputStream(new File(jmxDir.trim()).toPath())) { parserInstance.addMetricDefs(conf, inputStream); @@ -90,13 +92,13 @@ private static void buildFromUserRules(MetricConfiguration conf) { } } - private static MetricConfiguration buildMetricConfiguration() { - MetricConfiguration conf = new MetricConfiguration(); + private static MetricConfiguration buildMetricConfiguration(ConfigProperties configProperties) { + MetricConfiguration metricConfiguration = new MetricConfiguration(); - buildFromDefaultRules(conf); + buildFromDefaultRules(metricConfiguration, configProperties); - buildFromUserRules(conf); + buildFromUserRules(metricConfiguration, configProperties); - return conf; + return metricConfiguration; } }