diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java index a11a67a9b..fd0a60cab 100644 --- a/src/main/java/org/datadog/jmxfetch/App.java +++ b/src/main/java/org/datadog/jmxfetch/App.java @@ -35,7 +35,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Map; @@ -77,7 +76,7 @@ public class App { private ConcurrentHashMap configs; private ConcurrentHashMap adPipeConfigs = new ConcurrentHashMap(); - private ArrayList instances = new ArrayList(); + private List instances = new ArrayList(); private Map brokenInstanceMap = new ConcurrentHashMap(); private AtomicBoolean reinit = new AtomicBoolean(false); @@ -255,12 +254,9 @@ public static int getLoopCounter() { } private void clearInstances(Collection instances) { - List> cleanupInstanceTasks = new ArrayList>(); - - Iterator iterator = instances.iterator(); - while (iterator.hasNext()) { - Instance instance = iterator.next(); - + List> cleanupInstanceTasks = + new ArrayList>(instances.size()); + for (Instance instance : instances) { // create the cleanup task cleanupInstanceTasks.add(new InstanceCleanupTask(instance)); } @@ -375,7 +371,7 @@ public boolean processAutoDiscovery(byte[] buffer) { return reinit; } - protected ArrayList getInstances() { + protected List getInstances() { return this.instances; } @@ -494,8 +490,8 @@ public void doIteration() { loopCounter++; try { - List>>> getMetricsTasks = - new ArrayList>>>(); + List>>> getMetricsTasks = + new ArrayList>>>(instances.size()); for (Instance instance : instances) { getMetricsTasks.add(new MetricCollectionTask(instance)); @@ -515,11 +511,11 @@ public void doIteration() { getMetricsTasks, appConfig.getCollectionTimeout(), TimeUnit.SECONDS, - new TaskMethod>>() { + new TaskMethod>>() { @Override public TaskStatusHandler invoke( Instance instance, - Future>> future, + Future>> future, Reporter reporter) { return App.processCollectionResults(instance, future, reporter); } @@ -560,7 +556,8 @@ public TaskStatusHandler invoke( } private void fixBrokenInstances(Reporter reporter) { - List> fixInstanceTasks = new ArrayList>(); + List> fixInstanceTasks = + new ArrayList>(brokenInstanceMap.values().size()); for (Instance instance : brokenInstanceMap.values()) { // Clearing rates aggregator so we won't compute wrong rates if we can reconnect @@ -835,7 +832,6 @@ public void init(boolean forceNewConnection) { clearInstances(brokenInstanceMap.values()); brokenInstanceMap.clear(); - List> instanceInitTasks = new ArrayList>(); List newInstances = new ArrayList(); log.info("Dealing with YAML config instances..."); @@ -858,8 +854,8 @@ public void init(boolean forceNewConnection) { it.remove(); } - ArrayList> configInstances = - ((ArrayList>) yamlConfig.getYamlInstances()); + List> configInstances = + ((List>) yamlConfig.getYamlInstances()); if (configInstances == null || configInstances.size() == 0) { String warning = "No instance found in :" + name; log.warn(warning); @@ -896,8 +892,8 @@ public void init(boolean forceNewConnection) { (HashMap) adJsonConfigs.get(check); Map initConfig = (Map) checkConfig.get("init_config"); - ArrayList> configInstances = - (ArrayList>) checkConfig.get("instances"); + List> configInstances = + (List>) checkConfig.get("instances"); String checkName = (String) checkConfig.get("check_name"); for (Map configInstance : configInstances) { log.info("Instantiating instance for: " + checkName); @@ -908,6 +904,8 @@ public void init(boolean forceNewConnection) { } } + List> instanceInitTasks = + new ArrayList>(newInstances.size()); for (Instance instance : newInstances) { // create the initializing tasks instanceInitTasks.add(new InstanceInitializingTask(instance, forceNewConnection)); @@ -978,7 +976,7 @@ static TaskStatusHandler processRecoveryResults( static TaskStatusHandler processCollectionResults( Instance instance, - Future>> future, + Future>> future, Reporter reporter) { TaskStatusHandler status = new TaskStatusHandler(); @@ -988,7 +986,7 @@ static TaskStatusHandler processCollectionResults( int numberOfMetrics = 0; if (future.isDone()) { - LinkedList> metrics; + List> metrics; metrics = future.get(); numberOfMetrics = metrics.size(); @@ -1125,7 +1123,7 @@ private void processCollectionStatus( String instanceMessage = null; String instanceStatus = Status.STATUS_OK; String scStatus = Status.STATUS_OK; - LinkedList> metrics; + List> metrics; int numberOfMetrics = 0; @@ -1138,7 +1136,7 @@ private void processCollectionStatus( status.raiseForStatus(); // If we get here all was good - metric count available - metrics = (LinkedList>) status.getData(); + metrics = (List>) status.getData(); numberOfMetrics = metrics.size(); if (instance.isLimitReached()) { diff --git a/src/main/java/org/datadog/jmxfetch/Configuration.java b/src/main/java/org/datadog/jmxfetch/Configuration.java index 5541af522..ee5da7cd4 100644 --- a/src/main/java/org/datadog/jmxfetch/Configuration.java +++ b/src/main/java/org/datadog/jmxfetch/Configuration.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -52,10 +52,9 @@ private Boolean hasInclude() { * @param configurationList the configuration list to filter * @return a configuration list */ - private static LinkedList getIncludeConfigurationList( - LinkedList configurationList) { - LinkedList includeConfigList = - new LinkedList(configurationList); + private static List getIncludeConfigurationList( + List configurationList) { + List includeConfigList = new ArrayList(configurationList); Iterator confItr = includeConfigList.iterator(); while (confItr.hasNext()) { @@ -73,18 +72,18 @@ private static LinkedList getIncludeConfigurationList( * @param configurationList the configuration list to process * @return filters by domain name */ - private static HashMap> getIncludeFiltersByDomain( - LinkedList configurationList) { - HashMap> includeFiltersByDomain = - new HashMap>(); + private static HashMap> getIncludeFiltersByDomain( + List configurationList) { + HashMap> includeFiltersByDomain = + new HashMap>(); for (Configuration conf : configurationList) { Filter filter = conf.getInclude(); - LinkedList filters = new LinkedList(); + List filters = new ArrayList(); // Convert bean name, to a proper filter, i.e. a hash if (!filter.isEmptyBeanName()) { - ArrayList beanNames = filter.getBeanNames(); + List beanNames = filter.getBeanNames(); for (String beanName : beanNames) { String[] splitBeanName = beanName.split(":"); @@ -101,13 +100,13 @@ private static HashMap> getIncludeFiltersByDomain( for (Filter f : filters) { // Retrieve the existing filters for the domain, add the new filters - LinkedList domainFilters; + List domainFilters; String domainName = f.getDomain(); if (includeFiltersByDomain.containsKey(domainName)) { domainFilters = includeFiltersByDomain.get(domainName); } else { - domainFilters = new LinkedList(); + domainFilters = new ArrayList(); } domainFilters.add(f); @@ -124,16 +123,17 @@ private static HashMap> getIncludeFiltersByDomain( * @return common bean key parameters by domain name */ private static Map> getCommonBeanKeysByDomain( - Map> filtersByDomain) { + Map> filtersByDomain) { Map> beanKeysIntersectionByDomain = new HashMap>(); - for (Entry> filtersEntry : filtersByDomain.entrySet()) { - String domainName = filtersEntry.getKey(); - LinkedList filters = filtersEntry.getValue(); - + for (Entry> filtersEntry : filtersByDomain.entrySet()) { + List filters = filtersEntry.getValue(); + if (filters == null || filters.isEmpty()) { + continue; + } // Compute keys intersection - Set keysIntersection = new HashSet(filters.getFirst().keySet()); + Set keysIntersection = new HashSet(filters.get(0).keySet()); for (Filter filter : filters) { keysIntersection.retainAll(filter.keySet()); @@ -143,7 +143,7 @@ private static Map> getCommonBeanKeysByDomain( for (String param : JmxAttribute.getExcludedBeanParams()) { keysIntersection.remove(param); } - + String domainName = filtersEntry.getKey(); beanKeysIntersectionByDomain.put(domainName, keysIntersection); } @@ -160,7 +160,7 @@ private static Map> getCommonBeanKeysByDomain( */ private static Map> getCommonScopeByDomain( Map> beanKeysByDomain, - Map> filtersByDomain) { + Map> filtersByDomain) { // Compute a common scope a among filters by domain name Map> commonScopeByDomain = new HashMap>(); @@ -169,16 +169,16 @@ private static Map> getCommonScopeByDomain( beanKeysByDomain.entrySet()) { String domainName = commonParametersByDomainEntry.getKey(); Set commonParameters = commonParametersByDomainEntry.getValue(); - LinkedList filters = filtersByDomain.get(domainName); + List filters = filtersByDomain.get(domainName); Map commonScope = new HashMap(); for (String parameter : commonParameters) { // Check if all values associated with the parameters are the same String commonValue = null; - Boolean hasCommonValue = true; + boolean hasCommonValue = true; for (Filter f : filters) { - ArrayList parameterValues = f.getParameterValues(parameter); + List parameterValues = f.getParameterValues(parameter); if (parameterValues.size() != 1 || (commonValue != null @@ -231,18 +231,18 @@ private static String beanScopeToString( * @param configurationList the configuration list to process * @return common bean pattern strings */ - public static LinkedList getGreatestCommonScopes( - LinkedList configurationList) { - LinkedList includeConfigList = + public static List getGreatestCommonScopes( + List configurationList) { + List includeConfigList = getIncludeConfigurationList(configurationList); - Map> includeFiltersByDomain = + Map> includeFiltersByDomain = getIncludeFiltersByDomain(includeConfigList); Map> parametersIntersectionByDomain = getCommonBeanKeysByDomain(includeFiltersByDomain); Map> commonBeanScopeByDomain = getCommonScopeByDomain(parametersIntersectionByDomain, includeFiltersByDomain); - LinkedList result = new LinkedList(); + List result = new ArrayList(commonBeanScopeByDomain.entrySet().size()); for (Entry> beanScopeEntry : commonBeanScopeByDomain.entrySet()) { diff --git a/src/main/java/org/datadog/jmxfetch/Filter.java b/src/main/java/org/datadog/jmxfetch/Filter.java index 40ffed831..cc214d47c 100644 --- a/src/main/java/org/datadog/jmxfetch/Filter.java +++ b/src/main/java/org/datadog/jmxfetch/Filter.java @@ -1,15 +1,18 @@ package org.datadog.jmxfetch; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Set; import java.util.regex.Pattern; class Filter { HashMap filter; Pattern domainRegex; - ArrayList beanRegexes = null; - ArrayList excludeTags = null; + List beanRegexes = null; + List excludeTags = null; HashMap additionalTags = null; /** @@ -37,8 +40,8 @@ public Set keySet() { return filter.keySet(); } - @SuppressWarnings({"unchecked", "serial"}) - private static ArrayList toStringArrayList(final Object toCast) { + @SuppressWarnings({"unchecked"}) + private static List toStringList(final Object toCast) { // Return object as an ArrayList wherever it's defined as // list or not // @@ -49,20 +52,15 @@ private static ArrayList toStringArrayList(final Object toCast) { // ### OR // object: singleValue // ### - try { - return (ArrayList) toCast; - } catch (ClassCastException e) { - return new ArrayList() { - { - add(((String) toCast)); - } - }; + if (toCast instanceof List) { + return (List) toCast; } + return new ArrayList(Arrays.asList((String) toCast)); } - public ArrayList getBeanNames() { + public List getBeanNames() { if (isEmptyBeanName()) { - return new ArrayList(); + return Collections.emptyList(); } final Object beanNames = (filter.get("bean") != null) ? filter.get("bean") : filter.get("bean_name"); @@ -77,44 +75,43 @@ public ArrayList getBeanNames() { // ### OR // bean: org.datadog.jmxfetch.test:type=type=SimpleTestJavaApp // ### - return toStringArrayList(beanNames); + return toStringList(beanNames); } - private static ArrayList toPatternArrayList(final Object toCast) { - ArrayList patternArrayList = new ArrayList(); - ArrayList stringArrayList = toStringArrayList(toCast); - for (String string : stringArrayList) { - patternArrayList.add(Pattern.compile(string)); + private static List toPatternList(final Object toCast) { + List patternList = new ArrayList(); + List stringList = toStringList(toCast); + for (String string : stringList) { + patternList.add(Pattern.compile(string)); } - - return patternArrayList; + return patternList; } - public ArrayList getBeanRegexes() { + public List getBeanRegexes() { // Return bean regexes as an ArrayList of Pattern whether it's defined as // a list or not if (this.beanRegexes == null) { if (filter.get("bean_regex") == null) { - this.beanRegexes = new ArrayList(); + this.beanRegexes = Collections.emptyList(); } else { final Object beanRegexNames = filter.get("bean_regex"); - this.beanRegexes = toPatternArrayList(beanRegexNames); + this.beanRegexes = toPatternList(beanRegexNames); } } return this.beanRegexes; } - public ArrayList getExcludeTags() { + public List getExcludeTags() { // Return excluded tags as an ArrayList whether it's defined as a list or not if (this.excludeTags == null) { if (filter.get("exclude_tags") == null) { - this.excludeTags = new ArrayList(); + this.excludeTags = Collections.emptyList(); } else { final Object exclude_tags = filter.get("exclude_tags"); - this.excludeTags = toStringArrayList(exclude_tags); + this.excludeTags = toStringList(exclude_tags); } } @@ -154,7 +151,7 @@ public Object getAttribute() { return filter.get("attribute"); } - public ArrayList getParameterValues(String parameterName) { + public List getParameterValues(String parameterName) { // Return bean attributes values as an ArrayList wherever it's defined as // list or not // @@ -166,7 +163,7 @@ public ArrayList getParameterValues(String parameterName) { // bean_parameter: onlyOneType // ### final Object beanValues = filter.get(parameterName); - return toStringArrayList(beanValues); + return toStringList(beanValues); } public boolean isEmptyBeanName() { diff --git a/src/main/java/org/datadog/jmxfetch/Instance.java b/src/main/java/org/datadog/jmxfetch/Instance.java index ac5f8cebb..ec8069b00 100644 --- a/src/main/java/org/datadog/jmxfetch/Instance.java +++ b/src/main/java/org/datadog/jmxfetch/Instance.java @@ -16,7 +16,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -77,9 +76,9 @@ public Yaml initialValue() { }; private Set beans; - private LinkedList beanScopes; - private LinkedList configurationList = new LinkedList(); - private LinkedList matchingAttributes; + private List beanScopes; + private List configurationList = new ArrayList(); + private List matchingAttributes; private HashSet failingAttributes; private Integer refreshBeansPeriod; private long lastCollectionTime; @@ -124,7 +123,7 @@ public Instance( this.instanceName = (String) instanceMap.get("name"); this.tags = getTagsMap(instanceMap.get("tags"), appConfig); this.checkName = checkName; - this.matchingAttributes = new LinkedList(); + this.matchingAttributes = new ArrayList(); this.failingAttributes = new HashSet(); if (appConfig.getRefreshBeansPeriod() == null) { this.refreshBeansPeriod = (Integer) instanceMap.get("refresh_beans"); @@ -196,7 +195,7 @@ public Instance( log.warn("Cannot find a \"conf\" section in " + this.instanceName); } else { for (Map conf : - (ArrayList>) (instanceConf)) { + (List>) (instanceConf)) { configurationList.add(new Configuration(conf)); } } @@ -223,8 +222,8 @@ public static boolean isDirectInstance(Map configInstance) { } private void loadDefaultConfig(String configResourcePath) { - ArrayList> defaultConf = - (ArrayList>) + List> defaultConf = + (List>) YAML.get().load(this.getClass().getResourceAsStream(configResourcePath)); for (Map conf : defaultConf) { configurationList.add(new Configuration(conf)); @@ -233,7 +232,7 @@ private void loadDefaultConfig(String configResourcePath) { @VisibleForTesting static void loadMetricConfigFiles( - AppConfig appConfig, LinkedList configurationList) { + AppConfig appConfig, List configurationList) { List metricConfigFiles = appConfig.getMetricConfigFiles(); if (metricConfigFiles != null && !metricConfigFiles.isEmpty()) { log.warn("Loading files via metricConfigFiles setting is deprecated. Please " @@ -244,8 +243,8 @@ static void loadMetricConfigFiles( log.info("Reading metric config file " + yamlPath); try { yamlInputStream = new FileInputStream(yamlPath); - ArrayList> confs = - (ArrayList>) + List> confs = + (List>) YAML.get().load(yamlInputStream); for (Map conf : confs) { configurationList.add(new Configuration(conf)); @@ -269,7 +268,7 @@ static void loadMetricConfigFiles( @VisibleForTesting static void loadMetricConfigResources( - AppConfig config, LinkedList configurationList) { + AppConfig config, List configurationList) { List resourceConfigList = config.getMetricConfigResources(); if (resourceConfigList != null) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); @@ -280,10 +279,10 @@ static void loadMetricConfigResources( log.warn("Cannot find metric config resource" + resourceName); } else { try { - Map>> topYaml = - (Map>>) + Map>> topYaml = + (Map>>) YAML.get().load(inputStream); - ArrayList> jmxConf = + List> jmxConf = topYaml.get("jmx_metrics"); if (jmxConf != null) { for (Map conf : jmxConf) { @@ -395,7 +394,7 @@ public String toString() { } /** Returns a map of metrics collected. */ - public LinkedList> getMetrics() throws IOException { + public List> getMetrics() throws IOException { // We can force to refresh the bean list every x seconds in case of ephemeral beans // To enable this, a "refresh_beans" parameter must be specified in the yaml/json config @@ -407,7 +406,7 @@ public LinkedList> getMetrics() throws IOException { this.getMatchingAttributes(); } - LinkedList> metrics = new LinkedList>(); + List> metrics = new ArrayList>(); Iterator it = matchingAttributes.iterator(); // increment the lastCollectionTime @@ -416,7 +415,7 @@ public LinkedList> getMetrics() throws IOException { while (it.hasNext()) { JmxAttribute jmxAttr = it.next(); try { - LinkedList> jmxAttrMetrics = jmxAttr.getMetrics(); + List> jmxAttrMetrics = jmxAttr.getMetrics(); for (HashMap m : jmxAttrMetrics) { m.put("check_name", this.checkName); metrics.add(m); @@ -614,7 +613,7 @@ private void getMatchingAttributes() throws IOException { } /** Returns a list of strings listing the bean scopes. */ - public LinkedList getBeansScopes() { + public List getBeansScopes() { if (this.beanScopes == null) { this.beanScopes = Configuration.getGreatestCommonScopes(configurationList); } @@ -628,13 +627,13 @@ public LinkedList getBeansScopes() { private void refreshBeansList() throws IOException { this.beans = new HashSet(); String action = appConfig.getAction(); - Boolean limitQueryScopes = + boolean limitQueryScopes = !action.equals(AppConfig.ACTION_LIST_EVERYTHING) && !action.equals(AppConfig.ACTION_LIST_NOT_MATCHING); if (limitQueryScopes) { try { - LinkedList beanScopes = getBeansScopes(); + List beanScopes = getBeansScopes(); for (String scope : beanScopes) { ObjectName name = new ObjectName(scope); this.beans.addAll(connection.queryNames(name)); diff --git a/src/main/java/org/datadog/jmxfetch/JmxAttribute.java b/src/main/java/org/datadog/jmxfetch/JmxAttribute.java index 86f62f30a..04e267585 100644 --- a/src/main/java/org/datadog/jmxfetch/JmxAttribute.java +++ b/src/main/java/org/datadog/jmxfetch/JmxAttribute.java @@ -8,7 +8,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -55,7 +54,7 @@ public abstract class JmxAttribute { new HashMap>(); protected String[] tags; private Configuration matchingConf; - private LinkedList defaultTagsList; + private List defaultTagsList; private Boolean cassandraAliasing; JmxAttribute( @@ -85,7 +84,7 @@ public abstract class JmxAttribute { this.domain = domain; HashMap beanParametersHash = getBeanParametersHash(beanParameters); - LinkedList beanParametersList = + List beanParametersList = getBeanParametersList(instanceName, beanParametersHash, instanceTags); this.beanParameters = beanParametersHash; @@ -116,7 +115,7 @@ private void addAdditionalTags() { if (include != null) { for (Map.Entry tag : include.getAdditionalTags().entrySet()) { String alias = this.replaceByAlias(tag.getValue()); - if ((alias.trim().length() > 0) && alias != null) { + if (alias != null && alias.trim().length() > 0) { this.defaultTagsList.add(tag.getKey() + ":" + alias); } else { log.warn("Unable to apply tag " + tag.getKey() + " - with unknown alias"); @@ -141,11 +140,11 @@ public static HashMap getBeanParametersHash(String beanParameter return beanParamsMap; } - private LinkedList getBeanParametersList( + private List getBeanParametersList( String instanceName, Map beanParameters, Map instanceTags) { - LinkedList beanTags = new LinkedList(); + List beanTags = new ArrayList(); beanTags.add("instance:" + instanceName); beanTags.add("jmx_domain:" + domain); @@ -174,8 +173,8 @@ private LinkedList getBeanParametersList( * Sanitize MBean parameter names and values, i.e. - Rename parameter names conflicting with * existing tags - Remove illegal characters */ - private static LinkedList sanitizeParameters(LinkedList beanParametersList) { - LinkedList defaultTagsList = new LinkedList(); + private static List sanitizeParameters(List beanParametersList) { + List defaultTagsList = new ArrayList(beanParametersList.size()); for (String rawBeanParameter : beanParametersList) { // Remove `|` characters String beanParameter = rawBeanParameter.replace("|", ""); @@ -199,7 +198,7 @@ protected Boolean renameCassandraMetrics() { } private static Collection getCassandraBeanTags(Map beanParameters) { - Collection tags = new LinkedList(); + Collection tags = new ArrayList(); for (Map.Entry param : beanParameters.entrySet()) { if (param.getKey().equals("name")) { // This is already in the alias @@ -233,7 +232,7 @@ public String toString() { + attribute.getType(); } - public abstract LinkedList> getMetrics() + public abstract List> getMetrics() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException; @@ -325,7 +324,7 @@ Object convertMetricValue(Object metricValue, String field) { } private boolean matchBeanRegex(Filter filter, boolean matchIfNoRegex) { - ArrayList beanRegexes = filter.getBeanRegexes(); + List beanRegexes = filter.getBeanRegexes(); if (beanRegexes.isEmpty()) { return matchIfNoRegex; } @@ -355,7 +354,7 @@ private boolean matchBeanName(Configuration configuration) { continue; } - ArrayList beanValues = include.getParameterValues(beanAttr); + List beanValues = include.getParameterValues(beanAttr); if (beanParameters.get(beanAttr) == null || !(beanValues.contains(beanParameters.get(beanAttr)))) { @@ -367,7 +366,7 @@ private boolean matchBeanName(Configuration configuration) { private boolean excludeMatchBeanName(Configuration conf) { Filter exclude = conf.getExclude(); - ArrayList beanNames = exclude.getBeanNames(); + List beanNames = exclude.getBeanNames(); if (beanNames.contains(beanStringName)) { return true; @@ -382,7 +381,7 @@ private boolean excludeMatchBeanName(Configuration conf) { continue; } - ArrayList beanValues = exclude.getParameterValues(beanAttr); + List beanValues = exclude.getParameterValues(beanAttr); for (String beanVal : beanValues) { if (beanParameters.get(beanAttr).equals(beanVal)) { return true; @@ -576,12 +575,12 @@ protected String[] getTags() { if (include != null) { Object includeAttribute = include.getAttribute(); if (includeAttribute instanceof Map) { - Map> attributeParams = - ((Map>>) + Map> attributeParams = + ((Map>>) includeAttribute) .get(attributeName); if (attributeParams != null) { - ArrayList yamlTags = attributeParams.get("tags"); + List yamlTags = attributeParams.get("tags"); if (yamlTags != null) { defaultTagsList.addAll(yamlTags); } diff --git a/src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java b/src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java index a0d0fce89..a01ea6940 100644 --- a/src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java +++ b/src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; @@ -55,11 +55,12 @@ private void populateSubAttributeList(Object attributeValue) { } @Override - public LinkedList> getMetrics() + public List> getMetrics() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { - LinkedList> metrics = new LinkedList>(); + List> metrics = new ArrayList>( + subAttributeList.entrySet().size()); for (Map.Entry> pair : subAttributeList.entrySet()) { String subAttribute = pair.getKey(); @@ -146,8 +147,8 @@ private boolean matchSubAttribute( && ((Map) (params.getAttribute())) .containsKey(subAttributeName)) { return true; - } else if ((params.getAttribute() instanceof ArrayList - && ((ArrayList) (params.getAttribute())).contains(subAttributeName))) { + } else if ((params.getAttribute() instanceof List + && ((List) (params.getAttribute())).contains(subAttributeName))) { return true; } else if (params.getAttribute() == null) { return matchOnEmpty; diff --git a/src/main/java/org/datadog/jmxfetch/JmxSimpleAttribute.java b/src/main/java/org/datadog/jmxfetch/JmxSimpleAttribute.java index e3f7cf983..a5ff3b50b 100644 --- a/src/main/java/org/datadog/jmxfetch/JmxSimpleAttribute.java +++ b/src/main/java/org/datadog/jmxfetch/JmxSimpleAttribute.java @@ -3,7 +3,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; @@ -36,7 +36,7 @@ public JmxSimpleAttribute( } @Override - public LinkedList> getMetrics() + public List> getMetrics() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { HashMap metric = new HashMap(); @@ -45,7 +45,7 @@ public LinkedList> getMetrics() metric.put("value", castToDouble(getValue(), null)); metric.put("tags", getTags()); metric.put("metric_type", getMetricType()); - LinkedList> metrics = new LinkedList>(); + List> metrics = new ArrayList>(1); metrics.add(metric); return metrics; } @@ -69,8 +69,8 @@ private boolean excludeMatchAttribute(Configuration configuration) { .containsKey(getAttributeName())) { return true; - } else if ((exclude.getAttribute() instanceof ArrayList - && ((ArrayList) (exclude.getAttribute())).contains(getAttributeName()))) { + } else if ((exclude.getAttribute() instanceof List + && ((List) (exclude.getAttribute())).contains(getAttributeName()))) { return true; } return false; @@ -86,8 +86,8 @@ private boolean matchAttribute(Configuration configuration) { .containsKey(getAttributeName())) { return true; - } else if ((include.getAttribute() instanceof ArrayList - && ((ArrayList) (include.getAttribute())).contains(getAttributeName()))) { + } else if ((include.getAttribute() instanceof List + && ((List) (include.getAttribute())).contains(getAttributeName()))) { return true; } diff --git a/src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java b/src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java index 2e0a96b63..a8449adfe 100644 --- a/src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java +++ b/src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java @@ -10,7 +10,6 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.management.AttributeNotFoundException; @@ -126,12 +125,11 @@ protected String[] getTags(String key, String subAttribute) } @Override - public LinkedList> getMetrics() + public List> getMetrics() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { - LinkedList> metrics = new LinkedList>(); - HashMap>> subMetrics = - new HashMap>>(); + HashMap>> subMetrics = + new HashMap>>(); for (String dataKey : subAttributeList.keySet()) { HashMap> subSub = subAttributeList.get(dataKey); @@ -154,12 +152,14 @@ public LinkedList> getMetrics() String fullMetricKey = getAttributeName() + "." + metricKey; if (!subMetrics.containsKey(fullMetricKey)) { - subMetrics.put(fullMetricKey, new LinkedList>()); + subMetrics.put(fullMetricKey, new ArrayList>()); } subMetrics.get(fullMetricKey).add(metric); } } + List> metrics = + new ArrayList>(subMetrics.keySet().size()); for (String key : subMetrics.keySet()) { // only add explicitly included metrics if (getAttributesFor(key) != null) { @@ -171,7 +171,7 @@ public LinkedList> getMetrics() } private List> sortAndFilter( - String metricKey, LinkedList> metrics) { + String metricKey, List> metrics) { Map attributes = getAttributesFor(metricKey); if (!attributes.containsKey("limit")) { return metrics; @@ -287,8 +287,8 @@ private boolean matchSubAttribute( && ((Map) (params.getAttribute())) .containsKey(subAttributeName)) { return true; - } else if ((params.getAttribute() instanceof ArrayList - && ((ArrayList) (params.getAttribute())).contains(subAttributeName))) { + } else if ((params.getAttribute() instanceof List + && ((List) (params.getAttribute())).contains(subAttributeName))) { return true; } else if (params.getAttribute() == null) { return matchOnEmpty; diff --git a/src/main/java/org/datadog/jmxfetch/MetricCollectionTask.java b/src/main/java/org/datadog/jmxfetch/MetricCollectionTask.java index 12dd8b75d..6c6c7081d 100644 --- a/src/main/java/org/datadog/jmxfetch/MetricCollectionTask.java +++ b/src/main/java/org/datadog/jmxfetch/MetricCollectionTask.java @@ -2,25 +2,27 @@ import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; @Slf4j -class MetricCollectionTask extends InstanceTask>> { +class MetricCollectionTask extends InstanceTask>> { MetricCollectionTask(Instance instance) { super(instance); setWarning("Unable to collect metrics or refresh bean list."); } @Override - public LinkedList> call() throws Exception { + public List> call() throws Exception { if (!instance.timeToCollect()) { log.debug( "it is not time to collect, skipping run for instance: " + instance.getName()); // Maybe raise an exception here instead... - return new LinkedList>(); + return Collections.emptyList(); } return instance.getMetrics(); diff --git a/src/main/java/org/datadog/jmxfetch/Status.java b/src/main/java/org/datadog/jmxfetch/Status.java index 84e74495f..e85ba9dff 100644 --- a/src/main/java/org/datadog/jmxfetch/Status.java +++ b/src/main/java/org/datadog/jmxfetch/Status.java @@ -7,8 +7,9 @@ import org.yaml.snakeyaml.Yaml; import java.io.File; +import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; @Slf4j public class Status { @@ -81,15 +82,15 @@ private void addStats( String message, String status, String key) { - LinkedList> checkStats; + List> checkStats; HashMap initializedChecks; initializedChecks = (HashMap) this.instanceStats.get(key); if (initializedChecks == null) { initializedChecks = new HashMap(); } - checkStats = (LinkedList>) initializedChecks.get(checkName); + checkStats = (List>) initializedChecks.get(checkName); if (checkStats == null) { - checkStats = new LinkedList>(); + checkStats = new ArrayList>(); } HashMap instStats = new HashMap(); if (instance != null) { diff --git a/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java b/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java index 75bdd8b96..7e899bd57 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java @@ -7,15 +7,15 @@ import org.datadog.jmxfetch.Instance; import org.datadog.jmxfetch.JmxAttribute; +import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; @Slf4j public class ConsoleReporter extends Reporter { - private LinkedList> metrics = new LinkedList>(); - private LinkedList> serviceChecks = - new LinkedList>(); + private List> metrics = new ArrayList>(); + private List> serviceChecks = new ArrayList>(); @Override protected void sendMetricPoint( @@ -33,9 +33,9 @@ protected void sendMetricPoint( } /** Returns list of metrics to report and clears stored metric map. */ - public LinkedList> getMetrics() { - LinkedList> returnedMetrics = - new LinkedList>(); + public List> getMetrics() { + List> returnedMetrics = + new ArrayList>(metrics.size()); for (HashMap map : metrics) { returnedMetrics.add(new HashMap(map)); } @@ -61,9 +61,9 @@ public void doSendServiceCheck(String checkName, String status, String message, } /** Returns list of service checks to report and clears stored service check map.. */ - public LinkedList> getServiceChecks() { - LinkedList> returnedServiceChecks = - new LinkedList>(); + public List> getServiceChecks() { + List> returnedServiceChecks = + new ArrayList>(serviceChecks.size()); for (HashMap map : serviceChecks) { returnedServiceChecks.add(new HashMap(map)); } diff --git a/src/main/java/org/datadog/jmxfetch/reporter/JsonReporter.java b/src/main/java/org/datadog/jmxfetch/reporter/JsonReporter.java index bfe82b5cf..1bc429523 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/JsonReporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/JsonReporter.java @@ -10,21 +10,21 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; +import java.util.Map; @Slf4j public class JsonReporter extends Reporter { - private LinkedList> metrics = new LinkedList>(); + private List> metrics = new ArrayList>(); protected void sendMetricPoint( String metricType, String metricName, double value, String[] tags) { long currentTime = System.currentTimeMillis() / 1000L; - List point = new ArrayList(); + List point = new ArrayList(2); point.add(currentTime); point.add(value); - List points = new ArrayList(); + List points = new ArrayList(1); points.add(point); HashMap metric = new HashMap(); metric.put("host", "default"); @@ -43,7 +43,7 @@ public void doSendServiceCheck(String checkName, String status, String message, aggregator.put("metrics", metrics); HashMap serie = new HashMap(); serie.put("aggregator", aggregator); - List series = new ArrayList(); + List> series = new ArrayList>(1); series.add(serie); System.out.println("=== JSON ==="); diff --git a/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java b/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java index e97bbf087..d1101b0eb 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java @@ -9,7 +9,7 @@ import java.util.Arrays; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; @Slf4j public abstract class Reporter { @@ -47,7 +47,7 @@ public void clearCountersAggregator(String instanceName) { /** Submits the metrics in the implementing reporter. */ public void sendMetrics( - LinkedList> metrics, + List> metrics, String instanceName, boolean canonicalRate) { HashMap> instanceRatesAggregator; diff --git a/src/test/java/org/datadog/jmxfetch/TestApp.java b/src/test/java/org/datadog/jmxfetch/TestApp.java index 44c7449fb..f2f094587 100644 --- a/src/test/java/org/datadog/jmxfetch/TestApp.java +++ b/src/test/java/org/datadog/jmxfetch/TestApp.java @@ -10,7 +10,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import org.junit.Test; @@ -54,7 +53,7 @@ public void testBeanTags() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 14 = 13 metrics from java.lang + 1 metric explicitly defined in the yaml config file assertEquals(14, metrics.size()); @@ -80,7 +79,7 @@ public void testRegexpAliasing() throws Exception { // Collect metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // Assertions @@ -113,7 +112,7 @@ public void testNoAliasOnDetailedAttribute() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // Assertions @@ -147,7 +146,7 @@ public void testCassandraBean() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 14 = 2*13 metrics from java.lang + 2*1 metric explicitly defined in the yaml config file assertEquals(28, metrics.size()); @@ -186,7 +185,7 @@ public void testCassandraDeprecatedBean() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 14 = 13 metrics from java.lang + 1 metric explicitly defined in the yaml config file assertEquals(14, metrics.size()); @@ -210,7 +209,7 @@ public void testDomainInclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 29 = 13 metrics from java.lang + 16 metrics implicitly defined assertEquals(29, metrics.size()); @@ -228,7 +227,7 @@ public void testDomainExclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 14 = 13 metrics from java.lang + 2 metrics explicitly define- 1 implicitly // defined in the exclude section @@ -248,7 +247,7 @@ public void testDomainRegex() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 15 = 13 metrics from java.lang + 3 metrics explicitly defined - 1 implicitly // defined in exclude section @@ -265,7 +264,7 @@ public void testParameterMatch() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 13 default metrics from java.lang assertEquals(13, metrics.size()); @@ -281,7 +280,7 @@ public void testListParamsInclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 14 = 13 metrics from java.lang + 1 metrics explicitly defined assertEquals(14, metrics.size()); @@ -297,7 +296,7 @@ public void testListParamsExclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 13 = 13 metrics from java.lang + 2 metrics explicitly defined - 2 explicitly // defined @@ -314,7 +313,7 @@ public void testListBeansInclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 14 = 13 metrics from java.lang + 1 metrics explicitly defined assertEquals(14, metrics.size()); @@ -333,7 +332,7 @@ public void testListBeansRegexInclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 15 = 13 metrics from java.lang + 2 metrics explicitly defined assertEquals(15, metrics.size()); @@ -352,7 +351,7 @@ public void testListBeansRegexExclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 14 = 13 metrics from java.lang + 1 metrics explicitly defined assertEquals(14, metrics.size()); @@ -371,7 +370,7 @@ public void testListBeansExclude() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // First filter 14 = 13 metrics from java.lang + 1 metrics explicitly defined assertEquals(14, metrics.size()); @@ -402,7 +401,7 @@ public void testMetricTypes() throws Exception { initApplication("jmx_histogram.yaml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // We test for the presence and the value of the metrics we want to collect List commonTags = @@ -436,7 +435,7 @@ public void testExcludeTags() throws Exception { // We do a first collection initApplication("jmx_exclude_tags.yml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // We test for the presence and the value of the metrics we want to collect. // Tags "type", "newTag" and "env" should be excluded @@ -460,7 +459,7 @@ public void testAdditionalTags() throws Exception { // We do a first collection initApplication("jmx_additional_tags.yml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // We test for the presence and the value of the metrics we want to collect. // Tags "type", "newTag" and "env" should be excluded @@ -495,7 +494,7 @@ public void testApp() throws Exception { initApplication("jmx.yaml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 29 = 13 metrics from java.lang + the 6 gauges we are explicitly collecting + 9 gauges // implicitly collected @@ -609,7 +608,7 @@ public void testAppCanonicalRate() throws Exception { initApplication("jmx_canonical.yaml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 28 = 13 metrics from java.lang + the 5 gauges we are explicitly collecting + 9 gauges // implicitly collected @@ -769,7 +768,7 @@ public void testServiceDiscovery() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 14 = 13 metrics from java.lang + 1 metric explicitly defined in the yaml config file assertEquals(63, metrics.size()); @@ -836,8 +835,8 @@ public void testServiceDiscoveryLong() throws Exception { // Collecting metrics run(); - LinkedList> metrics = getMetrics(); - ArrayList instances = getInstances(); + List> metrics = getMetrics(); + List instances = getInstances(); assertEquals(35, metrics.size()); @@ -857,7 +856,7 @@ public void testMetricError() throws Exception { initApplication("jmx_cast.yaml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // 13 metrics from java.lang + 2 defined - 1 error assertEquals(14, metrics.size()); diff --git a/src/test/java/org/datadog/jmxfetch/TestCommon.java b/src/test/java/org/datadog/jmxfetch/TestCommon.java index e1d0fb84c..8f32d063e 100644 --- a/src/test/java/org/datadog/jmxfetch/TestCommon.java +++ b/src/test/java/org/datadog/jmxfetch/TestCommon.java @@ -14,7 +14,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import javax.management.InstanceAlreadyExistsException; @@ -35,9 +34,9 @@ public class TestCommon { AppConfig appConfig = spy(AppConfig.builder().build()); App app; MBeanServer mbs; - ArrayList objectNames = new ArrayList(); - LinkedList> metrics; - LinkedList> serviceChecks; + List objectNames = new ArrayList(); + List> metrics; + List> serviceChecks; /** Setup logger. */ @BeforeClass @@ -143,7 +142,7 @@ protected void run() { } /** Return configured instances */ - protected ArrayList getInstances() { + protected List getInstances() { return app.getInstances(); } @@ -153,12 +152,12 @@ protected Reporter getReporter() { } /** Return the metrics collected by JMXFetch. */ - protected LinkedList> getMetrics() { + protected List> getMetrics() { return metrics; } /** Return the service checks collected by JMXFetch. */ - protected LinkedList> getServiceChecks() { + protected List> getServiceChecks() { return ((ConsoleReporter) appConfig.getReporter()).getServiceChecks(); } @@ -330,8 +329,7 @@ public void assertMetric(String name, List tags, int countTags, String m */ public void assertCoverage() { int totalMetrics = 0; - LinkedList> untestedMetrics = - new LinkedList>(); + List> untestedMetrics = new ArrayList>(); for (HashMap m : metrics) { String mName = (String) (m.get("name")); @@ -361,7 +359,7 @@ public void assertCoverage() { * @return String report */ private static String generateReport( - LinkedList> untestedMetrics, int totalMetricsCount) { + List> untestedMetrics, int totalMetricsCount) { StringBuilder sb = new StringBuilder(); // Compute indicators diff --git a/src/test/java/org/datadog/jmxfetch/TestConfiguration.java b/src/test/java/org/datadog/jmxfetch/TestConfiguration.java index d293a4d66..bb4d360b1 100644 --- a/src/test/java/org/datadog/jmxfetch/TestConfiguration.java +++ b/src/test/java/org/datadog/jmxfetch/TestConfiguration.java @@ -11,14 +11,14 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import org.junit.BeforeClass; import org.junit.Test; public class TestConfiguration { - static LinkedList configurations = new LinkedList(); + static List configurations = new ArrayList(); static JsonParser adConfigs; /** @@ -33,13 +33,13 @@ public static void init() throws FileNotFoundException, IOException { String yamlPath = f.getAbsolutePath(); FileInputStream yamlInputStream = new FileInputStream(yamlPath); YamlParser fileConfig = new YamlParser(yamlInputStream); - ArrayList> configInstances = - ((ArrayList>) fileConfig.getYamlInstances()); + List> configInstances = + ((List>) fileConfig.getYamlInstances()); for (Map config : configInstances) { Object yamlConf = config.get("conf"); for (Map conf : - (ArrayList>) (yamlConf)) { + (List>) (yamlConf)) { configurations.add(new Configuration(conf)); } } @@ -69,12 +69,12 @@ public void testAutoDiscoveryConfigs() assertEquals(configurations.size(), 4); int nconfigs = 0; for (String check : configs.keySet()) { - ArrayList> configInstances = - ((ArrayList>) adConfigs.getJsonInstances(check)); + List> configInstances = + ((List>) adConfigs.getJsonInstances(check)); for (Map config : configInstances) { Object jsonConf = config.get("conf"); for (Map conf : - (ArrayList>) (jsonConf)) { + (List>) (jsonConf)) { configurations.add(new Configuration(conf)); nconfigs++; } @@ -100,12 +100,12 @@ public void testFiltersByDomain() // Private method reflection Method getIncludeFiltersByDomain = Configuration.class.getDeclaredMethod( - "getIncludeFiltersByDomain", LinkedList.class); + "getIncludeFiltersByDomain", List.class); getIncludeFiltersByDomain.setAccessible(true); // Assert - HashMap> filtersByDomain = - (HashMap>) + HashMap> filtersByDomain = + (HashMap>) getIncludeFiltersByDomain.invoke(null, configurations); // Only contains 'org.datadog.jmxfetch.test' domain @@ -133,7 +133,7 @@ public void testCommonBeanKeys() // Private method reflection Method getIncludeFiltersByDomain = Configuration.class.getDeclaredMethod( - "getIncludeFiltersByDomain", LinkedList.class); + "getIncludeFiltersByDomain", List.class); getIncludeFiltersByDomain.setAccessible(true); Method getCommonBeanKeysByDomain = @@ -141,8 +141,8 @@ public void testCommonBeanKeys() getCommonBeanKeysByDomain.setAccessible(true); // Assert - HashMap> filtersByDomain = - (HashMap>) + HashMap> filtersByDomain = + (HashMap>) getIncludeFiltersByDomain.invoke(null, configurations); HashMap> parametersIntersectionByDomain = (HashMap>) @@ -177,7 +177,7 @@ public void testCommonScope() // Private method reflection Method getIncludeFiltersByDomain = Configuration.class.getDeclaredMethod( - "getIncludeFiltersByDomain", LinkedList.class); + "getIncludeFiltersByDomain", List.class); getIncludeFiltersByDomain.setAccessible(true); Method getCommonBeanKeysByDomain = @@ -190,8 +190,8 @@ public void testCommonScope() getCommonScopeByDomain.setAccessible(true); // Assert - Map> filtersByDomain = - (Map>) + Map> filtersByDomain = + (Map>) getIncludeFiltersByDomain.invoke(null, configurations); Map> parametersIntersectionByDomain = (Map>) diff --git a/src/test/java/org/datadog/jmxfetch/TestInstance.java b/src/test/java/org/datadog/jmxfetch/TestInstance.java index 22f36f0d1..b2535bf73 100644 --- a/src/test/java/org/datadog/jmxfetch/TestInstance.java +++ b/src/test/java/org/datadog/jmxfetch/TestInstance.java @@ -9,9 +9,9 @@ import com.google.common.collect.Lists; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -26,7 +26,7 @@ public void testMinCollectionInterval() throws Exception { initApplication("jmx_min_collection_period.yml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); assertEquals(15, metrics.size()); run(); @@ -62,14 +62,14 @@ public void testEmptyDefaultHostname() throws Exception { initApplication("jmx_empty_default_hostname.yaml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); assertEquals(28, metrics.size()); for (HashMap metric : metrics) { String[] tags = (String[]) metric.get("tags"); this.assertHostnameTags(Arrays.asList(tags)); } - LinkedList> serviceChecks = getServiceChecks(); + List> serviceChecks = getServiceChecks(); assertEquals(2, serviceChecks.size()); for (HashMap sc : serviceChecks) { String[] tags = (String[]) sc.get("tags"); @@ -82,7 +82,7 @@ public void testLoadMetricConfigFiles() throws Exception { URL defaultConfig = Instance.class.getResource("default-jmx-metrics.yaml"); AppConfig config = mock(AppConfig.class); when(config.getMetricConfigFiles()).thenReturn(Lists.newArrayList(defaultConfig.getPath())); - LinkedList configurationList = new LinkedList(); + List configurationList = new ArrayList(); Instance.loadMetricConfigFiles(config, configurationList); assertEquals(2, configurationList.size()); @@ -94,7 +94,7 @@ public void testLoadMetricConfigResources() throws Exception { String configResource = defaultConfig.getPath().split("test-classes/")[1]; AppConfig config = mock(AppConfig.class); when(config.getMetricConfigResources()).thenReturn(Lists.newArrayList(configResource)); - LinkedList configurationList = new LinkedList(); + List configurationList = new ArrayList(); Instance.loadMetricConfigResources(config, configurationList); assertEquals(2, configurationList.size()); diff --git a/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java b/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java index b33f8e375..46dce6e93 100644 --- a/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java +++ b/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java @@ -8,7 +8,8 @@ import java.util.Arrays; import java.util.HashMap; -import java.util.LinkedList; +import java.util.List; + import org.datadog.jmxfetch.reporter.Reporter; import org.junit.Test; @@ -24,13 +25,13 @@ public void testServiceCheckOK() throws Exception { initApplication("jmx.yaml"); run(); - LinkedList> metrics = getMetrics(); + List> metrics = getMetrics(); // Test that an OK service check status is sent - LinkedList> serviceChecks = getServiceChecks(); + List> serviceChecks = getServiceChecks(); assertEquals(1, serviceChecks.size()); - HashMap sc = serviceChecks.getFirst(); + HashMap sc = serviceChecks.get(0); assertNotNull(sc.get("name")); assertNotNull(sc.get("status")); assertNull(sc.get("message")); @@ -64,12 +65,12 @@ public void testServiceCheckWarning() throws Exception { run(); // Test that an WARNING service check status is sent - LinkedList> serviceChecks = getServiceChecks(); - LinkedList> metrics = getMetrics(); + List> serviceChecks = getServiceChecks(); + List> metrics = getMetrics(); assertTrue(metrics.size() >= 350); assertEquals(1, serviceChecks.size()); - HashMap sc = serviceChecks.getFirst(); + HashMap sc = serviceChecks.get(0); assertNotNull(sc.get("name")); assertNotNull(sc.get("status")); @@ -99,10 +100,10 @@ public void testServiceCheckCRITICAL() throws Exception { initApplication("non_running_process.yaml"); // Test that a CRITICAL service check status is sent on initialization - LinkedList> serviceChecks = getServiceChecks(); + List> serviceChecks = getServiceChecks(); assertEquals(1, serviceChecks.size()); - HashMap sc = serviceChecks.getFirst(); + HashMap sc = serviceChecks.get(0); assertNotNull(sc.get("name")); assertNotNull(sc.get("status")); assertNotNull(sc.get("message")); @@ -129,7 +130,7 @@ public void testServiceCheckCRITICAL() throws Exception { serviceChecks = getServiceChecks(); assertEquals(1, serviceChecks.size()); - sc = serviceChecks.getFirst(); + sc = serviceChecks.get(0); assertNotNull(sc.get("name")); assertNotNull(sc.get("status")); assertNotNull(sc.get("message"));