Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bean name matching logic: OR→AND #81

Merged
merged 1 commit into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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