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

Issue #90. Fix bean names with ':' in the name. #91

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>datadog</groupId>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/datadog/jmxfetch/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.datadog.jmxfetch;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/datadog/jmxfetch/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/datadog/jmxfetch/Filter.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.datadog.jmxfetch;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.lang.ClassCastException;
import java.util.regex.Pattern;


Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/datadog/jmxfetch/JMXAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public abstract class JMXAttribute {

// A bean name is formatted like that: org.apache.cassandra.db:type=Caches,keyspace=system,cache=HintsColumnFamilyKeyCache
// i.e. : domain:bean_parameter1,bean_parameter2
String[] splitBeanName = beanStringName.split(":");
String domain = splitBeanName[0];
String beanParameters = splitBeanName[1];
//Note: some beans have a ':' in the name. Example: some.domain:name="some.bean.0.0.0.0:80.some-metric"
int splitPosition = beanStringName.indexOf(':');
String domain = beanStringName.substring(0, splitPosition);
String beanParameters = beanStringName.substring(splitPosition+1);
this.domain = domain;

HashMap<String, String> beanParametersHash = getBeanParametersHash(beanParameters);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/datadog/jmxfetch/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.HashMap;
import java.util.LinkedList;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.yaml.snakeyaml.Yaml;
import org.apache.commons.io.FileUtils;

public class Status {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.datadog.jmxfetch.converter;

import com.beust.jcommander.IStringConverter;
import org.datadog.jmxfetch.ExitWatcher;

import com.beust.jcommander.IStringConverter;

public class ExitWatcherConverter implements IStringConverter<ExitWatcher> {

public ExitWatcher convert(String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.datadog.jmxfetch.converter;

import com.beust.jcommander.IStringConverter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.reporter.ReporterFactory;

import com.beust.jcommander.IStringConverter;

public class ReporterConverter implements IStringConverter<Reporter> {

public Reporter convert(String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.datadog.jmxfetch.converter;

import com.beust.jcommander.IStringConverter;
import org.datadog.jmxfetch.Status;

import com.beust.jcommander.IStringConverter;

public class StatusConverter implements IStringConverter<Status> {

public Status convert(String value) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/datadog/jmxfetch/reporter/Reporter.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.datadog.jmxfetch.reporter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.datadog.jmxfetch.App;
import org.datadog.jmxfetch.Instance;
import org.datadog.jmxfetch.JMXAttribute;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.lang.Integer;
import java.util.LinkedList;


public abstract class Reporter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.datadog.jmxfetch.reporter;

import com.google.common.base.Joiner;
import java.util.Arrays;

import com.google.common.base.Joiner;

public class ReporterFactory {

public static Reporter getReporter(String type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.datadog.jmxfetch.reporter;

import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.StatsDClient;
import com.timgroup.statsd.ServiceCheck;
import org.datadog.jmxfetch.Instance;
import org.datadog.jmxfetch.JMXAttribute;
import org.datadog.jmxfetch.Status;

import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.ServiceCheck;
import com.timgroup.statsd.StatsDClient;

public class StatsdReporter extends Reporter {

private StatsDClient statsDClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.datadog.jmxfetch.validator;

import java.util.Arrays;
import java.util.List;

import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.ParameterException;
import com.google.common.base.Joiner;

import java.util.Arrays;
import java.util.List;

public class Log4JLevelValidator implements IParameterValidator {
public static final List<String> LOG4J_LEVELS = Arrays.asList("ALL", "DEBUG", "ERROR", "FATAL",
"INFO", "OFF", "TRACE", "LEVEL", "WARN");
Expand Down
67 changes: 30 additions & 37 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.datadog.jmxfetch;

import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
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 static org.junit.Assert.*;
import org.junit.Test;

public class TestApp extends TestCommon {

Expand Down Expand Up @@ -77,25 +73,24 @@ public void testCassandraBean() throws Exception {
assertEquals(28, metrics.size());

// Assert compliancy with CASSANDRA-4009
ArrayList<String> tags = new ArrayList<String>() {{
add("type:ColumnFamily");
add("keyspace:MyKeySpace");
add("ColumnFamily:MyColumnFamily");
add("jmx_domain:org.apache.cassandra.metrics");
add("instance:jmx_first_instance");
}};
List<String> tags = Arrays.asList(
"type:ColumnFamily",
"keyspace:MyKeySpace",
"ColumnFamily:MyColumnFamily",
"jmx_domain:org.apache.cassandra.metrics",
"instance:jmx_first_instance"
);

assertMetric("cassandra.pending_tasks.should_be100", tags, 5);

// Default behavior
tags = new ArrayList<String>() {{
add("type:ColumnFamily");
add("scope:MyColumnFamily");
add("keyspace:MyKeySpace");
add("jmx_domain:org.apache.cassandra.metrics");
add("instance:jmx_second_instance");
add("name:PendingTasks");
}};
tags = Arrays.asList(
"type:ColumnFamily",
"scope:MyColumnFamily",
"keyspace:MyKeySpace",
"jmx_domain:org.apache.cassandra.metrics",
"instance:jmx_second_instance",
"name:PendingTasks");

assertMetric("cassandra.metrics.should_be1000", tags, 6);
}
Expand All @@ -113,13 +108,12 @@ public void testCassandraDeprecatedBean() throws Exception {
// 14 = 13 metrics from java.lang + 1 metric explicitly defined in the yaml config file
assertEquals(14, metrics.size());

ArrayList<String> tags = new ArrayList<String>() {{
add("type:ColumnFamilies");
add("keyspace:MyKeySpace");
add("columnfamily:MyColumnFamily");
add("jmx_domain:org.apache.cassandra.db");
add("instance:jmx_test_instance");
}};
List<String> tags = Arrays.asList(
"type:ColumnFamilies",
"keyspace:MyKeySpace",
"columnfamily:MyColumnFamily",
"jmx_domain:org.apache.cassandra.db",
"instance:jmx_test_instance");

assertMetric("cassandra.db.should_be100", tags, 5);
}
Expand Down Expand Up @@ -329,13 +323,12 @@ public void testApp() throws Exception {
assertEquals(27, metrics.size()); // 27 = 13 metrics from java.lang + the 5 gauges we are explicitly collecting + the 9 gauges that is implicitly collected, see jmx.yaml in the test/resources folder

// We test for the presence and the value of the metrics we want to collect
ArrayList<String> commonTags = new ArrayList<String>() {{
add("instance:jmx_test_instance");
add("env:stage");
add("newTag:test");
}};
List<String> commonTags = Arrays.asList(
"instance:jmx_test_instance",
"env:stage",
"newTag:test");

assertMetric("this.is.100", 100.0, commonTags, new ArrayList<String>() {{add("foo");add("gorch");add("bar:baz");}} , 8);
assertMetric("this.is.100", 100.0, commonTags, Arrays.asList("foo","gorch","bar:baz") , 8);
assertMetric("jmx.org.datadog.jmxfetch.test.number_big", 1.2345678890123457E20, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.long42424242",4.2424242E7, commonTags, 5);
assertMetric("jmx.org.datadog.jmxfetch.test.int424242", 424242.0, commonTags, 5);
Expand Down
34 changes: 18 additions & 16 deletions src/test/java/org/datadog/jmxfetch/TestCommon.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.datadog.jmxfetch;

import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.util.CustomLogger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.lang.management.ManagementFactory;
import java.util.ArrayList;
Expand All @@ -15,18 +15,20 @@

import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import org.apache.log4j.Level;
import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.util.CustomLogger;
import org.junit.After;
import org.junit.BeforeClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.beust.jcommander.JCommander;
import org.apache.log4j.Level;


public class TestCommon {
Expand Down Expand Up @@ -140,7 +142,7 @@ protected LinkedList<HashMap<String, Object>> getServiceChecks(){
*
* @return fail if the metric was not found
*/
public void assertMetric(String name, Number value, Number lowerBound, Number upperBound, ArrayList<String> commonTags, ArrayList<String> additionalTags, int countTags){
public void assertMetric(String name, Number value, Number lowerBound, Number upperBound, List<String> commonTags, List<String> additionalTags, int countTags){
List<String> tags = new ArrayList<String>(commonTags);
tags.addAll(additionalTags);

Expand Down Expand Up @@ -173,23 +175,23 @@ public void assertMetric(String name, Number value, Number lowerBound, Number up
fail("Metric assertion failed (name: "+name+", value: "+value+", tags: "+tags+", #tags: "+countTags+").");
}

public void assertMetric(String name, Number value, ArrayList<String> commonTags, ArrayList<String> additionalTags, int countTags){
public void assertMetric(String name, Number value, List<String> commonTags, List<String> additionalTags, int countTags){
assertMetric(name, value, -1, -1, commonTags, additionalTags, countTags);
}

public void assertMetric(String name, Number lowerBound, Number upperBound, ArrayList<String> commonTags, ArrayList<String> additionalTags, int countTags){
public void assertMetric(String name, Number lowerBound, Number upperBound, List<String> commonTags, List<String> additionalTags, int countTags){
assertMetric(name, -1, lowerBound, upperBound, commonTags, additionalTags, countTags);
}

public void assertMetric(String name, Number value, ArrayList<String> tags, int countTags){
public void assertMetric(String name, Number value, List<String> tags, int countTags){
assertMetric(name, value, tags, new ArrayList<String>(), countTags);
}

public void assertMetric(String name, Number lowerBound, Number upperBound, ArrayList<String> tags, int countTags){
public void assertMetric(String name, Number lowerBound, Number upperBound, List<String> tags, int countTags){
assertMetric(name, lowerBound, upperBound, tags, new ArrayList<String>(), countTags);
}

public void assertMetric(String name, ArrayList<String> tags, int countTags){
public void assertMetric(String name, List<String> tags, int countTags){
assertMetric(name, -1, tags, new ArrayList<String>(), countTags);
}

Expand All @@ -204,8 +206,8 @@ public void assertCoverage(){

for (HashMap<String, Object> m: metrics) {
String mName = (String) (m.get("name"));
Double mValue = (Double) (m.get("value"));
Set<String> mTags = new HashSet<String>(Arrays.asList((String[]) (m.get("tags"))));
//Double mValue = (Double) (m.get("value"));
//Set<String> mTags = new HashSet<String>(Arrays.asList((String[]) (m.get("tags"))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove these lines completely ? :)


// Exclusion logic
if (mName.startsWith("jvm.")) {
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/org/datadog/jmxfetch/TestConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.datadog.jmxfetch;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand All @@ -14,8 +17,6 @@
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

public class TestConfiguration {
static LinkedList<Configuration> configurations = new LinkedList<Configuration>();

Expand Down Expand Up @@ -48,6 +49,7 @@ public static void init() throws FileNotFoundException {
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
@SuppressWarnings("unchecked")
@Test
public void testFiltersByDomain() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
// Private method reflection
Expand All @@ -74,6 +76,7 @@ public void testFiltersByDomain() throws NoSuchMethodException, SecurityExceptio
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
@SuppressWarnings("unchecked")
@Test
public void testCommonBeanKeys() throws FileNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
// Private method reflection
Expand Down Expand Up @@ -107,6 +110,7 @@ public void testCommonBeanKeys() throws FileNotFoundException, NoSuchMethodExcep
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
@SuppressWarnings("unchecked")
@Test
public void testCommonScope() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
// Private method reflection
Expand Down
Loading