You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by de...@apache.org on 2023/10/10 01:57:01 UTC

[shenyu-website] branch main updated: add alert notice help en and cn doc (#981)

This is an automated email from the ASF dual-hosted git repository.

dengliming pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shenyu-website.git


The following commit(s) were added to refs/heads/main by this push:
     new e92c52aa1d add alert notice help en and cn doc (#981)
e92c52aa1d is described below

commit e92c52aa1d3926800c52f204e3ae15b28ab73d4a
Author: tomsun28 <to...@outlook.com>
AuthorDate: Tue Oct 10 09:56:54 2023 +0800

    add alert notice help en and cn doc (#981)
    
    * add alert notice help en and cn doc
    
    * update gateway prop config doc
---
 docs/developer/notice-alert.md                     |  83 +++++++++++++++++++++
 .../property-config/gateway-property-config.md     |  26 +++----
 .../current/developer/notice-alert.md              |  83 +++++++++++++++++++++
 .../property-config/gateway-property-config.md     |  12 +++
 static/img/shenyu/alert/alarm-config.png           | Bin 0 -> 298638 bytes
 5 files changed, 190 insertions(+), 14 deletions(-)

diff --git a/docs/developer/notice-alert.md b/docs/developer/notice-alert.md
new file mode 100644
index 0000000000..500b8ed7ec
--- /dev/null
+++ b/docs/developer/notice-alert.md
@@ -0,0 +1,83 @@
+---
+title: Alarm Notice
+keywords: ["alarm"]
+description: Alarm message dispatch and notice
+---
+
+## Description
+
+* This doc gives a brief description for send alarm notice message using `Apache ShenYu API`.
+
+## Enable Alert in ShenYu Gateway
+
+* Config the gateway `application.yml` 
+
+```yaml
+shenyu:
+  alert:
+    enabled: true
+    # the shenyu admin servers, if admin cluster, config like 127.0.0.1:9095,192.3.4.2:9095
+    admins: localhost:9095
+```
+
+## Send Alarm Message 
+
+* We can send custom alarm message in plugin using `AlarmSender.alarm()`
+
+Refer below:
+
+```java
+public class ParamMappingPlugin extends AbstractShenyuPlugin {
+
+    @Override
+    public Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
+        ParamMappingRuleHandle paramMappingRuleHandle = ParamMappingPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
+     
+        if(some condition) {
+             Map<String, String> labels = new HashMap<>(8);
+             labels.put("plugin", "http-redirect");
+             labels.put("component", "http");
+             AlarmSender.alarmHighEmergency("alarm-title", "alarm-content", labels);
+             AlarmSender.alarmMediumCritical("alarm-title", "alarm-content", labels);
+             AlarmSender.alarmLowWarning("alarm-title", "alarm-content", labels);
+             AlarmSender.alarm((byte) 0, "alarm-title", "alarm-content");
+        }
+      
+        HttpHeaders headers = exchange.getRequest().getHeaders();
+        MediaType contentType = headers.getContentType();
+        return match(contentType).apply(exchange, chain, paramMappingRuleHandle);
+    }
+}
+```
+
+## Dispatch Alarm Notice
+
+* In the previous step, we send custom alarm message in plugin. 
+* Now we configure how these messages are sent to whom(tom,lili...) by which type(email,DingDing...)
+* Config this in ShenYu Admin Dashboard.
+
+![alarm-config](/img/shenyu/alert/alarm-config.png)
+
+Have fun!
+
+## Attention
+
+1. If you use the email notice, you should config your email send server in ShenYu Admin `application.yml` 
+
+```yaml
+spring:
+  mail:
+    # Attention: this is mail server address.
+    host: smtp.qq.com
+    username: shenyu@apache.com
+    # Attention: this is not email account password, this requires an email authorization code
+    password: your-password
+    port: 465
+    default-encoding: UTF-8
+    properties:
+      mail:
+        smtp:
+          socketFactoryClass: javax.net.ssl.SSLSocketFactory
+          ssl:
+            enable: true
+```
diff --git a/docs/user-guide/property-config/gateway-property-config.md b/docs/user-guide/property-config/gateway-property-config.md
index 9735019636..d7b90e98de 100644
--- a/docs/user-guide/property-config/gateway-property-config.md
+++ b/docs/user-guide/property-config/gateway-property-config.md
@@ -176,6 +176,9 @@ shenyu:
     paths:
       - /actuator/health
       - /health_check
+  alert:
+    enabled: true
+    admins: localhost:9095
   extPlugin:
     path:
     enabled: true
@@ -261,7 +264,6 @@ shenyu trie match support two match mode, we suggest use `pathPattern` as defaul
 
 when you mark `matchRestful` as true, we suggest mark all cache to `false` to avoid cache conflict.
 
-
 ##### shenyu.NettyTcpProperties config
 
 The apache shenyu reactor-netty config.
@@ -393,7 +395,6 @@ Gateway routing can support routing to http and https back-end services at the s
 | closeNotifyReadTimeout   |   int   |    0    |    No    | SSL close_notify read timeout. Default to 0 ms.              |
 | defaultConfigurationType | String  |   TCP   |    No    | The default ssl configuration type. Defaults to TCP.<br />- H2: SslProvider will be set depending on OpenSsl.isAlpnSupported(), SslProvider.HTTP2_CIPHERS, ALPN support, HTTP/1.1 and HTTP/2 support.<br />- TCP: [`SslProvider`](https://netty.io/4.1/api/io/netty/handler/ssl/SslProvider.html?is-external=true) will be set depending on `OpenSsl.isAvailable()`.<br />- NONE: There will be no default configuration. |
 
-
 ##### Filter Configuration
 
 - `shenyu.file` config
@@ -464,8 +465,6 @@ Local forwarding-related configuration.
 | enabled   | Boolean |  false  |    No    | Whether to enable local forwarding.                          |
 | sha512Key | String  |   ""    |   Yes    | Secret key, according to the secret key to determine whether the need for local forwarding. |
 
-
-
 ##### shenyu.switchConfig config
 
 The apache shenyu switch configuration.
@@ -474,8 +473,6 @@ The apache shenyu switch configuration.
 | :---- | :------ | :-----: | :------: | :----------------------------------------------------------- |
 | local | Boolean |  true   |    No    | Whether to open local mode, if so, local operation data, default open. |
 
-
-
 ##### shenyu.sync config
 
 The apache shenyu gateway and the Admin System use data synchronization configurations.
@@ -554,7 +551,6 @@ The following properties are configured for data synchronization using `consul`
 | waitTime   | int    |  null   |   Yes    | the timeout period for requesting consul service to pull configuration information (milliseconds). |
 |watchDelay | int | null | Yes |Synchronization interval (milliseconds).|
 
-
 ##### shenyu.extPlugin config
 
 The apache shenyu supports dynamic loading of custom plug-ins with the following configuration
@@ -577,7 +573,6 @@ Scheduler config for apache shenyu scheduler thread model.
 | type | String |   fixed  |   False    | fixed Thread Pool or elastic  Scheduler Thread Model. |
 | threads | Integer |    Math.max((Runtime.getRuntime().availableProcessors() << 1) + 1, 16) |   False    | threads for fixed Thread Pool. |
 
-
 ##### shenyu.upstreamCheck config
 
 UpstreamCheck config is the configuration used by  apache shenyu to detect upstream.
@@ -592,8 +587,6 @@ UpstreamCheck config is the configuration used by  apache shenyu to detect upstr
 | printEnabled | Boolean |  true  |    No    | Whether to turn on print logs. |
 | printInterval | Integer |    60000 |   No  | schedule time (ms) for print logs. |
 
-
-
 ##### shenyu.ribbon config
 
 The apache shenyu polling interval configuration.
@@ -602,8 +595,6 @@ The apache shenyu polling interval configuration.
 | :------------------------ | :------ | :-----: | :------: | :----------------------------------------------------------- |
 | serverListRefreshInterval | Integer |  10000  |    No    | Adjust the refresh interval parameter, refer to`com.netflix.client.config.CommonClientConfigKey#ServerListRefreshInterval`. |
 
-
-
 ##### shenyu.metrics config
 
 The apache shenyu metrics config,the gateway is used to monitor its own operational status.
@@ -618,8 +609,6 @@ The apache shenyu metrics config,the gateway is used to monitor its own operat
 | props     |             |    -    |         | No       | properties.                                                  |
 |           | jvm_enabled | Boolean |  Null   | No       | Turn on jvm's monitoring metrics.                            |
 
-
-
 ##### shenyu.sharedPool config
 
 The apache shenyu shared thread pool configuration.
@@ -634,3 +623,12 @@ The apache shenyu shared thread pool configuration.
 | maxWorkQueueMemory | Long    | 80% of the current JVM maximum available memory |    No    |             Maximum memory used (byte).             |
 | maxFreeMemory      | Integer | 无                                              |    No    |          Maximum remaining memory (byte).           |
 
+##### shenyu.alert config
+
+The apache shenyu alert notice configuration.
+
+| Name               | Type    | Default                                         | Required |                    Description                    |
+| :----------------- | ------- |:------------------------------------------------| :------: |:-------------------------------------------------:|
+| enabled            | Boolean | false                                           |    No    |         Whether to enable alarm message.          |
+| admins             | String  | "localhost:9095"                                |    No    | Report alarm message to shenyu admin server list. |
+
diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/developer/notice-alert.md b/i18n/zh/docusaurus-plugin-content-docs/current/developer/notice-alert.md
new file mode 100644
index 0000000000..5ec7aea096
--- /dev/null
+++ b/i18n/zh/docusaurus-plugin-content-docs/current/developer/notice-alert.md
@@ -0,0 +1,83 @@
+---
+title: 告警通知
+keywords: ["alarm"]
+description: Alarm message dispatch and notice
+---
+
+## 说明
+
+* 本文主要介绍 Apache ShenYu 的网关插件发送告警通知消息的支持。
+
+## ShenYu网关开启告警通知  
+
+* 配置 ShenYu网关的配置文件 `application.yml`,开启告警,配置 ShenYu Admin服务地址。 
+
+```yaml
+shenyu:
+  alert:
+    enabled: true
+    # the shenyu admin servers, if admin cluster, config like 127.0.0.1:9095,192.3.4.2:9095
+    admins: localhost:9095
+```
+
+## 发送告警消息
+
+* 在网关插件中使用 `AlarmSender.alarm()` 发送自定义告警消息。
+
+参考如下:
+
+```java
+public class ParamMappingPlugin extends AbstractShenyuPlugin {
+
+    @Override
+    public Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
+        ParamMappingRuleHandle paramMappingRuleHandle = ParamMappingPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
+     
+        if(some condition) {
+             Map<String, String> labels = new HashMap<>(8);
+             labels.put("plugin", "http-redirect");
+             labels.put("component", "http");
+             AlarmSender.alarmHighEmergency("alarm-title", "alarm-content", labels);
+             AlarmSender.alarmMediumCritical("alarm-title", "alarm-content", labels);
+             AlarmSender.alarmLowWarning("alarm-title", "alarm-content", labels);
+             AlarmSender.alarm((byte) 0, "alarm-title", "alarm-content");
+        }
+      
+        HttpHeaders headers = exchange.getRequest().getHeaders();
+        MediaType contentType = headers.getContentType();
+        return match(contentType).apply(exchange, chain, paramMappingRuleHandle);
+    }
+}
+```
+
+## 告警消息转发
+
+* 在上一步中,我们在插件中发送的告警消息。 
+* 现在我们需要配置这些消息发给谁,通过什么渠道发(邮件,钉钉。。。)
+* 在 ShenYu Admin 页面操作配置。
+
+![alarm-config](/img/shenyu/alert/alarm-config.png)
+
+Have fun!
+
+## 注意
+
+1. 若您使用了邮件通知渠道,您需要提前在 ShenYu Admin 的配置文件配置自己的邮件服务器参数 `application.yml` 
+
+```yaml
+spring:
+  mail:
+    # Attention: this is mail server address.
+    host: smtp.qq.com
+    username: shenyu@apache.com
+    # Attention: this is not email account password, this requires an email authorization code
+    password: your-password
+    port: 465
+    default-encoding: UTF-8
+    properties:
+      mail:
+        smtp:
+          socketFactoryClass: javax.net.ssl.SSLSocketFactory
+          ssl:
+            enable: true
+```
diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/user-guide/property-config/gateway-property-config.md b/i18n/zh/docusaurus-plugin-content-docs/current/user-guide/property-config/gateway-property-config.md
index b6ce7edc70..13b103bbe4 100644
--- a/i18n/zh/docusaurus-plugin-content-docs/current/user-guide/property-config/gateway-property-config.md
+++ b/i18n/zh/docusaurus-plugin-content-docs/current/user-guide/property-config/gateway-property-config.md
@@ -176,6 +176,9 @@ shenyu:
     paths:
       - /actuator/health
       - /health_check
+  alert:
+    enabled: true
+    admins: localhost:9095
   extPlugin:
     path:
     enabled: true
@@ -628,3 +631,12 @@ Apache ShenYu Metrics 配置,网关用来监控自身运行状态
 | maxWorkQueueMemory | Long    | 当前JVM最大可用内存的80% |    否    |        最大使用内存,单位字节         |
 | maxFreeMemory      | Integer | 无                                                     |    否    |        最大剩余内存,单位字节         |
 
+##### shenyu.alert 配置
+
+Apache ShenYu 网关告警通知配置  
+
+| Name              | Type    | Default                                                 | Required |     Description     |
+|:------------------| ------- |:--------------------------------------------------------|:--------:|:-------------------:|
+| enabled           | Boolean | false                                                   |    否     |      是否开启告警消息通知     |
+| admins            | String  | "localhost:9095"                                        |    否     | ShenYu Admin 服务地址列表 |
+
diff --git a/static/img/shenyu/alert/alarm-config.png b/static/img/shenyu/alert/alarm-config.png
new file mode 100644
index 0000000000..8b4d896261
Binary files /dev/null and b/static/img/shenyu/alert/alarm-config.png differ