Skip to content

Commit

Permalink
Merge pull request #81 from DataDog/yann/fix-bean-matching-logic
Browse files Browse the repository at this point in the history
Bean name matching logic: OR→AND
  • Loading branch information
yannmh committed Oct 28, 2015
2 parents 3aa86bd + 8f35494 commit fc8ce63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
20 changes: 3 additions & 17 deletions src/main/java/org/datadog/jmxfetch/JMXAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ private boolean matchBeanRegex(Filter filter, boolean matchIfNoRegex) {
return true;
}
}

return false;
}

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

if (!include.isEmptyBeanName() && !include.getBeanNames().contains(beanStringName)) {
Expand All @@ -233,26 +231,14 @@ private boolean matchBeanName(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);


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

private boolean excludeMatchBeanName(Configuration conf) {
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testParameterMatch() throws Exception {
@Test
public void testListParamsInclude() throws Exception {
// We expose a few metrics through JMX
registerMBean(new SimpleTestJavaApp(), "org.datadog.jmxfetch.test:type=RightType");
registerMBean(new SimpleTestJavaApp(), "org.datadog.jmxfetch.test:foo=bar,type=RightType");

// Initializing application
initApplication("jmx_list_params_include.yaml");
Expand Down Expand Up @@ -276,7 +276,6 @@ public void testApp() throws Exception {
assertMetric("test.boolean", 1.0, commonTags, 5);
assertMetric("test.defaulted", 32.0, commonTags, 5);
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.atomic42", 42.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.atomic4242", 4242.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.object1337", 13.37, commonTags, 5);
Expand All @@ -300,7 +299,6 @@ public void testApp() throws Exception {
assertMetric("test.boolean", 1.0, commonTags, 5);
assertMetric("test.defaulted", 32.0, commonTags, 5);
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.atomic42", 42.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.atomic4242", 4242.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.object1337", 13.37, commonTags, 5);
Expand Down Expand Up @@ -331,7 +329,6 @@ public void testApp() throws Exception {
assertMetric("test.boolean", 1.0, commonTags, 5);
assertMetric("test.defaulted", 32.0, commonTags, 5);
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.atomic42", 42.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.atomic4242", 4242.0, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.object1337", 13.37, commonTags, 5);
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/jmx_list_params_include.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ instances:
env: stage
newTag: test
conf:
- include:
domain: org.datadog.jmxfetch.test
foo: bar
type: WrongType
- include:
domain: org.datadog.jmxfetch.test
type:
Expand Down

0 comments on commit fc8ce63

Please sign in to comment.