diff --git a/src/main/java/org/datadog/jmxfetch/Configuration.java b/src/main/java/org/datadog/jmxfetch/Configuration.java index ebb639abf..0960c98f5 100644 --- a/src/main/java/org/datadog/jmxfetch/Configuration.java +++ b/src/main/java/org/datadog/jmxfetch/Configuration.java @@ -43,7 +43,7 @@ public String toString() { } private Boolean hasInclude() { - return getInclude() != null; + return getInclude() != null && !getInclude().isEmptyFilter(); } /** diff --git a/src/main/java/org/datadog/jmxfetch/Filter.java b/src/main/java/org/datadog/jmxfetch/Filter.java index 096084734..eb886ed94 100644 --- a/src/main/java/org/datadog/jmxfetch/Filter.java +++ b/src/main/java/org/datadog/jmxfetch/Filter.java @@ -188,4 +188,8 @@ public List getParameterValues(String parameterName) { public boolean isEmptyBeanName() { return (filter.get("bean") == null && filter.get("bean_name") == null); } + + public boolean isEmptyFilter() { + return filter.isEmpty(); + } } diff --git a/src/test/java/org/datadog/jmxfetch/TestConfiguration.java b/src/test/java/org/datadog/jmxfetch/TestConfiguration.java index 12a9efcdf..c0c567fad 100644 --- a/src/test/java/org/datadog/jmxfetch/TestConfiguration.java +++ b/src/test/java/org/datadog/jmxfetch/TestConfiguration.java @@ -84,14 +84,49 @@ public void testAutoDiscoveryConfigs() } /** - * Extract filters from the configuration list and index by domain name + * Check that an empty include doesn't return a '*:*' filters * + * @throws FileNotFoundException * @throws SecurityException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalArgumentException * @throws IllegalAccessException */ + @Test + public void testEmptyInclude() + throws FileNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + File f = new File("src/test/resources/", "jmx_empty_filters.yaml"); + String yamlPath = f.getAbsolutePath(); + FileInputStream yamlInputStream = new FileInputStream(yamlPath); + YamlParser fileConfig = new YamlParser(yamlInputStream); + List> configInstances = + ((List>) fileConfig.getYamlInstances()); + + List confs = new ArrayList(); + for (Map config : configInstances) { + Object yamlConf = config.get("conf"); + for (Map conf : + (List>) (yamlConf)) { + confs.add(new Configuration(conf)); + } + } + + assertEquals(confs.size(), 1); + List res = Configuration.getGreatestCommonScopes(confs); + assertEquals(res, new ArrayList()); + } + + /** + * Extract filters from the configuration list and index by domain name + * + * @throws SecurityException + * @throws NoSuchMethodException + * @throws InvocationTargetExceptionConfiguration + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ @SuppressWarnings("unchecked") @Test public void testFiltersByDomain() diff --git a/src/test/resources/jmx_empty_filters.yaml b/src/test/resources/jmx_empty_filters.yaml new file mode 100644 index 000000000..bb61b7a59 --- /dev/null +++ b/src/test/resources/jmx_empty_filters.yaml @@ -0,0 +1,6 @@ +init_config: + +instances: + - name: jmx_test_default_hostname + conf: + - include: