From 164679f431fe423259077538ebb75d3bf5aa45ef Mon Sep 17 00:00:00 2001 From: robsunday Date: Wed, 11 Sep 2024 12:34:12 +0200 Subject: [PATCH] Cleanup of config. Refactoring of JmxScraperConfigFactory. Added first unit tests. --- jmx-scraper/build.gradle.kts | 2 + .../jmxscraper/config/JmxScraperConfig.java | 22 +- .../config/JmxScraperConfigFactory.java | 74 ++-- .../config/JmxScraperConfigFactoryTest.java | 325 ++++++++++++++++++ 4 files changed, 364 insertions(+), 59 deletions(-) create mode 100644 jmx-scraper/src/test/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactoryTest.java diff --git a/jmx-scraper/build.gradle.kts b/jmx-scraper/build.gradle.kts index a05539971..87c2129d8 100644 --- a/jmx-scraper/build.gradle.kts +++ b/jmx-scraper/build.gradle.kts @@ -19,6 +19,8 @@ dependencies { implementation("io.opentelemetry:opentelemetry-sdk-testing") implementation("io.opentelemetry.instrumentation:opentelemetry-jmx-metrics") + + testImplementation("org.junit-pioneer:junit-pioneer") } tasks { diff --git a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfig.java b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfig.java index 8da6bad47..eb04e13cd 100644 --- a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfig.java +++ b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfig.java @@ -11,17 +11,13 @@ /** This class keeps application settings */ public class JmxScraperConfig { String serviceUrl = ""; - String customJmxScrapingConfig = ""; - String targetSystem = ""; + String customJmxScrapingConfigPath = ""; Set targetSystems = Collections.emptySet(); int intervalMilliseconds; String metricsExporterType = ""; String otlpExporterEndpoint = ""; - String prometheusExporterHost = ""; - int prometheusExporterPort; - String username = ""; String password = ""; String realm = ""; @@ -34,12 +30,8 @@ public String getServiceUrl() { return serviceUrl; } - public String getCustomJmxScrapingConfig() { - return customJmxScrapingConfig; - } - - public String getTargetSystem() { - return targetSystem; + public String getCustomJmxScrapingConfigPath() { + return customJmxScrapingConfigPath; } public Set getTargetSystems() { @@ -58,14 +50,6 @@ public String getOtlpExporterEndpoint() { return otlpExporterEndpoint; } - public String getPrometheusExporterHost() { - return prometheusExporterHost; - } - - public int getPrometheusExporterPort() { - return prometheusExporterPort; - } - public String getUsername() { return username; } diff --git a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactory.java b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactory.java index 25d7bbe48..c74f7c2f8 100644 --- a/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactory.java +++ b/jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactory.java @@ -13,37 +13,32 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; -import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Properties; +import java.util.stream.Collectors; @SuppressWarnings({"SystemOut", "SystemExitOutsideMain"}) public class JmxScraperConfigFactory { private static final String PREFIX = "otel."; - private static final String SERVICE_URL = PREFIX + "jmx.service.url"; - private static final String CUSTOM_JMX_SCRAPING_CONFIG = - PREFIX + "jmx.custom.jmx.scraping.config"; - private static final String TARGET_SYSTEM = PREFIX + "jmx.target.system"; - private static final String INTERVAL_MILLISECONDS = PREFIX + "jmx.interval.milliseconds"; - private static final String METRICS_EXPORTER_TYPE = PREFIX + "metrics.exporter"; - private static final String EXPORTER = PREFIX + "exporter."; - private static final String REGISTRY_SSL = PREFIX + "jmx.remote.registry.ssl"; - private static final String EXPORTER_INTERVAL = PREFIX + "metric.export.interval"; - - private static final String OTLP_ENDPOINT = EXPORTER + "otlp.endpoint"; - - private static final String PROMETHEUS_HOST = EXPORTER + "prometheus.host"; - private static final String PROMETHEUS_PORT = EXPORTER + "prometheus.port"; - - private static final String JMX_USERNAME = PREFIX + "jmx.username"; - private static final String JMX_PASSWORD = PREFIX + "jmx.password"; - private static final String JMX_REMOTE_PROFILE = PREFIX + "jmx.remote.profile"; - private static final String JMX_REALM = PREFIX + "jmx.realm"; + static final String SERVICE_URL = PREFIX + "jmx.service.url"; + static final String CUSTOM_JMX_SCRAPING_CONFIG = PREFIX + "jmx.custom.jmx.scraping.config"; + static final String TARGET_SYSTEM = PREFIX + "jmx.target.system"; + static final String INTERVAL_MILLISECONDS = PREFIX + "jmx.interval.milliseconds"; + static final String METRICS_EXPORTER_TYPE = PREFIX + "metrics.exporter"; + static final String EXPORTER_INTERVAL = PREFIX + "metric.export.interval"; + static final String REGISTRY_SSL = PREFIX + "jmx.remote.registry.ssl"; + + static final String OTLP_ENDPOINT = PREFIX + "exporter.otlp.endpoint"; + + static final String JMX_USERNAME = PREFIX + "jmx.username"; + static final String JMX_PASSWORD = PREFIX + "jmx.password"; + static final String JMX_REMOTE_PROFILE = PREFIX + "jmx.remote.profile"; + static final String JMX_REALM = PREFIX + "jmx.realm"; // These properties need to be copied into System Properties if provided via the property // file so that they are available to the JMX Connection builder - private static final List JAVA_SYSTEM_PROPERTIES = + static final List JAVA_SYSTEM_PROPERTIES = Arrays.asList( "javax.net.ssl.keyStore", "javax.net.ssl.keyStorePassword", @@ -52,7 +47,7 @@ public class JmxScraperConfigFactory { "javax.net.ssl.trustStorePassword", "javax.net.ssl.trustStoreType"); - private static final List AVAILABLE_TARGET_SYSTEMS = + static final List AVAILABLE_TARGET_SYSTEMS = Arrays.asList( "activemq", "cassandra", @@ -94,6 +89,8 @@ public JmxScraperConfig createConfigFromArgs(List args) { JmxScraperConfig config = createConfig(loadedProperties); validateConfig(config); + populateJmxSystemProperties(); + return config; } @@ -128,26 +125,21 @@ JmxScraperConfig createConfig(Properties props) { JmxScraperConfig config = new JmxScraperConfig(); config.serviceUrl = properties.getProperty(SERVICE_URL); - config.customJmxScrapingConfig = properties.getProperty(CUSTOM_JMX_SCRAPING_CONFIG); - config.targetSystem = + config.customJmxScrapingConfigPath = properties.getProperty(CUSTOM_JMX_SCRAPING_CONFIG); + String targetSystem = properties.getProperty(TARGET_SYSTEM, "").toLowerCase(Locale.ENGLISH).trim(); List targets = - Arrays.asList( - isBlank(config.targetSystem) ? new String[0] : config.targetSystem.split(",")); - config.targetSystems = new LinkedHashSet<>(targets); + Arrays.asList(isBlank(targetSystem) ? new String[0] : targetSystem.split(",")); + config.targetSystems = targets.stream().map(String::trim).collect(Collectors.toSet()); - int interval = getProperty(INTERVAL_MILLISECONDS, 10000); - config.intervalMilliseconds = interval == 0 ? 10000 : interval; - // set for autoconfigure usage - getAndSetProperty(EXPORTER_INTERVAL, config.intervalMilliseconds); + int interval = getProperty(INTERVAL_MILLISECONDS, 0); + config.intervalMilliseconds = (interval == 0 ? 10000 : interval); + getAndSetPropertyIfUndefined(EXPORTER_INTERVAL, config.intervalMilliseconds); - config.metricsExporterType = getAndSetProperty(METRICS_EXPORTER_TYPE, "logging"); + config.metricsExporterType = getAndSetPropertyIfUndefined(METRICS_EXPORTER_TYPE, "logging"); config.otlpExporterEndpoint = properties.getProperty(OTLP_ENDPOINT); - config.prometheusExporterHost = getAndSetProperty(PROMETHEUS_HOST, "0.0.0.0"); - config.prometheusExporterPort = getAndSetProperty(PROMETHEUS_PORT, 9464); - config.username = properties.getProperty(JMX_USERNAME); config.password = properties.getProperty(JMX_PASSWORD); @@ -156,6 +148,10 @@ JmxScraperConfig createConfig(Properties props) { config.registrySsl = Boolean.parseBoolean(properties.getProperty(REGISTRY_SSL)); + return config; + } + + private void populateJmxSystemProperties() { // For the list of System Properties, if they have been set in the properties file // they need to be set in Java System Properties. JAVA_SYSTEM_PROPERTIES.forEach( @@ -170,8 +166,6 @@ JmxScraperConfig createConfig(Properties props) { System.setProperty(key, value); } }); - - return config; } private int getProperty(String key, int defaultValue) { @@ -189,7 +183,7 @@ private int getProperty(String key, int defaultValue) { /** * Similar to getProperty(key, defaultValue) but sets the property to default if not in object. */ - private String getAndSetProperty(String key, String defaultValue) { + private String getAndSetPropertyIfUndefined(String key, String defaultValue) { String propVal = properties.getProperty(key, defaultValue); if (propVal.equals(defaultValue)) { properties.setProperty(key, defaultValue); @@ -197,7 +191,7 @@ private String getAndSetProperty(String key, String defaultValue) { return propVal; } - private int getAndSetProperty(String key, int defaultValue) { + private int getAndSetPropertyIfUndefined(String key, int defaultValue) { int propVal = getProperty(key, defaultValue); if (propVal == defaultValue) { properties.setProperty(key, String.valueOf(defaultValue)); @@ -211,7 +205,7 @@ void validateConfig(JmxScraperConfig config) { throw new ConfigurationException(SERVICE_URL + " must be specified."); } - if (isBlank(config.customJmxScrapingConfig) && isBlank(config.targetSystem)) { + if (isBlank(config.customJmxScrapingConfigPath) && config.targetSystems.isEmpty()) { throw new ConfigurationException( CUSTOM_JMX_SCRAPING_CONFIG + " or " + TARGET_SYSTEM + " must be specified."); } diff --git a/jmx-scraper/src/test/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactoryTest.java b/jmx-scraper/src/test/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactoryTest.java new file mode 100644 index 000000000..bcd6ac574 --- /dev/null +++ b/jmx-scraper/src/test/java/io/opentelemetry/contrib/jmxscraper/config/JmxScraperConfigFactoryTest.java @@ -0,0 +1,325 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.contrib.jmxscraper.config; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Properties; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class JmxScraperConfigFactoryTest { + private static Properties validProperties; + + @BeforeAll + static void setUp() { + validProperties = new Properties(); + validProperties.setProperty( + JmxScraperConfigFactory.SERVICE_URL, + "jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi"); + validProperties.setProperty(JmxScraperConfigFactory.CUSTOM_JMX_SCRAPING_CONFIG, ""); + validProperties.setProperty(JmxScraperConfigFactory.TARGET_SYSTEM, "tomcat, activemq"); + validProperties.setProperty(JmxScraperConfigFactory.METRICS_EXPORTER_TYPE, "otel"); + validProperties.setProperty(JmxScraperConfigFactory.INTERVAL_MILLISECONDS, "1410"); + validProperties.setProperty(JmxScraperConfigFactory.REGISTRY_SSL, "true"); + validProperties.setProperty(JmxScraperConfigFactory.OTLP_ENDPOINT, "http://localhost:4317"); + validProperties.setProperty(JmxScraperConfigFactory.JMX_USERNAME, "some-user"); + validProperties.setProperty(JmxScraperConfigFactory.JMX_PASSWORD, "some-password"); + validProperties.setProperty(JmxScraperConfigFactory.JMX_REMOTE_PROFILE, "some-profile"); + validProperties.setProperty(JmxScraperConfigFactory.JMX_REALM, "some-realm"); + } + + @Test + void verifyDefaultValues() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties emptyProperties = new Properties(); + + // When + JmxScraperConfig config = configFactory.createConfig(emptyProperties); + + // Then + assertThat(config.serviceUrl).isNull(); + assertThat(config.customJmxScrapingConfigPath).isNull(); + assertThat(config.targetSystems).isEmpty(); + assertThat(config.intervalMilliseconds).isEqualTo(10000); + assertThat(config.metricsExporterType).isEqualTo("logging"); + assertThat(config.otlpExporterEndpoint).isNull(); + assertThat(config.username).isNull(); + assertThat(config.password).isNull(); + assertThat(config.remoteProfile).isNull(); + assertThat(config.realm).isNull(); + } + + @Test + void shouldUseValuesFromProperties() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + + // When + JmxScraperConfig config = configFactory.createConfig(validProperties); + + // Then + assertThat(config.serviceUrl).isEqualTo("jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi"); + assertThat(config.customJmxScrapingConfigPath).isEqualTo(""); + assertThat(config.targetSystems).isEqualTo(new HashSet<>(Arrays.asList("tomcat", "activemq"))); + assertThat(config.intervalMilliseconds).isEqualTo(1410); + assertThat(config.metricsExporterType).isEqualTo("otel"); + assertThat(config.otlpExporterEndpoint).isEqualTo("http://localhost:4317"); + assertThat(config.username).isEqualTo("some-user"); + assertThat(config.password).isEqualTo("some-password"); + assertThat(config.remoteProfile).isEqualTo("some-profile"); + assertThat(config.realm).isEqualTo("some-realm"); + assertThat(config.registrySsl).isTrue(); + } + + @Test + void shouldFailValidation_missingServiceUrl() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties properties = (Properties) validProperties.clone(); + properties.remove(JmxScraperConfigFactory.SERVICE_URL); + JmxScraperConfig config = configFactory.createConfig(properties); + + // When and Then + assertThatThrownBy(() -> configFactory.validateConfig(config)) + .isInstanceOf(ConfigurationException.class) + .hasMessage("otel.jmx.service.url must be specified."); + } + + @Test + void shouldFailValidation_missingConfigPathAndTargetSystem() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties properties = (Properties) validProperties.clone(); + properties.remove(JmxScraperConfigFactory.CUSTOM_JMX_SCRAPING_CONFIG); + properties.remove(JmxScraperConfigFactory.TARGET_SYSTEM); + JmxScraperConfig config = configFactory.createConfig(properties); + + // When and Then + assertThatThrownBy(() -> configFactory.validateConfig(config)) + .isInstanceOf(ConfigurationException.class) + .hasMessage( + "otel.jmx.custom.jmx.scraping.config or otel.jmx.target.system must be specified."); + } + + @Test + void shouldFailValidation_invalidTargetSystem() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties properties = (Properties) validProperties.clone(); + properties.setProperty(JmxScraperConfigFactory.TARGET_SYSTEM, "hal9000"); + JmxScraperConfig config = configFactory.createConfig(properties); + + // When and Then + assertThatThrownBy(() -> configFactory.validateConfig(config)) + .isInstanceOf(ConfigurationException.class) + .hasMessage( + "[hal9000] must specify targets from " + + JmxScraperConfigFactory.AVAILABLE_TARGET_SYSTEMS); + } + + @Test + void shouldFailValidation_missingOtlpEndpoint() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties properties = (Properties) validProperties.clone(); + properties.remove(JmxScraperConfigFactory.OTLP_ENDPOINT); + properties.setProperty(JmxScraperConfigFactory.METRICS_EXPORTER_TYPE, "otlp"); + JmxScraperConfig config = configFactory.createConfig(properties); + + // When and Then + assertThatThrownBy(() -> configFactory.validateConfig(config)) + .isInstanceOf(ConfigurationException.class) + .hasMessage("otel.exporter.otlp.endpoint must be specified for otlp format."); + } + + @Test + void shouldFailValidation_negativeInterval() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties properties = (Properties) validProperties.clone(); + properties.setProperty(JmxScraperConfigFactory.INTERVAL_MILLISECONDS, "-1"); + JmxScraperConfig config = configFactory.createConfig(properties); + + // When and Then + assertThatThrownBy(() -> configFactory.validateConfig(config)) + .isInstanceOf(ConfigurationException.class) + .hasMessage("otel.jmx.interval.milliseconds must be positive."); + } + + @Test + void shouldFailConfigCreation_invalidInterval() { + // Given + JmxScraperConfigFactory configFactory = new JmxScraperConfigFactory(); + Properties properties = (Properties) validProperties.clone(); + properties.setProperty(JmxScraperConfigFactory.INTERVAL_MILLISECONDS, "abc"); + + // When and Then + assertThatThrownBy(() -> configFactory.createConfig(properties)) + .isInstanceOf(ConfigurationException.class) + .hasMessage("Failed to parse otel.jmx.interval.milliseconds"); + } + + // @ClearSystemProperty(key = "otel.metric.export.interval") + + // @Test + // @SetSystemProperty(key = "otel.jmx.service.url", value = "myServiceUrl") + // @SetSystemProperty(key = "otel.jmx.groovy.script", value = "myGroovyScript") + // @SetSystemProperty( + // key = "otel.jmx.target.system", + // value = "mytargetsystem,mytargetsystem,myothertargetsystem,myadditionaltargetsystem") + // @SetSystemProperty(key = "otel.jmx.interval.milliseconds", value = "123") + // @SetSystemProperty(key = "otel.metrics.exporter", value = "inmemory") + // @SetSystemProperty(key = "otel.exporter.otlp.endpoint", value = "https://myOtlpEndpoint") + // @SetSystemProperty(key = "otel.exporter.prometheus.host", value = "myPrometheusHost") + // @SetSystemProperty(key = "otel.exporter.prometheus.port", value = "234") + // @SetSystemProperty(key = "otel.jmx.username", value = "myUsername") + // @SetSystemProperty(key = "otel.jmx.password", value = "myPassword") + // @SetSystemProperty(key = "otel.jmx.remote.profile", value = "myRemoteProfile") + // @SetSystemProperty(key = "otel.jmx.realm", value = "myRealm") + // void specifiedValues() { + // JmxConfig config = new JmxConfig(); + // + // assertThat(config.serviceUrl).isEqualTo("myServiceUrl"); + // assertThat(config.groovyScript).isEqualTo("myGroovyScript"); + // assertThat(config.targetSystem) + // + // .isEqualTo("mytargetsystem,mytargetsystem,myothertargetsystem,myadditionaltargetsystem"); + // assertThat(config.targetSystems) + // .containsOnly("mytargetsystem", "myothertargetsystem", "myadditionaltargetsystem"); + // assertThat(config.intervalMilliseconds).isEqualTo(123); + // assertThat(config.metricsExporterType).isEqualTo("inmemory"); + // assertThat(config.otlpExporterEndpoint).isEqualTo("https://myOtlpEndpoint"); + // assertThat(config.prometheusExporterHost).isEqualTo("myPrometheusHost"); + // assertThat(config.prometheusExporterPort).isEqualTo(234); + // assertThat(config.username).isEqualTo("myUsername"); + // assertThat(config.password).isEqualTo("myPassword"); + // assertThat(config.remoteProfile).isEqualTo("myRemoteProfile"); + // assertThat(config.realm).isEqualTo("myRealm"); + // } + // + // @Test + // void propertiesFile() { + // Properties props = new Properties(); + // JmxMetrics.loadPropertiesFromPath( + // props, ClassLoader.getSystemClassLoader().getResource("all.properties").getPath()); + // JmxConfig config = new JmxConfig(props); + // + // + // assertThat(config.serviceUrl).isEqualTo("service:jmx:rmi:///jndi/rmi://myhost:12345/jmxrmi"); + // assertThat(config.groovyScript).isEqualTo("/my/groovy/script"); + // assertThat(config.targetSystem).isEqualTo("jvm,cassandra"); + // assertThat(config.targetSystems).containsOnly("jvm", "cassandra"); + // assertThat(config.intervalMilliseconds).isEqualTo(20000); + // assertThat(config.metricsExporterType).isEqualTo("otlp"); + // assertThat(config.otlpExporterEndpoint).isEqualTo("https://myotlpendpoint"); + // assertThat(config.prometheusExporterHost).isEqualTo("host123.domain.com"); + // assertThat(config.prometheusExporterPort).isEqualTo(67890); + // assertThat(config.username).isEqualTo("myUser\nname"); + // assertThat(config.password).isEqualTo("myPassw\\ord"); + // assertThat(config.remoteProfile).isEqualTo("SASL/DIGEST-MD5"); + // assertThat(config.realm).isEqualTo("myRealm"); + // + // // These properties are set from the config file loading into JmxConfig + // assertThat(System.getProperty("javax.net.ssl.keyStore")).isEqualTo("/my/key/store"); + // assertThat(System.getProperty("javax.net.ssl.keyStorePassword")).isEqualTo("abc123"); + // assertThat(System.getProperty("javax.net.ssl.keyStoreType")).isEqualTo("JKS"); + // assertThat(System.getProperty("javax.net.ssl.trustStore")).isEqualTo("/my/trust/store"); + // assertThat(System.getProperty("javax.net.ssl.trustStorePassword")).isEqualTo("def456"); + // assertThat(System.getProperty("javax.net.ssl.trustStoreType")).isEqualTo("JKS"); + // } + // + // @Test + // @SetSystemProperty(key = "otel.jmx.service.url", value = "myServiceUrl") + // @SetSystemProperty(key = "javax.net.ssl.keyStorePassword", value = "truth") + // void propertiesFileOverride() { + // Properties props = new Properties(); + // JmxMetrics.loadPropertiesFromPath( + // props, ClassLoader.getSystemClassLoader().getResource("all.properties").getPath()); + // JmxConfig config = new JmxConfig(props); + // + // // This property should retain the system property value, not the config file value + // assertThat(config.serviceUrl).isEqualTo("myServiceUrl"); + // // These properties are set from the config file + // assertThat(config.groovyScript).isEqualTo("/my/groovy/script"); + // assertThat(config.targetSystem).isEqualTo("jvm,cassandra"); + // assertThat(config.targetSystems).containsOnly("jvm", "cassandra"); + // assertThat(config.intervalMilliseconds).isEqualTo(20000); + // assertThat(config.metricsExporterType).isEqualTo("otlp"); + // assertThat(config.otlpExporterEndpoint).isEqualTo("https://myotlpendpoint"); + // assertThat(config.prometheusExporterHost).isEqualTo("host123.domain.com"); + // assertThat(config.prometheusExporterPort).isEqualTo(67890); + // assertThat(config.username).isEqualTo("myUser\nname"); + // assertThat(config.password).isEqualTo("myPassw\\ord"); + // assertThat(config.remoteProfile).isEqualTo("SASL/DIGEST-MD5"); + // assertThat(config.realm).isEqualTo("myRealm"); + // + // // This property should retain the system property value, not the config file value + // assertThat(System.getProperty("javax.net.ssl.keyStorePassword")).isEqualTo("truth"); + // // These properties are set from the config file loading into JmxConfig + // assertThat(System.getProperty("javax.net.ssl.keyStore")).isEqualTo("/my/key/store"); + // assertThat(System.getProperty("javax.net.ssl.keyStoreType")).isEqualTo("JKS"); + // assertThat(System.getProperty("javax.net.ssl.trustStore")).isEqualTo("/my/trust/store"); + // assertThat(System.getProperty("javax.net.ssl.trustStorePassword")).isEqualTo("def456"); + // assertThat(System.getProperty("javax.net.ssl.trustStoreType")).isEqualTo("JKS"); + // } + // + // @Test + // @SetSystemProperty(key = "otel.jmx.interval.milliseconds", value = "abc") + // void invalidInterval() { + // assertThatThrownBy(JmxConfig::new) + // .isInstanceOf(ConfigurationException.class) + // .hasMessage("Failed to parse otel.jmx.interval.milliseconds"); + // } + // + // @Test + // @SetSystemProperty(key = "otel.exporter.prometheus.port", value = "abc") + // void invalidPrometheusPort() { + // assertThatThrownBy(JmxConfig::new) + // .isInstanceOf(ConfigurationException.class) + // .hasMessage("Failed to parse otel.exporter.prometheus.port"); + // } + // + // @Test + // @SetSystemProperty(key = "otel.jmx.service.url", value = "myServiceUrl") + // @SetSystemProperty(key = "otel.jmx.groovy.script", value = "myGroovyScript") + // @SetSystemProperty(key = "otel.jmx.target.system", value = "myTargetSystem") + // void canSupportScriptAndTargetSystem() { + // JmxConfig config = new JmxConfig(); + // + // assertThat(config.serviceUrl).isEqualTo("myServiceUrl"); + // assertThat(config.groovyScript).isEqualTo("myGroovyScript"); + // assertThat(config.targetSystem).isEqualTo("mytargetsystem"); + // assertThat(config.targetSystems).containsOnly("mytargetsystem"); + // } + // + // @Test + // @SetSystemProperty(key = "otel.jmx.service.url", value = "requiredValue") + // @SetSystemProperty(key = "otel.jmx.target.system", value = "jvm,unavailableTargetSystem") + // void invalidTargetSystem() { + // JmxConfig config = new JmxConfig(); + // + // assertThatThrownBy(config::validate) + // .isInstanceOf(ConfigurationException.class) + // .hasMessage( + // "[jvm, unavailabletargetsystem] must specify targets from [activemq, cassandra, + // hbase, hadoop, jetty, jvm, " + // + "kafka, kafka-consumer, kafka-producer, solr, tomcat, wildfly]"); + // } + // + // @Test + // @SetSystemProperty(key = "otel.metric.export.interval", value = "123") + // void otelMetricExportIntervalRespected() { + // JmxConfig config = new JmxConfig(); + // assertThat(config.intervalMilliseconds).isEqualTo(10000); + // assertThat(config.properties.getProperty("otel.metric.export.interval")).isEqualTo("123"); + // } + // +}