5
5
6
6
package io .opentelemetry .contrib .jmxscraper .config ;
7
7
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 ;
9
10
import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_PASSWORD ;
10
11
import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_REALM ;
11
12
import static io .opentelemetry .contrib .jmxscraper .config .JmxScraperConfig .JMX_REGISTRY_SSL ;
22
23
import java .util .Properties ;
23
24
import org .junit .jupiter .api .BeforeAll ;
24
25
import org .junit .jupiter .api .Test ;
26
+ import org .junit .jupiter .params .ParameterizedTest ;
27
+ import org .junit .jupiter .params .provider .ValueSource ;
25
28
26
29
class JmxScraperConfigTest {
27
30
private static Properties validProperties ;
@@ -31,7 +34,7 @@ static void setUp() {
31
34
validProperties = new Properties ();
32
35
validProperties .setProperty (
33
36
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" );
35
38
validProperties .setProperty (JMX_TARGET_SYSTEM , "tomcat, activemq" );
36
39
validProperties .setProperty (JMX_REGISTRY_SSL , "true" );
37
40
validProperties .setProperty (JMX_USERNAME , "some-user" );
@@ -50,7 +53,7 @@ void shouldPassValidation() {
50
53
// Then
51
54
assertThat (config .getServiceUrl ())
52
55
.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" );
54
57
assertThat (config .getTargetSystems ()).containsExactlyInAnyOrder ("tomcat" , "activemq" );
55
58
assertThat (config .getSamplingInterval ()).isEqualTo (Duration .ofSeconds (10 ));
56
59
assertThat (config .getUsername ()).isEqualTo ("some-user" );
@@ -59,21 +62,33 @@ void shouldPassValidation() {
59
62
assertThat (config .getRealm ()).isEqualTo ("some-realm" );
60
63
}
61
64
62
- @ Test
63
- void shouldCreateMinimalValidConfiguration () {
65
+ @ ParameterizedTest (name = "custom yaml = {arguments}" )
66
+ @ ValueSource (booleans = {true , false })
67
+ public void shouldCreateMinimalValidConfiguration (boolean customYaml ) {
64
68
// Given
65
69
Properties properties = new Properties ();
66
70
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
+ }
68
76
69
77
// When
70
78
JmxScraperConfig config = fromConfig (TestUtil .configProperties (properties ));
71
79
72
80
// Then
73
81
assertThat (config .getServiceUrl ())
74
82
.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
+
77
92
assertThat (config .getSamplingInterval ())
78
93
.describedAs ("default sampling interval must align to default metric export interval" )
79
94
.isEqualTo (Duration .ofMinutes (1 ));
@@ -83,6 +98,21 @@ void shouldCreateMinimalValidConfiguration() {
83
98
assertThat (config .getRealm ()).isNull ();
84
99
}
85
100
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
+
86
116
@ Test
87
117
void shouldFailValidation_missingServiceUrl () {
88
118
// Given
@@ -99,14 +129,13 @@ void shouldFailValidation_missingServiceUrl() {
99
129
void shouldFailValidation_missingConfigPathAndTargetSystem () {
100
130
// Given
101
131
Properties properties = (Properties ) validProperties .clone ();
102
- properties .remove (JMX_CUSTOM_CONFIG );
132
+ properties .remove (JMX_CONFIG );
103
133
properties .remove (JMX_TARGET_SYSTEM );
104
134
105
135
// When and Then
106
136
assertThatThrownBy (() -> fromConfig (TestUtil .configProperties (properties )))
107
137
.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" );
110
139
}
111
140
112
141
@ Test
0 commit comments