From f8472d20a8e62050e65ea85695bf268089973f20 Mon Sep 17 00:00:00 2001 From: Yann Mahe Date: Thu, 2 Apr 2015 11:11:15 -0400 Subject: [PATCH] fix bad regression with `Status` type --- CHANGELOG.md | 6 +++++- pom.xml | 2 +- src/main/java/org/datadog/jmxfetch/App.java | 4 ++-- src/main/java/org/datadog/jmxfetch/Status.java | 12 ++++++------ .../jmxfetch/reporter/ConsoleReporter.java | 4 ++-- .../org/datadog/jmxfetch/reporter/Reporter.java | 2 +- .../jmxfetch/reporter/StatsdReporter.java | 16 ++++++++++++++-- src/test/java/org/datadog/jmxfetch/TestApp.java | 8 ++++---- 8 files changed, 35 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32754cf16..d300389df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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][] @@ -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 diff --git a/pom.xml b/pom.xml index 6fcb2792a..de82d3dd4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ datadog jmxfetch - 0.5.0 + 0.5.1 jar jmxfetch diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java index eb3930625..f72cfd78b 100644 --- a/src/main/java/org/datadog/jmxfetch/App.java +++ b/src/main/java/org/datadog/jmxfetch/App.java @@ -166,7 +166,7 @@ public void doIteration() { while (it.hasNext()) { Instance instance = it.next(); LinkedList> metrics; - int instanceStatus = Status.STATUS_OK; + String instanceStatus = Status.STATUS_OK; String instanceMessage = null; try { metrics = instance.getMetrics(); @@ -282,7 +282,7 @@ private HashMap 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); diff --git a/src/main/java/org/datadog/jmxfetch/Status.java b/src/main/java/org/datadog/jmxfetch/Status.java index 725747c66..2fb2dde6e 100644 --- a/src/main/java/org/datadog/jmxfetch/Status.java +++ b/src/main/java/org/datadog/jmxfetch/Status.java @@ -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"; @@ -40,12 +40,12 @@ private void clearStats() { instanceStats.put(FAILED_CHECKS, new HashMap()); } - 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> checkStats; HashMap initializedChecks; initializedChecks = (HashMap) this.instanceStats.get(key); @@ -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); } diff --git a/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java b/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java index 72ce2686c..9c1038885 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/ConsoleReporter.java @@ -34,7 +34,7 @@ public LinkedList> 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) + "]"; @@ -43,7 +43,7 @@ public void sendServiceCheck(String checkName, int status, String message, Strin HashMap sc = new HashMap(); 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); diff --git a/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java b/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java index 70bf2b9e0..77bac0c7d 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/Reporter.java @@ -108,7 +108,7 @@ private void postProcessCassandra(HashMap 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(); diff --git a/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java b/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java index 6175cf3d2..d98405722 100644 --- a/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java +++ b/src/main/java/org/datadog/jmxfetch/reporter/StatsdReporter.java @@ -31,7 +31,19 @@ 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(); @@ -39,7 +51,7 @@ public void sendServiceCheck(String checkName, int status, String message, } ServiceCheck sc = new ServiceCheck(String.format("%s.can_connect", checkName), - status, message, hostname, tags); + this.statusToInt(status), message, hostname, tags); statsDClient.serviceCheck(sc); } diff --git a/src/test/java/org/datadog/jmxfetch/TestApp.java b/src/test/java/org/datadog/jmxfetch/TestApp.java index ab78a7c67..3c7a62aed 100644 --- a/src/test/java/org/datadog/jmxfetch/TestApp.java +++ b/src/test/java/org/datadog/jmxfetch/TestApp.java @@ -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); @@ -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); @@ -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")); @@ -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"));