From 83fc34d9fbd3703193b0cc3c3cfd93281ef0fd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=A0=A1=E7=82=9C?= Date: Mon, 5 Feb 2024 17:19:15 +0800 Subject: [PATCH 1/2] refactor: auto refresh dingding alert whitelist --- .../agent/service/DingDingService.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java index 29426268b..4c4f49dbc 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java @@ -36,6 +36,8 @@ import javax.annotation.PostConstruct; import java.util.*; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; /** * @author zhangxiaowei6 @@ -99,25 +101,32 @@ public void init() throws Exception { dingCardClient = new com.aliyun.dingtalkcard_1_0.Client(dingConfig); dingOauthClient = new com.aliyun.dingtalkoauth2_1_0.Client(dingConfig); //registerDingDingCallBack(); - //fill in white list - if (!StringUtils.isBlank(whiteListStr)) { - List whiteList = Arrays.asList(whiteListStr.split(",", -1)); - log.info("DingDingService init whiteList is :{}", whiteList); - if (whiteList.size() % 2 != 0) { - log.error("DingDingService sendDingDing whiteList error , because whiteList size is not even"); - return; - } - //fill in map - for (int i = 0; i < whiteList.size(); i = i + 2) { - whiteListMap.put(whiteList.get(i), whiteList.get(i + 1)); - } - } //user type judge if (!dingdingUserType.equals("userId") && !dingdingUserType.equals("unionId")) { log.error("DingDingService.userType not valid, userType: {}",dingdingUserType); //set default value dingdingUserType = "userId"; } + periodicRefreshWhiteList(); + } + + //2m refresh white list + private void periodicRefreshWhiteList() { + new ScheduledThreadPoolExecutor(1).scheduleWithFixedDelay(() -> { + //fill in white list + if (!StringUtils.isBlank(whiteListStr)) { + List whiteList = Arrays.asList(whiteListStr.split(",", -1)); + log.info("DingDingService init whiteList is :{}", whiteList); + if (whiteList.size() % 2 != 0) { + log.error("DingDingService sendDingDing whiteList error , because whiteList size is not even"); + return; + } + //fill in map + for (int i = 0; i < whiteList.size(); i = i + 2) { + whiteListMap.put(whiteList.get(i), whiteList.get(i + 1)); + } + } + }, 0, 120, TimeUnit.SECONDS); } private String getAccessToken() { From 0a57ce3d52373bca3f363217b052d20d60c54939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=A0=A1=E7=82=9C?= Date: Mon, 5 Feb 2024 17:19:55 +0800 Subject: [PATCH 2/2] refactor: auto refresh dingding alert whitelist --- .../xiaomi/youpin/prometheus/agent/service/DingDingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java index 4c4f49dbc..70d2022bc 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/DingDingService.java @@ -110,7 +110,7 @@ public void init() throws Exception { periodicRefreshWhiteList(); } - //2m refresh white list + //2m auto refresh white list private void periodicRefreshWhiteList() { new ScheduledThreadPoolExecutor(1).scheduleWithFixedDelay(() -> { //fill in white list