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 6096c58cb7 [feature#14654] alert-spi support prometheus alertmanager
(#15079)
6096c58cb7 is described below
commit 6096c58cb7049783b8f67e790e6a5d62969a4bdf
Author: Jingliu Xiong <[email protected]>
AuthorDate: Mon Nov 13 13:23:33 2023 +0800
[feature#14654] alert-spi support prometheus alertmanager (#15079)
* feat alert-spi support prometheus alert manager
* fix: fix err into message
* Update
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSender.java
Co-authored-by: 旺阳 <[email protected]>
---
.../dolphinscheduler-alert-all/pom.xml | 5 +
.../dolphinscheduler/alert/api/AlertInputTips.java | 3 +-
.../pom.xml | 33 ++--
.../alert/prometheus/PrometheusAlertChannel.java | 39 +++++
.../prometheus/PrometheusAlertChannelFactory.java | 74 +++++++++
.../alert/prometheus/PrometheusAlertConstants.java | 30 ++++
.../alert/prometheus/PrometheusAlertSender.java | 166 +++++++++++++++++++++
.../prometheus/PrometheusAlertFactoryTest.java | 45 ++++++
.../prometheus/PrometheusAlertSenderTest.java | 71 +++++++++
.../dolphinscheduler-alert-plugins/pom.xml | 1 +
dolphinscheduler-ui/src/locales/en_US/security.ts | 4 +-
dolphinscheduler-ui/src/locales/zh_CN/security.ts | 4 +-
12 files changed, 453 insertions(+), 22 deletions(-)
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-all/pom.xml
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-all/pom.xml
index 69b588d7b8..ec8f53fd41 100644
---
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-all/pom.xml
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-all/pom.xml
@@ -27,6 +27,11 @@
<artifactId>dolphinscheduler-alert-all</artifactId>
<dependencies>
+ <dependency>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler-alert-prometheus</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-alert-dingtalk</artifactId>
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInputTips.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInputTips.java
index dce02b16c9..ec8f4184e0 100644
---
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInputTips.java
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInputTips.java
@@ -50,7 +50,8 @@ public enum AlertInputTips {
SECRET("please input secret", "请输入secret"),
WECHAT_MENTION_USERS("use `|` to separate userIds and `@all` to everyone",
"使用`|`来分割userId或使用`@all`来提到所有人"),
WECHAT_AGENT_ID("please input agent id or chat id", "请输入agent id或chat id"),
- ;
+ ANNOTATION("please input annotation in json form", "请输入json格式的annotation"),
+ GENERATOR_URL("please input Generator URL", "请输入生成地址");
private final String enMsg;
private final String zhMsg;
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/pom.xml
similarity index 57%
copy from dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
copy to
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/pom.xml
index 8d9b5d7a73..8182b2fa49 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/pom.xml
@@ -16,29 +16,24 @@
~ limitations under the License.
-->
<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">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dolphinscheduler</groupId>
- <artifactId>dolphinscheduler-alert</artifactId>
+ <artifactId>dolphinscheduler-alert-plugins</artifactId>
<version>dev-SNAPSHOT</version>
</parent>
- <artifactId>dolphinscheduler-alert-plugins</artifactId>
- <packaging>pom</packaging>
-
- <modules>
- <module>dolphinscheduler-alert-all</module>
- <module>dolphinscheduler-alert-api</module>
- <module>dolphinscheduler-alert-email</module>
- <module>dolphinscheduler-alert-wechat</module>
- <module>dolphinscheduler-alert-dingtalk</module>
- <module>dolphinscheduler-alert-script</module>
- <module>dolphinscheduler-alert-http</module>
- <module>dolphinscheduler-alert-feishu</module>
- <module>dolphinscheduler-alert-slack</module>
- <module>dolphinscheduler-alert-pagerduty</module>
- <module>dolphinscheduler-alert-webexteams</module>
- <module>dolphinscheduler-alert-telegram</module>
- </modules>
+ <artifactId>dolphinscheduler-alert-prometheus</artifactId>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler-alert-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertChannel.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertChannel.java
new file mode 100644
index 0000000000..7ca79253fa
--- /dev/null
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertChannel.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.prometheus;
+
+import org.apache.dolphinscheduler.alert.api.AlertChannel;
+import org.apache.dolphinscheduler.alert.api.AlertData;
+import org.apache.dolphinscheduler.alert.api.AlertInfo;
+import org.apache.dolphinscheduler.alert.api.AlertResult;
+
+import java.util.Map;
+
+public final class PrometheusAlertChannel implements AlertChannel {
+
+ @Override
+ public AlertResult process(AlertInfo info) {
+ AlertData alertData = info.getAlertData();
+ Map<String, String> paramsMap = info.getAlertParams();
+ if (null == paramsMap) {
+ return new AlertResult("false", "prometheus alert manager params
is null");
+ }
+ return new PrometheusAlertSender(paramsMap).sendMessage(alertData);
+
+ }
+}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertChannelFactory.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertChannelFactory.java
new file mode 100644
index 0000000000..093b14a2c1
--- /dev/null
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertChannelFactory.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.prometheus;
+
+import org.apache.dolphinscheduler.alert.api.AlertChannel;
+import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
+import org.apache.dolphinscheduler.alert.api.AlertInputTips;
+import org.apache.dolphinscheduler.spi.params.base.PluginParams;
+import org.apache.dolphinscheduler.spi.params.base.Validate;
+import org.apache.dolphinscheduler.spi.params.input.InputParam;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(AlertChannelFactory.class)
+public final class PrometheusAlertChannelFactory implements
AlertChannelFactory {
+
+ @Override
+ public String name() {
+ return "Prometheus AlertManager";
+ }
+
+ @Override
+ public List<PluginParams> params() {
+ InputParam urlParam =
+ InputParam
+
.newBuilder(PrometheusAlertConstants.NAME_ALERT_MANAGER_URL,
+ PrometheusAlertConstants.ALERT_MANAGER_URL)
+ .setPlaceholder(AlertInputTips.URL.getMsg())
+ .addValidate(Validate.newBuilder()
+ .setRequired(true)
+ .build())
+ .build();
+ InputParam annotationParam =
+ InputParam
+
.newBuilder(PrometheusAlertConstants.NAME_ALERT_MANAGER_ANNOTATIONS,
+
PrometheusAlertConstants.ALERT_MANAGER_ANNOTATIONS)
+ .setPlaceholder(AlertInputTips.ANNOTATION.getMsg())
+ .addValidate(Validate.newBuilder()
+ .setRequired(false).build())
+ .build();
+ InputParam generatorUrlParam =
+ InputParam
+
.newBuilder(PrometheusAlertConstants.NAME_GENERATOR_URL,
PrometheusAlertConstants.GENERATOR_URL)
+ .setPlaceholder(AlertInputTips.GENERATOR_URL.getMsg())
+ .addValidate(Validate.newBuilder()
+ .setRequired(false).build())
+ .build();
+
+ return Arrays.asList(urlParam, annotationParam, generatorUrlParam);
+ }
+
+ @Override
+ public AlertChannel create() {
+ return new PrometheusAlertChannel();
+ }
+}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertConstants.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertConstants.java
new file mode 100644
index 0000000000..8e35306fb4
--- /dev/null
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertConstants.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.prometheus;
+
+public class PrometheusAlertConstants {
+
+ static final String ALERT_MANAGER_URL = "$t('url')";
+ static final String NAME_ALERT_MANAGER_URL = "url";
+ static final String ALERT_MANAGER_ANNOTATIONS = "$t('annotations')";
+ static final String NAME_ALERT_MANAGER_ANNOTATIONS = "annotations";
+ static final String ALERT_V2_API_PATH = "/api/v2/alerts";
+ static final String GENERATOR_URL = "$t('generatorURL')";
+ static final String NAME_GENERATOR_URL = "generatorURL";
+ static final String ALERT_SUCCESS = "alert success";
+}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSender.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSender.java
new file mode 100644
index 0000000000..d27745049e
--- /dev/null
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/main/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSender.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.prometheus;
+
+import org.apache.dolphinscheduler.alert.api.AlertData;
+import org.apache.dolphinscheduler.alert.api.AlertResult;
+import org.apache.dolphinscheduler.alert.api.HttpServiceRetryStrategy;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+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.ContentType;
+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.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class PrometheusAlertSender {
+
+ private String url;
+ private String generatorURL;
+ private String annotations;
+
+ public PrometheusAlertSender(Map<String, String> config) {
+ url = config.get(PrometheusAlertConstants.NAME_ALERT_MANAGER_URL);
+ generatorURL = config.get(PrometheusAlertConstants.NAME_GENERATOR_URL);
+ annotations =
config.get(PrometheusAlertConstants.NAME_ALERT_MANAGER_ANNOTATIONS);
+ }
+
+ public AlertResult sendMessage(AlertData alertData) {
+ AlertResult alertResult;
+ try {
+ String resp = sendMsg(alertData);
+ return checkSendAlertManageMsgResult(resp);
+ } catch (Exception e) {
+ String errorMsg = String.format("send prometheus alert manager
alert error, exception: %s", e.getMessage());
+ log.error(errorMsg);
+ alertResult = new AlertResult();
+ alertResult.setStatus("false");
+ alertResult.setMessage(errorMsg);
+ }
+ return alertResult;
+ }
+
+ private String sendMsg(AlertData alertData) throws IOException {
+ String v2Path = String.format("%s%s", this.url,
PrometheusAlertConstants.ALERT_V2_API_PATH);
+ String msg = generateContentJson(alertData);
+ HttpPost httpPost = constructHttpPost(v2Path, msg);
+
+ try (CloseableHttpClient httpClient = getDefaultClient()) {
+ try (CloseableHttpResponse response =
httpClient.execute(httpPost)) {
+ String resp;
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (statusCode == HttpStatus.SC_OK) {
+ resp = PrometheusAlertConstants.ALERT_SUCCESS;
+ log.info("Prometheus alert manager send alert succeed,
title: {} ,content: {}",
+ alertData.getTitle(),
+ alertData.getContent());
+ return resp;
+ }
+
+ HttpEntity entity = response.getEntity();
+ resp = EntityUtils.toString(entity, "utf-8");
+ EntityUtils.consume(entity);
+ log.error(
+ "Prometheus alert manager send alert failed, http
status code: {}, title: {} ,content: {}, resp: {}",
+ statusCode,
+ alertData.getTitle(),
+ alertData.getContent(), resp);
+
+ return resp;
+ }
+ }
+ }
+
+ public AlertResult checkSendAlertManageMsgResult(String resp) {
+ AlertResult alertResult = new AlertResult();
+ alertResult.setStatus("false");
+
+ if (Objects.equals(resp, PrometheusAlertConstants.ALERT_SUCCESS)) {
+ alertResult.setStatus("true");
+ alertResult.setMessage("prometheus alert manager send success");
+ return alertResult;
+ }
+
+ alertResult.setMessage(String.format("prometheus alert manager send
fail, resp is %s", resp));
+ log.info("send prometheus alert manager msg error, resp error");
+ return alertResult;
+ }
+
+ public String generateContentJson(AlertData alertData) {
+ List<HashMap> list = JSONUtils.toList(alertData.getContent(),
HashMap.class);
+ HashMap<String, String> labels = new HashMap<>();
+ if (CollectionUtils.isEmpty(list)) {
+ labels.put("content", alertData.getContent());
+ }
+ for (Map map : list) {
+ for (Map.Entry<String, Object> entry : (Iterable<Map.Entry<String,
Object>>) map.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue().toString();
+ labels.put(key, value);
+ }
+ }
+ labels.put("title", alertData.getTitle());
+
+ Map<String, Object> alert = new HashMap<>();
+ alert.put("labels", labels);
+
+ Map<String, String> annotations = JSONUtils.toMap(this.annotations);
+ if (annotations != null) {
+ alert.put("annotations", annotations);
+ }
+
+ String formattedTime = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date());
+ alert.put("startsAt", formattedTime);
+ alert.put("endsAt", formattedTime);
+
+ if (generatorURL != null && generatorURL.length() != 0) {
+ alert.put("generatorURL", generatorURL);
+ }
+ List<Map<String, Object>> body = new ArrayList<>();
+ body.add(alert);
+ return JSONUtils.toJsonString(body);
+ }
+
+ private static CloseableHttpClient getDefaultClient() {
+ return
HttpClients.custom().setRetryHandler(HttpServiceRetryStrategy.retryStrategy).build();
+ }
+
+ private static HttpPost constructHttpPost(String url, String msg) {
+ HttpPost post = new HttpPost(url);
+ StringEntity entity = new StringEntity(msg,
ContentType.APPLICATION_JSON);
+ post.setEntity(entity);
+ return post;
+ }
+}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/test/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertFactoryTest.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/test/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertFactoryTest.java
new file mode 100644
index 0000000000..ee2db92168
--- /dev/null
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/test/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertFactoryTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.prometheus;
+
+import org.apache.dolphinscheduler.alert.api.AlertChannel;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.spi.params.base.PluginParams;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class PrometheusAlertFactoryTest {
+
+ @Test
+ public void testGetParams() {
+ PrometheusAlertChannelFactory prometheusAlertChannelFactory = new
PrometheusAlertChannelFactory();
+ List<PluginParams> params = prometheusAlertChannelFactory.params();
+ JSONUtils.toJsonString(params);
+ Assertions.assertEquals(3, params.size());
+ }
+
+ @Test
+ public void testCreate() {
+ PrometheusAlertChannelFactory prometheusAlertChannelFactory = new
PrometheusAlertChannelFactory();
+ AlertChannel alertChannel = prometheusAlertChannelFactory.create();
+ Assertions.assertNotNull(alertChannel);
+ }
+}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/test/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSenderTest.java
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/test/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSenderTest.java
new file mode 100644
index 0000000000..2347d97262
--- /dev/null
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-prometheus/src/test/java/org/apache/dolphinscheduler/plugin/alert/prometheus/PrometheusAlertSenderTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.plugin.alert.prometheus;
+
+import org.apache.dolphinscheduler.alert.api.AlertData;
+import org.apache.dolphinscheduler.alert.api.AlertResult;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class PrometheusAlertSenderTest {
+
+ private static Map<String, String> config = new HashMap<>();
+
+ @BeforeEach
+ public void initConfig() {
+ config.put(PrometheusAlertConstants.NAME_ALERT_MANAGER_URL,
"http://127.0.0.1:9093");
+ config.put(PrometheusAlertConstants.NAME_GENERATOR_URL,
"localhost:8080");
+ config.put(PrometheusAlertConstants.NAME_ALERT_MANAGER_ANNOTATIONS,
"{\"annotation1\": \"string\"," +
+ " \"annotation2\": \"string\"}");
+ }
+
+ @AfterEach
+ public void resetConfig() {
+ config = new HashMap<>();
+ }
+
+ @Test
+ public void testSendAlert() {
+ AlertData alertData = new AlertData();
+ alertData.setTitle("[alertManager alert] test title");
+ alertData.setContent("[{\n" +
+ " \"additionalProp1\": \"string\",\n" +
+ " \"additionalProp2\": \"string\",\n" +
+ " }]");
+ PrometheusAlertSender sender = new PrometheusAlertSender(config);
+ AlertResult result = sender.sendMessage(alertData);
+ Assertions.assertEquals("false", result.getStatus());
+ }
+
+ @Test
+ public void testCheckSendAlertManageMsgResult() {
+ PrometheusAlertSender prometheusAlertSender = new
PrometheusAlertSender(config);
+ AlertResult alertResult1 =
prometheusAlertSender.checkSendAlertManageMsgResult("");
+ Assertions.assertFalse(Boolean.parseBoolean(alertResult1.getStatus()));
+ Assertions.assertEquals("prometheus alert manager send fail, resp is
", alertResult1.getMessage());
+ AlertResult alertResult2 =
prometheusAlertSender.checkSendAlertManageMsgResult("alert success");
+ Assertions.assertTrue(Boolean.parseBoolean(alertResult2.getStatus()));
+ Assertions.assertEquals("prometheus alert manager send success",
alertResult2.getMessage());
+ }
+}
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
index 8d9b5d7a73..e60d4e7049 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/pom.xml
@@ -39,6 +39,7 @@
<module>dolphinscheduler-alert-pagerduty</module>
<module>dolphinscheduler-alert-webexteams</module>
<module>dolphinscheduler-alert-telegram</module>
+ <module>dolphinscheduler-alert-prometheus</module>
</modules>
</project>
diff --git a/dolphinscheduler-ui/src/locales/en_US/security.ts
b/dolphinscheduler-ui/src/locales/en_US/security.ts
index d8fe8ec79b..91b9941722 100644
--- a/dolphinscheduler-ui/src/locales/en_US/security.ts
+++ b/dolphinscheduler-ui/src/locales/en_US/security.ts
@@ -269,7 +269,9 @@ export default {
AtUserIds: 'At User Ids',
MsgType: 'Msg Type',
// eslint-disable-next-line quotes
- IsAtAll: "{'@'}All"
+ IsAtAll: "{'@'}All",
+ annotations: 'Annotations',
+ generatorURL: 'GeneratorURL',
},
k8s_namespace: {
create_namespace: 'Create Namespace',
diff --git a/dolphinscheduler-ui/src/locales/zh_CN/security.ts
b/dolphinscheduler-ui/src/locales/zh_CN/security.ts
index 279ef0eb42..86624eb0fc 100644
--- a/dolphinscheduler-ui/src/locales/zh_CN/security.ts
+++ b/dolphinscheduler-ui/src/locales/zh_CN/security.ts
@@ -269,7 +269,9 @@ export default {
AtUserIds: "被{'@'}人的用户ID",
MsgType: '消息类型',
// eslint-disable-next-line quotes
- IsAtAll: "{'@'}所有人"
+ IsAtAll: "{'@'}所有人",
+ annotations: '注释',
+ generatorURL: '生成地址',
},
k8s_namespace: {
create_namespace: '创建命名空间',