55
66package io .opentelemetry .contrib .jmxscraper .config ;
77
8- import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_CUSTOM_CONFIG ;
8+ import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_CONFIG ;
9+ import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_CONFIG_LEGACY ;
910import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_PASSWORD ;
1011import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_REALM ;
1112import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_REGISTRY_SSL ;
2223import java .util .Properties ;
2324import org .junit .jupiter .api .BeforeAll ;
2425import org .junit .jupiter .api .Test ;
26+ import org .junit .jupiter .params .ParameterizedTest ;
27+ import org .junit .jupiter .params .provider .ValueSource ;
2528
2629class JmxScraperConfigTest {
2730 private static Properties validProperties ;
@@ -31,7 +34,7 @@ static void setUp() {
3134 validProperties = new Properties ();
3235 validProperties .setProperty (
3336 JMX_SERVICE_URL , "jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi" );
34- validProperties .setProperty (JMX_CUSTOM_CONFIG , "/path/to/config.yaml" );
37+ validProperties .setProperty (JMX_CONFIG , "/path/to/config.yaml" );
3538 validProperties .setProperty (JMX_TARGET_SYSTEM , "tomcat, activemq" );
3639 validProperties .setProperty (JMX_REGISTRY_SSL , "true" );
3740 validProperties .setProperty (JMX_USERNAME , "some-user" );
@@ -50,7 +53,7 @@ void shouldPassValidation() {
5053 // Then
5154 assertThat (config .getServiceUrl ())
5255 .isEqualTo ("jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi" );
53- assertThat (config .getCustomJmxScrapingConfigPath ()).isEqualTo ("/path/to/config.yaml" );
56+ assertThat (config .getJmxConfig ()).containsExactly ("/path/to/config.yaml" );
5457 assertThat (config .getTargetSystems ()).containsExactlyInAnyOrder ("tomcat" , "activemq" );
5558 assertThat (config .getSamplingInterval ()).isEqualTo (Duration .ofSeconds (10 ));
5659 assertThat (config .getUsername ()).isEqualTo ("some-user" );
@@ -59,21 +62,33 @@ void shouldPassValidation() {
5962 assertThat (config .getRealm ()).isEqualTo ("some-realm" );
6063 }
6164
62- @ Test
63- void shouldCreateMinimalValidConfiguration () {
65+ @ ParameterizedTest (name = "custom yaml = {arguments}" )
66+ @ ValueSource (booleans = {true , false })
67+ public void shouldCreateMinimalValidConfiguration (boolean customYaml ) {
6468 // Given
6569 Properties properties = new Properties ();
6670 properties .setProperty (JMX_SERVICE_URL , "jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi" );
67- properties .setProperty (JMX_CUSTOM_CONFIG , "/file.properties" );
71+ if (customYaml ) {
72+ properties .setProperty (JMX_CONFIG , "/file.yaml" );
73+ } else {
74+ properties .setProperty (JMX_TARGET_SYSTEM , "tomcat" );
75+ }
6876
6977 // When
7078 JmxScraperConfig config = fromConfig (TestUtil .configProperties (properties ));
7179
7280 // Then
7381 assertThat (config .getServiceUrl ())
7482 .isEqualTo ("jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi" );
75- assertThat (config .getCustomJmxScrapingConfigPath ()).isEqualTo ("/file.properties" );
76- assertThat (config .getTargetSystems ()).isEmpty ();
83+
84+ if (customYaml ) {
85+ assertThat (config .getJmxConfig ()).containsExactly ("/file.yaml" );
86+ assertThat (config .getTargetSystems ()).isEmpty ();
87+ } else {
88+ assertThat (config .getJmxConfig ()).isEmpty ();
89+ assertThat (config .getTargetSystems ()).containsExactly ("tomcat" );
90+ }
91+
7792 assertThat (config .getSamplingInterval ())
7893 .describedAs ("default sampling interval must align to default metric export interval" )
7994 .isEqualTo (Duration .ofMinutes (1 ));
@@ -83,6 +98,21 @@ void shouldCreateMinimalValidConfiguration() {
8398 assertThat (config .getRealm ()).isNull ();
8499 }
85100
101+ @ Test
102+ void legacyCustomScrapingConfig () {
103+ // Given
104+ Properties properties = new Properties ();
105+ properties .setProperty (JMX_SERVICE_URL , "jservice:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi" );
106+ properties .setProperty (JMX_CONFIG_LEGACY , "/file.yaml" );
107+ properties .setProperty (JMX_CONFIG , "/another.yaml" );
108+
109+ // When
110+ JmxScraperConfig config = fromConfig (TestUtil .configProperties (properties ));
111+
112+ // Then
113+ assertThat (config .getJmxConfig ()).containsOnly ("/file.yaml" , "/another.yaml" );
114+ }
115+
86116 @ Test
87117 void shouldFailValidation_missingServiceUrl () {
88118 // Given
@@ -99,14 +129,13 @@ void shouldFailValidation_missingServiceUrl() {
99129 void shouldFailValidation_missingConfigPathAndTargetSystem () {
100130 // Given
101131 Properties properties = (Properties ) validProperties .clone ();
102- properties .remove (JMX_CUSTOM_CONFIG );
132+ properties .remove (JMX_CONFIG );
103133 properties .remove (JMX_TARGET_SYSTEM );
104134
105135 // When and Then
106136 assertThatThrownBy (() -> fromConfig (TestUtil .configProperties (properties )))
107137 .isInstanceOf (ConfigurationException .class )
108- .hasMessage (
109- "at least one of 'otel.jmx.target.system' or 'otel.jmx.custom.scraping.config' must be set" );
138+ .hasMessage ("at least one of 'otel.jmx.target.system' or 'otel.jmx.config' must be set" );
110139 }
111140
112141 @ Test
0 commit comments