Skip to content

Commit

Permalink
Fix empty include in configuration
Browse files Browse the repository at this point in the history
An empty 'include' configuration would produce a beanScrope of '*:*' and
would match every bean from the server without applying any of the
default configuration
  • Loading branch information
hush-hush committed Jan 7, 2021
1 parent 9cd2a64 commit b55d023
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/datadog/jmxfetch/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String toString() {
}

private Boolean hasInclude() {
return getInclude() != null;
return getInclude() != null && !getInclude().isEmptyFilter();
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/datadog/jmxfetch/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ public List<String> getParameterValues(String parameterName) {
public boolean isEmptyBeanName() {
return (filter.get("bean") == null && filter.get("bean_name") == null);
}

public boolean isEmptyFilter() {
return filter.isEmpty();
}
}
37 changes: 36 additions & 1 deletion src/test/java/org/datadog/jmxfetch/TestConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, Object>> configInstances =
((List<Map<String, Object>>) fileConfig.getYamlInstances());

List<Configuration> confs = new ArrayList<Configuration>();
for (Map<String, Object> config : configInstances) {
Object yamlConf = config.get("conf");
for (Map<String, Object> conf :
(List<Map<String, Object>>) (yamlConf)) {
confs.add(new Configuration(conf));
}
}

assertEquals(confs.size(), 1);
List<String> res = Configuration.getGreatestCommonScopes(confs);
assertEquals(res, new ArrayList<String>());
}

/**
* 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()
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/jmx_empty_filters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
init_config:

instances:
- name: jmx_test_default_hostname
conf:
- include:

0 comments on commit b55d023

Please sign in to comment.