Skip to content

Commit

Permalink
Merge pull request #48 from DataDog/yann/match-bean-issue
Browse files Browse the repository at this point in the history
Buggy matchBean method fix
  • Loading branch information
yannmh committed Mar 16, 2015
2 parents c66cb3d + 0a59252 commit 0c825a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/datadog/jmxfetch/JMXAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Object convertMetricValue(Object metricValue) {
}

boolean matchBean(Configuration configuration) {
boolean matchBeanAttr = true;
Filter include = configuration.getInclude();

if (!include.isEmptyBeanName() && !include.getBeanNames().contains(beanName)) {
Expand All @@ -217,25 +218,26 @@ boolean matchBean(Configuration configuration) {
if (EXCLUDED_BEAN_PARAMS.contains(bean_attr)) {
continue;
}
matchBeanAttr = false;

if (beanParameters.get(bean_attr) == null) {
continue;
}

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

boolean matchBeanAttr = false;

for (String beanVal : beanValues) {
if (!beanParameters.get(bean_attr).equals(beanVal)) {
continue;
}
return true;
}
// We havent' found a match among our attribute values list
if (!matchBeanAttr) {
return false;
}
return false;
}
return true;
// Returns true if all bean_attr belong to EXCLUDED_BEAN_PARAMS otherwise false
return matchBeanAttr;
}

@SuppressWarnings("unchecked")
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ public void testDomainExclude() throws Exception {
mbs.unregisterMBean(excludeMe);
}

@Test
public void testParameterMatch() throws Exception {
// Do not match beans which do not contain types specified in the conf
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName matchParam = new ObjectName("org.datadog.jmxfetch.test:param=AParameter");
SimpleTestJavaApp testApp = new SimpleTestJavaApp();
mbs.registerMBean(testApp, matchParam);

// Initializing application
AppConfig appConfig = new AppConfig();
App app = initApp("jmx_list_params_include.yaml", appConfig);

// Collecting metrics
app.doIteration();
LinkedList<HashMap<String, Object>> metrics = ((ConsoleReporter) appConfig.getReporter()).getMetrics();

// 13 default metrics from java.lang
assertEquals(13, metrics.size());

mbs.unregisterMBean(matchParam);

}

@Test
public void testListParamsInclude() throws Exception {
// We expose a few metrics through JMX
Expand Down

0 comments on commit 0c825a3

Please sign in to comment.