You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by wa...@apache.org on 2023/10/16 05:13:52 UTC
[dolphinscheduler] branch dev updated: [Improvement][Alert] Alert plugin enhance fail message (#15024)
This is an automated email from the ASF dual-hosted git repository.
wangyang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 154e1679f9 [Improvement][Alert] Alert plugin enhance fail message (#15024)
154e1679f9 is described below
commit 154e1679f9e162ef04a4c4fe6d4b07f87122c546
Author: 旺阳 <wa...@lqwang.net>
AuthorDate: Mon Oct 16 00:13:45 2023 -0500
[Improvement][Alert] Alert plugin enhance fail message (#15024)
* add webex && pagerduty fail log
* update
* fix spotless
* Update dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
Co-authored-by: xiangzihao <zi...@apache.org>
* update
---------
Co-authored-by: xiangzihao <zi...@apache.org>
---
.../plugin/alert/email/MailSender.java | 4 +-
.../plugin/alert/http/HttpSender.java | 3 +-
.../plugin/alert/pagerduty/PagerDutySender.java | 7 +++
.../plugin/alert/webexteams/WebexMessage.java | 51 ++--------------------
.../plugin/alert/webexteams/WebexTeamsSender.java | 10 ++++-
5 files changed, 24 insertions(+), 51 deletions(-)
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java
index f323219dab..2e400efbce 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java
@@ -405,7 +405,9 @@ public final class MailSender {
*/
private void handleException(AlertResult alertResult, Exception e) {
log.error("Send email to {} failed", receivers, e);
- alertResult.setMessage("Send email to {" + String.join(",", receivers) + "} failed," + e.toString());
+ alertResult.setMessage(
+ String.format("Send email to: %s, failed: %s",
+ String.join(",", receivers), e.getMessage()));
}
}
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
index bdd6cf15cd..32448393ce 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
@@ -100,7 +100,8 @@ public final class HttpSender {
} catch (Exception e) {
log.error("send http alert msg exception : {}", e.getMessage());
alertResult.setStatus("false");
- alertResult.setMessage("send http request alert fail.");
+ alertResult.setMessage(
+ String.format("Send http request alert failed: %s", e.getMessage()));
}
return alertResult;
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java
index 568faf167b..65792c8eae 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java
@@ -21,12 +21,14 @@ import org.apache.dolphinscheduler.alert.api.AlertResult;
import org.apache.dolphinscheduler.alert.api.HttpServiceRetryStrategy;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -77,11 +79,16 @@ public final class PagerDutySender {
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
+ HttpEntity entity = response.getEntity();
+ String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8);
try {
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) {
alertResult.setStatus("true");
alertResult.setMessage("send pager duty alert success");
} else {
+ alertResult.setMessage(
+ String.format("send pager duty alert error, statusCode: %s, responseContent: %s",
+ statusCode, responseContent));
log.info("send pager duty alert fail, statusCode : {}", statusCode);
}
} finally {
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java
index 4a417909e4..199ccd5ea1 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexMessage.java
@@ -17,6 +17,9 @@
package org.apache.dolphinscheduler.plugin.alert.webexteams;
+import lombok.Data;
+
+@Data
public class WebexMessage {
private String roomId;
@@ -25,52 +28,4 @@ public class WebexMessage {
private String text;
private String markdown;
private String html;
-
- public String getRoomId() {
- return roomId;
- }
-
- public void setRoomId(String roomId) {
- this.roomId = roomId;
- }
-
- public String getToPersonId() {
- return toPersonId;
- }
-
- public void setToPersonId(String toPersonId) {
- this.toPersonId = toPersonId;
- }
-
- public String getToPersonEmail() {
- return toPersonEmail;
- }
-
- public void setToPersonEmail(String toPersonEmail) {
- this.toPersonEmail = toPersonEmail;
- }
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public String getMarkdown() {
- return markdown;
- }
-
- public void setMarkdown(String markdown) {
- this.markdown = markdown;
- }
-
- public String getHtml() {
- return html;
- }
-
- public void setHtml(String html) {
- this.html = html;
- }
}
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java
index cd9ca87157..f8201a40e0 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-webexteams/src/main/java/org/apache/dolphinscheduler/plugin/alert/webexteams/WebexTeamsSender.java
@@ -22,12 +22,14 @@ import org.apache.dolphinscheduler.alert.api.AlertResult;
import org.apache.dolphinscheduler.alert.api.HttpServiceRetryStrategy;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -82,15 +84,21 @@ public final class WebexTeamsSender {
HttpClients.custom().setRetryHandler(HttpServiceRetryStrategy.retryStrategy).build();
try {
- HttpPost httpPost = constructHttpPost(getMessage(alertData), botAccessToken);
+ WebexMessage message = getMessage(alertData);
+ HttpPost httpPost = constructHttpPost(message, botAccessToken);
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
+ HttpEntity entity = response.getEntity();
+ String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8);
try {
if (statusCode == HttpStatus.SC_OK) {
alertResult.setStatus("true");
alertResult.setMessage("send webex teams alert success");
} else {
+ alertResult.setMessage(String.format(
+ "send webex teams alert error, message: %s, statusCode: %s, responseContent: %s", message,
+ statusCode, responseContent));
log.info("send webex teams alert fail, statusCode : {}", statusCode);
}
} finally {