File tree 2 files changed +30
-5
lines changed
main/java/org/datadog/jmxfetch
test/java/org/datadog/jmxfetch
2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,7 @@ Object convertMetricValue(Object metricValue) {
207
207
}
208
208
209
209
boolean matchBean (Configuration configuration ) {
210
+ boolean matchBeanAttr = true ;
210
211
Filter include = configuration .getInclude ();
211
212
212
213
if (!include .isEmptyBeanName () && !include .getBeanNames ().contains (beanName )) {
@@ -217,25 +218,26 @@ boolean matchBean(Configuration configuration) {
217
218
if (EXCLUDED_BEAN_PARAMS .contains (bean_attr )) {
218
219
continue ;
219
220
}
221
+ matchBeanAttr = false ;
222
+
220
223
if (beanParameters .get (bean_attr ) == null ) {
221
224
continue ;
222
225
}
223
226
224
227
ArrayList <String > beanValues = include .getParameterValues (bean_attr );
225
228
226
- boolean matchBeanAttr = false ;
229
+
227
230
for (String beanVal : beanValues ) {
228
231
if (!beanParameters .get (bean_attr ).equals (beanVal )) {
229
232
continue ;
230
233
}
231
234
return true ;
232
235
}
233
236
// We havent' found a match among our attribute values list
234
- if (!matchBeanAttr ) {
235
- return false ;
236
- }
237
+ return false ;
237
238
}
238
- return true ;
239
+ // Returns true if all bean_attr belong to EXCLUDED_BEAN_PARAMS otherwise false
240
+ return matchBeanAttr ;
239
241
}
240
242
241
243
@ SuppressWarnings ("unchecked" )
Original file line number Diff line number Diff line change @@ -128,6 +128,29 @@ public void testDomainExclude() throws Exception {
128
128
mbs .unregisterMBean (excludeMe );
129
129
}
130
130
131
+ @ Test
132
+ public void testParameterMatch () throws Exception {
133
+ // Do not match beans which do not contain types specified in the conf
134
+ MBeanServer mbs = ManagementFactory .getPlatformMBeanServer ();
135
+ ObjectName matchParam = new ObjectName ("org.datadog.jmxfetch.test:param=AParameter" );
136
+ SimpleTestJavaApp testApp = new SimpleTestJavaApp ();
137
+ mbs .registerMBean (testApp , matchParam );
138
+
139
+ // Initializing application
140
+ AppConfig appConfig = new AppConfig ();
141
+ App app = initApp ("jmx_list_params_include.yaml" , appConfig );
142
+
143
+ // Collecting metrics
144
+ app .doIteration ();
145
+ LinkedList <HashMap <String , Object >> metrics = ((ConsoleReporter ) appConfig .getReporter ()).getMetrics ();
146
+
147
+ // 13 default metrics from java.lang
148
+ assertEquals (13 , metrics .size ());
149
+
150
+ mbs .unregisterMBean (matchParam );
151
+
152
+ }
153
+
131
154
@ Test
132
155
public void testListParamsInclude () throws Exception {
133
156
// We expose a few metrics through JMX
You can’t perform that action at this time.
0 commit comments