From 32fd818e835fa07898ab2cac6262f70afa417ee0 Mon Sep 17 00:00:00 2001 From: kamtohung Date: Sat, 29 Jun 2024 17:17:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[ISSUE=20#428]=20=E9=A3=9E=E4=B9=A6?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6=20=E5=A1=AB=E5=86=99=E4=BA=86username(?= =?UTF-8?q?=E9=9D=9Eopenid=E7=9A=84=E6=83=85=E5=86=B5),=20=E5=8F=91?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E6=B6=88=E6=81=AF=E6=8E=A5=E5=8F=97=E4=BA=BA?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/LarkNotifyConst.java | 2 +- .../dynamictp/core/notifier/DtpLarkNotifier.java | 2 +- .../test/core/notify/AbstractDtpNotifierTest.java | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/dromara/dynamictp/common/constant/LarkNotifyConst.java b/common/src/main/java/org/dromara/dynamictp/common/constant/LarkNotifyConst.java index 9145dac1e..4e9642bf6 100644 --- a/common/src/main/java/org/dromara/dynamictp/common/constant/LarkNotifyConst.java +++ b/common/src/main/java/org/dromara/dynamictp/common/constant/LarkNotifyConst.java @@ -43,7 +43,7 @@ private LarkNotifyConst() { } * lark at format. username * 当配置username时,只能蓝色字体展示@username,被@人无@提醒 */ - public static final String LARK_AT_FORMAT_USERNAME = "%s"; + public static final String LARK_AT_FORMAT_USERNAME = "%s"; /** * lark openid prefix diff --git a/core/src/main/java/org/dromara/dynamictp/core/notifier/DtpLarkNotifier.java b/core/src/main/java/org/dromara/dynamictp/core/notifier/DtpLarkNotifier.java index eca352621..2bac20543 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/notifier/DtpLarkNotifier.java +++ b/core/src/main/java/org/dromara/dynamictp/core/notifier/DtpLarkNotifier.java @@ -70,7 +70,7 @@ protected Pair getColors() { protected String formatReceivers(String receives) { return Arrays.stream(receives.split(",")) .map(r -> StringUtils.startsWith(r, LARK_OPENID_PREFIX) ? - String.format(LARK_AT_FORMAT_OPENID, r) : String.format(LARK_AT_FORMAT_USERNAME, r)) + String.format(LARK_AT_FORMAT_OPENID, r) : String.format(LARK_AT_FORMAT_USERNAME, r, r)) .collect(Collectors.joining(" ")); } } diff --git a/test/test-core/src/test/java/org/dromara/dynamictp/test/core/notify/AbstractDtpNotifierTest.java b/test/test-core/src/test/java/org/dromara/dynamictp/test/core/notify/AbstractDtpNotifierTest.java index 4485603d9..0e8780144 100644 --- a/test/test-core/src/test/java/org/dromara/dynamictp/test/core/notify/AbstractDtpNotifierTest.java +++ b/test/test-core/src/test/java/org/dromara/dynamictp/test/core/notify/AbstractDtpNotifierTest.java @@ -18,6 +18,7 @@ package org.dromara.dynamictp.test.core.notify; import com.google.common.collect.Lists; +import org.dromara.dynamictp.common.notifier.LarkNotifier; import org.dromara.dynamictp.common.spring.ApplicationContextHolder; import org.dromara.dynamictp.common.em.NotifyItemEnum; import org.dromara.dynamictp.common.entity.NotifyItem; @@ -28,6 +29,8 @@ import org.dromara.dynamictp.core.notifier.AbstractDtpNotifier; import org.dromara.dynamictp.core.notifier.DtpDingNotifier; import org.dromara.dynamictp.common.notifier.Notifier; +import org.dromara.dynamictp.core.notifier.DtpLarkNotifier; +import org.dromara.dynamictp.core.notifier.DtpNotifier; import org.dromara.dynamictp.core.notifier.context.AlarmCtx; import org.dromara.dynamictp.core.notifier.context.DtpNotifyCtxHolder; import org.dromara.dynamictp.core.notifier.context.NoticeCtx; @@ -118,4 +121,16 @@ public void testSendAlarmMsg() { public void testGetQueueName2() { Assert.assertEquals(dtpExecutor.getQueueType(), VARIABLE_LINKED_BLOCKING_QUEUE.getName()); } + + @Test + public void testLarkSendChangeMsg() { + DtpNotifier larkNotifier = new DtpLarkNotifier(new LarkNotifier()); + NotifyPlatform notifyPlatform = new NotifyPlatform(); + notifyPlatform.setWebhook(""); + notifyPlatform.setReceivers(""); + TpMainFields oldFields = new TpMainFields(); + List diffs = Lists.newArrayList("corePoolSize"); + DtpNotifyCtxHolder.set(new NoticeCtx(ExecutorWrapper.of(dtpExecutor), new NotifyItem(), oldFields, diffs)); + larkNotifier.sendChangeMsg(notifyPlatform, oldFields, diffs); + } } From a618f357959d4b42cf27991f2efa7ebf3e28649f Mon Sep 17 00:00:00 2001 From: hemingsheng Date: Fri, 12 Jul 2024 11:13:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DJMX=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B3=A8=E5=86=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitor/collector/jmx/JMXCollector.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/JMXCollector.java b/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/JMXCollector.java index 366aab465..a7643b2b7 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/JMXCollector.java +++ b/core/src/main/java/org/dromara/dynamictp/core/monitor/collector/jmx/JMXCollector.java @@ -21,11 +21,14 @@ import org.dromara.dynamictp.common.em.CollectorTypeEnum; import org.dromara.dynamictp.common.entity.ThreadPoolStats; import org.dromara.dynamictp.core.monitor.collector.AbstractCollector; +import org.springframework.beans.BeanUtils; import javax.management.JMException; import javax.management.MBeanServer; import javax.management.ObjectName; import java.lang.management.ManagementFactory; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * ThreadPoolStatsInfo related @@ -37,15 +40,26 @@ public class JMXCollector extends AbstractCollector { public static final String DTP_METRIC_NAME_PREFIX = "dtp.thread.pool"; + /** + * thread pool stats map + */ + private static final Map GAUGE_CACHE = new ConcurrentHashMap<>(); + @Override public void collect(ThreadPoolStats threadPoolStats) { - try { - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); - ObjectName name = new ObjectName(DTP_METRIC_NAME_PREFIX + ":name=" + threadPoolStats.getPoolName()); - ThreadPoolStatsJMX stats = new ThreadPoolStatsJMX(threadPoolStats); - server.registerMBean(stats, name); - } catch (JMException e) { - log.error("collect thread pool stats error", e); + if (GAUGE_CACHE.containsKey(threadPoolStats.getPoolName())) { + ThreadPoolStats poolStats = GAUGE_CACHE.get(threadPoolStats.getPoolName()); + BeanUtils.copyProperties(threadPoolStats, poolStats); + } else { + try { + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + ObjectName name = new ObjectName(DTP_METRIC_NAME_PREFIX + ":name=" + threadPoolStats.getPoolName()); + ThreadPoolStatsJMX stats = new ThreadPoolStatsJMX(threadPoolStats); + server.registerMBean(stats, name); + } catch (JMException e) { + log.error("collect thread pool stats error", e); + } + GAUGE_CACHE.put(threadPoolStats.getPoolName(), threadPoolStats); } }