Skip to content

Commit fc8ce63

Browse files
committed
Merge pull request #81 from DataDog/yann/fix-bean-matching-logic
Bean name matching logic: OR→AND
2 parents 3aa86bd + 8f35494 commit fc8ce63

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

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

+3-17
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ private boolean matchBeanRegex(Filter filter, boolean matchIfNoRegex) {
217217
return true;
218218
}
219219
}
220-
221220
return false;
222221
}
223222

224223
private boolean matchBeanName(Configuration configuration) {
225-
boolean matchBeanAttr = true;
226224
Filter include = configuration.getInclude();
227225

228226
if (!include.isEmptyBeanName() && !include.getBeanNames().contains(beanStringName)) {
@@ -233,26 +231,14 @@ private boolean matchBeanName(Configuration configuration) {
233231
if (EXCLUDED_BEAN_PARAMS.contains(bean_attr)) {
234232
continue;
235233
}
236-
matchBeanAttr = false;
237-
238-
if (beanParameters.get(bean_attr) == null) {
239-
continue;
240-
}
241234

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

244-
245-
for (String beanVal : beanValues) {
246-
if (!beanParameters.get(bean_attr).equals(beanVal)) {
247-
continue;
237+
if (beanParameters.get(bean_attr) == null || !(beanValues.contains(beanParameters.get(bean_attr)))){
238+
return false;
248239
}
249-
return true;
250-
}
251-
// We havent' found a match among our attribute values list
252-
return false;
253240
}
254-
// Returns true if all bean_attr belong to EXCLUDED_BEAN_PARAMS otherwise false
255-
return matchBeanAttr;
241+
return true;
256242
}
257243

258244
private boolean excludeMatchBeanName(Configuration conf) {

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void testParameterMatch() throws Exception {
126126
@Test
127127
public void testListParamsInclude() throws Exception {
128128
// We expose a few metrics through JMX
129-
registerMBean(new SimpleTestJavaApp(), "org.datadog.jmxfetch.test:type=RightType");
129+
registerMBean(new SimpleTestJavaApp(), "org.datadog.jmxfetch.test:foo=bar,type=RightType");
130130

131131
// Initializing application
132132
initApplication("jmx_list_params_include.yaml");
@@ -276,7 +276,6 @@ public void testApp() throws Exception {
276276
assertMetric("test.boolean", 1.0, commonTags, 5);
277277
assertMetric("test.defaulted", 32.0, commonTags, 5);
278278
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
279-
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
280279
assertMetric("jmx.org.datadog.jmxfetch.test.atomic42", 42.0, commonTags, 5);
281280
assertMetric("jmx.org.datadog.jmxfetch.test.atomic4242", 4242.0, commonTags, 5);
282281
assertMetric("jmx.org.datadog.jmxfetch.test.object1337", 13.37, commonTags, 5);
@@ -300,7 +299,6 @@ public void testApp() throws Exception {
300299
assertMetric("test.boolean", 1.0, commonTags, 5);
301300
assertMetric("test.defaulted", 32.0, commonTags, 5);
302301
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
303-
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
304302
assertMetric("jmx.org.datadog.jmxfetch.test.atomic42", 42.0, commonTags, 5);
305303
assertMetric("jmx.org.datadog.jmxfetch.test.atomic4242", 4242.0, commonTags, 5);
306304
assertMetric("jmx.org.datadog.jmxfetch.test.object1337", 13.37, commonTags, 5);
@@ -331,7 +329,6 @@ public void testApp() throws Exception {
331329
assertMetric("test.boolean", 1.0, commonTags, 5);
332330
assertMetric("test.defaulted", 32.0, commonTags, 5);
333331
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
334-
assertMetric("subattr.this.is.0", 0.0, commonTags, 5);
335332
assertMetric("jmx.org.datadog.jmxfetch.test.atomic42", 42.0, commonTags, 5);
336333
assertMetric("jmx.org.datadog.jmxfetch.test.atomic4242", 4242.0, commonTags, 5);
337334
assertMetric("jmx.org.datadog.jmxfetch.test.object1337", 13.37, commonTags, 5);

src/test/resources/jmx_list_params_include.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ instances:
77
env: stage
88
newTag: test
99
conf:
10+
- include:
11+
domain: org.datadog.jmxfetch.test
12+
foo: bar
13+
type: WrongType
1014
- include:
1115
domain: org.datadog.jmxfetch.test
1216
type:

0 commit comments

Comments
 (0)