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

Fix service check name for Console and Json Reporters #281

Closed
wants to merge 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ public List<Map<String, Object>> getMetrics() {
}

/** Adds service check to report on. */
public void doSendServiceCheck(String checkName, String status, String message, String[] tags) {
public void doSendServiceCheck(
String serviceCheckName, String status, String message, String[] tags) {
String tagString = "";
if (tags != null && tags.length > 0) {
tagString = "[" + Joiner.on(",").join(tags) + "]";
}
log.info(
checkName + tagString + " - " + System.currentTimeMillis() / 1000 + " = " + status);
log.info(serviceCheckName + tagString + " - "
+ System.currentTimeMillis() / 1000 + " = " + status);

Map<String, Object> sc = new HashMap<String, Object>();
sc.put("name", checkName);
sc.put("name", serviceCheckName);
sc.put("status", status);
sc.put("message", message);
sc.put("tags", tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ protected void sendMetricPoint(
}

/** Use the service check callback to display the JSON. */
public void doSendServiceCheck(String checkName, String status, String message, String[] tags) {
public void doSendServiceCheck(
String serviceCheckName, String status, String message, String[] tags) {
log.debug("Displaying JSON output");
Map<String, Object> sc = new HashMap<String, Object>();
sc.put("check", checkName);
sc.put("check", serviceCheckName);
sc.put("host_name", "default");
sc.put("timestamp", System.currentTimeMillis() / 1000);
sc.put("status", status);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/datadog/jmxfetch/reporter/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ public void sendMetrics(List<Metric> metrics, String instanceName, boolean canon
}

/** Submits service check. */
public void sendServiceCheck(String checkName, String status, String message, String[] tags) {
public void sendServiceCheck(
String checkName, String status, String message, String[] tags) {
this.incrementServiceCheckCount(checkName);
String dataName = Reporter.formatServiceCheckPrefix(checkName);
String serviceCheckName = String.format(
"%s.can_connect", Reporter.formatServiceCheckPrefix(checkName));

this.doSendServiceCheck(dataName, status, message, tags);
this.doSendServiceCheck(serviceCheckName, status, message, tags);
}

/** Increments the service check count - for book-keeping purposes. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ private ServiceCheck.Status statusToServiceCheckStatus(String status) {
}

/** Submits service check. */
public void doSendServiceCheck(String checkName, String status, String message, String[] tags) {
public void doSendServiceCheck(
String serviceCheckName, String status, String message, String[] tags) {
if (System.currentTimeMillis() - this.initializationTime > 300 * 1000) {
this.statsDClient.stop();
init();
}

ServiceCheck sc = ServiceCheck.builder()
.withName(String.format("%s.can_connect", checkName))
.withName(serviceCheckName)
.withStatus(this.statusToServiceCheckStatus(status))
.withMessage(message)
.withTags(tags)
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/datadog/jmxfetch/TestServiceChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testServiceCheckOK() throws Exception {
String scStatus = (String) (sc.get("status"));
String[] scTags = (String[]) (sc.get("tags"));

assertEquals(Reporter.formatServiceCheckPrefix("jmx"), scName);
assertEquals(Reporter.formatServiceCheckPrefix("jmx") + ".can_connect", scName);
assertEquals(Status.STATUS_OK, scStatus);
assertEquals(scTags.length, 3);
assertTrue(Arrays.asList(scTags).contains("instance:jmx_test_instance"));
Expand Down Expand Up @@ -83,7 +83,7 @@ public void testServiceCheckWarning() throws Exception {
String scStatus = (String) (sc.get("status"));
String[] scTags = (String[]) (sc.get("tags"));

assertEquals(Reporter.formatServiceCheckPrefix("too_many_metrics"), scName);
assertEquals(Reporter.formatServiceCheckPrefix("too_many_metrics") + ".can_connect", scName);
// We should have an OK service check status when too many metrics are getting sent
assertEquals(Status.STATUS_OK, scStatus);
assertEquals(scTags.length, 3);
Expand Down Expand Up @@ -115,7 +115,7 @@ public void testServiceCheckCRITICAL() throws Exception {
String scMessage = (String) (sc.get("message"));
String[] scTags = (String[]) (sc.get("tags"));

assertEquals(Reporter.formatServiceCheckPrefix("non_running_process"), scName);
assertEquals(Reporter.formatServiceCheckPrefix("non_running_process") + ".can_connect", scName);
assertEquals(Status.STATUS_ERROR, scStatus);
assertEquals(
"Unable to instantiate or initialize instance process_regex: `.*non_running_process_test.*`. "
Expand All @@ -142,7 +142,7 @@ public void testServiceCheckCRITICAL() throws Exception {
scMessage = (String) (sc.get("message"));
scTags = (String[]) (sc.get("tags"));

assertEquals(Reporter.formatServiceCheckPrefix("non_running_process"), scName);
assertEquals(Reporter.formatServiceCheckPrefix("non_running_process") + ".can_connect", scName);
assertEquals(Status.STATUS_ERROR, scStatus);
assertEquals(
"Unable to instantiate or initialize instance process_regex: `.*non_running_process_test.*`. "
Expand Down