Skip to content

Commit 0c825a3

Browse files
committed
Merge pull request #48 from DataDog/yann/match-bean-issue
Buggy matchBean method fix
2 parents c66cb3d + 0a59252 commit 0c825a3

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/main/java/org/datadog/jmxfetch/JMXAttribute.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Object convertMetricValue(Object metricValue) {
207207
}
208208

209209
boolean matchBean(Configuration configuration) {
210+
boolean matchBeanAttr = true;
210211
Filter include = configuration.getInclude();
211212

212213
if (!include.isEmptyBeanName() && !include.getBeanNames().contains(beanName)) {
@@ -217,25 +218,26 @@ boolean matchBean(Configuration configuration) {
217218
if (EXCLUDED_BEAN_PARAMS.contains(bean_attr)) {
218219
continue;
219220
}
221+
matchBeanAttr = false;
222+
220223
if (beanParameters.get(bean_attr) == null) {
221224
continue;
222225
}
223226

224227
ArrayList<String> beanValues = include.getParameterValues(bean_attr);
225228

226-
boolean matchBeanAttr = false;
229+
227230
for (String beanVal : beanValues) {
228231
if (!beanParameters.get(bean_attr).equals(beanVal)) {
229232
continue;
230233
}
231234
return true;
232235
}
233236
// We havent' found a match among our attribute values list
234-
if (!matchBeanAttr) {
235-
return false;
236-
}
237+
return false;
237238
}
238-
return true;
239+
// Returns true if all bean_attr belong to EXCLUDED_BEAN_PARAMS otherwise false
240+
return matchBeanAttr;
239241
}
240242

241243
@SuppressWarnings("unchecked")

src/test/java/org/datadog/jmxfetch/TestApp.java

+23
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,29 @@ public void testDomainExclude() throws Exception {
128128
mbs.unregisterMBean(excludeMe);
129129
}
130130

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+
131154
@Test
132155
public void testListParamsInclude() throws Exception {
133156
// We expose a few metrics through JMX

0 commit comments

Comments
 (0)