Skip to content

Commit

Permalink
fix bad regression with Status type
Browse files Browse the repository at this point in the history
  • Loading branch information
yannmh committed Apr 2, 2015
1 parent 0c825a3 commit f8472d2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Changes
=======

# 0.5.0 / Unreleased
# 0.5.1 / 04-02-2015
* [BUGFIX] Fix bad regression with `Status` type. See [#49][]

# 0.5.0 / 03-16-2015
* [FEATURE] Send service checks for JMX integrations
* [FEATURE] Support list of filters instead of simple filters: See [#20][]

Expand All @@ -26,4 +29,5 @@ Changes
[#26]: https://github.com/DataDog/jmxfetch/issues/26
[#28]: https://github.com/DataDog/jmxfetch/issues/28
[#30]: https://github.com/DataDog/jmxfetch/issues/30
[#49]: https://github.com/DataDog/jmxfetch/issues/49
[@coupacooke]: https://github.com/coupacooke
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>datadog</groupId>
<artifactId>jmxfetch</artifactId>
<version>0.5.0</version>
<version>0.5.1</version>
<packaging>jar</packaging>

<name>jmxfetch</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void doIteration() {
while (it.hasNext()) {
Instance instance = it.next();
LinkedList<HashMap<String, Object>> metrics;
int instanceStatus = Status.STATUS_OK;
String instanceStatus = Status.STATUS_OK;
String instanceMessage = null;
try {
metrics = instance.getMetrics();
Expand Down Expand Up @@ -282,7 +282,7 @@ private HashMap<String, YamlParser> getConfigs(AppConfig config) {
}

private void reportStatus(AppConfig appConfig, Reporter reporter, Instance instance,
int metricCount, String message, int status) {
int metricCount, String message, String status) {
String checkName = instance.getCheckName();
appConfig.getStatus().addInstanceStats(checkName, instance.getName(),
metricCount, message, status);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/datadog/jmxfetch/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

public class Status {

public final static int STATUS_WARNING = 1;
public final static int STATUS_OK = 0;
public final static int STATUS_ERROR = 2;
public final static String STATUS_WARNING = "WARNING";
public final static String STATUS_OK = "OK";
public final static String STATUS_ERROR = "ERROR";
private final static Logger LOGGER = Logger.getLogger(Status.class.getName());
private final static String INITIALIZED_CHECKS = "initialized_checks";
private final static String FAILED_CHECKS = "failed_checks";
Expand Down Expand Up @@ -40,12 +40,12 @@ private void clearStats() {
instanceStats.put(FAILED_CHECKS, new HashMap<String, Object>());
}

public void addInstanceStats(String checkName, String instance, int metricCount, String message, int status) {
public void addInstanceStats(String checkName, String instance, int metricCount, String message, String status) {
addStats(checkName, instance, metricCount, message, status, INITIALIZED_CHECKS);
}

@SuppressWarnings("unchecked")
private void addStats(String checkName, String instance, int metricCount, String message, int status, String key) {
private void addStats(String checkName, String instance, int metricCount, String message, String status, String key) {
LinkedList<HashMap<String, Object>> checkStats;
HashMap<String, Object> initializedChecks;
initializedChecks = (HashMap<String, Object>) this.instanceStats.get(key);
Expand All @@ -70,7 +70,7 @@ private void addStats(String checkName, String instance, int metricCount, String
this.instanceStats.put(key, initializedChecks);
}

public void addInitFailedCheck(String checkName, String message, int status) {
public void addInitFailedCheck(String checkName, String message, String status) {
addStats(checkName, null, -1, message, status, FAILED_CHECKS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LinkedList<HashMap<String, Object>> getMetrics() {
return returnedMetrics;
}

public void sendServiceCheck(String checkName, int status, String message, String hostname, String[] tags) {
public void sendServiceCheck(String checkName, String status, String message, String hostname, String[] tags) {
String tagString = "";
if (tags != null && tags.length > 0) {
tagString = "[" + Joiner.on(",").join(tags) + "]";
Expand All @@ -43,7 +43,7 @@ public void sendServiceCheck(String checkName, int status, String message, Strin

HashMap<String, Object> sc = new HashMap<String, Object>();
sc.put("name", checkName);
sc.put("status", Integer.toString(status));
sc.put("status", status);
sc.put("message", message);
sc.put("hostname", hostname);
sc.put("tags", tags);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/datadog/jmxfetch/reporter/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void postProcessCassandra(HashMap<String, Object> metric) {

protected abstract void sendMetricPoint(String metricName, double value, String[] tags);

public abstract void sendServiceCheck(String checkName, int status, String message, String hostname, String[] tags);
public abstract void sendServiceCheck(String checkName, String status, String message, String hostname, String[] tags);

public abstract void displayMetricReached();

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@ protected void sendMetricPoint(String metricName, double value, String[] tags) {
statsDClient.gauge(metricName, value, tags);
}

public void sendServiceCheck(String checkName, int status, String message,
private int statusToInt(String status) {
if (status == Status.STATUS_OK) {
return 0;
} else if (status == Status.STATUS_WARNING) {
return 1;
} else if (status == Status.STATUS_ERROR) {
// critical
return 2;
}
return 3;
}

public void sendServiceCheck(String checkName, String status, String message,
String hostname, String[] tags) {
if (System.currentTimeMillis() - this.initializationTime > 300 * 1000) {
this.statsDClient.stop();
init();
}

ServiceCheck sc = new ServiceCheck(String.format("%s.can_connect", checkName),
status, message, hostname, tags);
this.statusToInt(status), message, hostname, tags);
statsDClient.serviceCheck(sc);
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void testServiceCheckOK() throws Exception {
assertNotNull(sc.get("tags"));

String scName = (String) (sc.get("name"));
int scStatus = Integer.parseInt((String) (sc.get("status")));
String scStatus = (String) (sc.get("status"));
String[] scTags = (String[]) (sc.get("tags"));

assertEquals("jmx", scName);
Expand Down Expand Up @@ -318,7 +318,7 @@ public void testServiceCheckWarning() throws Exception {
assertNotNull(sc.get("tags"));

String scName = (String) (sc.get("name"));
int scStatus = Integer.parseInt((String) (sc.get("status")));
String scStatus = (String) (sc.get("status"));
String[] scTags = (String[]) (sc.get("tags"));

assertEquals("too_many_metrics", scName);
Expand Down Expand Up @@ -355,7 +355,7 @@ public void testServiceCheckCRITICAL() throws Exception {
assertNotNull(sc.get("tags"));

String scName = (String) (sc.get("name"));
int scStatus = Integer.parseInt((String) (sc.get("status")));
String scStatus = (String) (sc.get("status"));
String scMessage = (String) (sc.get("message"));
String[] scTags = (String[]) (sc.get("tags"));

Expand All @@ -381,7 +381,7 @@ public void testServiceCheckCRITICAL() throws Exception {
assertNotNull(sc.get("tags"));

scName = (String) (sc.get("name"));
scStatus = Integer.parseInt((String) (sc.get("status")));
scStatus = (String) (sc.get("status"));
scMessage = (String) (sc.get("message"));
scTags = (String[]) (sc.get("tags"));

Expand Down

0 comments on commit f8472d2

Please sign in to comment.