This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 34f4c1e4fa [type:fix] (logging-tencent): Fixed the issue where Tencent
log configuration was not refreshed correctly after modification. (#6002)
34f4c1e4fa is described below
commit 34f4c1e4fa0b3fb97c5c56d1f84668961311fc94
Author: yqw570994511 <[email protected]>
AuthorDate: Sun Apr 13 16:33:29 2025 +0800
[type:fix] (logging-tencent): Fixed the issue where Tencent log
configuration was not refreshed correctly after modification. (#6002)
Co-authored-by: yuqianwei <qq120405>
Co-authored-by: moremind <[email protected]>
Co-authored-by: aias00 <[email protected]>
---
.../cls/config/TencentLogCollectConfig.java | 5 +-
.../LoggingTencentClsPluginDataHandlerTest.java | 76 +++++++++++++++++++++-
2 files changed, 78 insertions(+), 3 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/config/TencentLogCollectConfig.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/config/TencentLogCollectConfig.java
index 626d49b607..5cc91b2aac 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/config/TencentLogCollectConfig.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/config/TencentLogCollectConfig.java
@@ -427,14 +427,15 @@ public class TencentLogCollectConfig {
&& Objects.equals(getRetries(), that.getRetries())
&& Objects.equals(getMaxReservedAttempts(),
that.getMaxReservedAttempts())
&& Objects.equals(getBaseRetryBackoffMs(),
that.getBaseRetryBackoffMs())
- && Objects.equals(getMaxRetryBackoffMs(),
that.getMaxRetryBackoffMs());
+ && Objects.equals(getMaxRetryBackoffMs(),
that.getMaxRetryBackoffMs())
+ && Objects.equals(getSampleRate(), that.getSampleRate());
}
@Override
public int hashCode() {
return Objects.hash(secretId, secretKey, endpoint, topic,
sendThreadCount, totalSizeInBytes,
maxSendThreadCount, maxBlockSec, maxBatchSize,
maxBatchCount, lingerMs, retries,
- maxReservedAttempts, baseRetryBackoffMs,
maxRetryBackoffMs);
+ maxReservedAttempts, baseRetryBackoffMs,
maxRetryBackoffMs, getSampleRate());
}
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/handler/LoggingTencentClsPluginDataHandlerTest.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/handler/LoggingTencentClsPluginDataHandlerTest.java
index 3f1abca5f4..04cf55e1ce 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/handler/LoggingTencentClsPluginDataHandlerTest.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/handler/LoggingTencentClsPluginDataHandlerTest.java
@@ -19,17 +19,33 @@ package org.apache.shenyu.plugin.tencent.cls.handler;
import org.apache.shenyu.common.dto.PluginData;
import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.common.utils.Singleton;
import org.apache.shenyu.plugin.tencent.cls.client.TencentClsLogCollectClient;
+import org.apache.shenyu.plugin.tencent.cls.config.TencentLogCollectConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import java.lang.reflect.Field;
import java.util.UUID;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
/**
* The Test Case For LoggingTencentClsPluginDataHandler.
*/
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
public class LoggingTencentClsPluginDataHandlerTest {
private LoggingTencentClsPluginDataHandler
loggingTencentClsPluginDataHandler;
@@ -38,7 +54,7 @@ public class LoggingTencentClsPluginDataHandlerTest {
@BeforeEach
public void setUp() {
- this.loggingTencentClsPluginDataHandler = new
LoggingTencentClsPluginDataHandler();
+ this.loggingTencentClsPluginDataHandler = Mockito.spy(new
LoggingTencentClsPluginDataHandler());
pluginData.setEnabled(true);
pluginData.setId(UUID.randomUUID().toString().replace("-", ""));
pluginData.setConfig("{\"topic\":\"shenyu-topic-test\",
\"secretId\":\"test\", \"secretKey\":\"test\", "
@@ -64,4 +80,62 @@ public class LoggingTencentClsPluginDataHandlerTest {
public void testGetAliyunSlsLogCollectClient() {
Assertions.assertEquals(LoggingTencentClsPluginDataHandler.getTencentClsLogCollectClient().getClass(),
TencentClsLogCollectClient.class);
}
+
+ @Test
+ public void testHandlerPluginUpdateSameConfig() {
+ TencentLogCollectConfig.TencentClsLogConfig existingConfig =
createValidConfig();
+ Singleton.INST.single(existingConfig.getClass(), existingConfig);
+
+ PluginData pluginData = createPluginData();
+ pluginData.setConfig(GsonUtils.getGson().toJson(existingConfig));
+
+ loggingTencentClsPluginDataHandler.handlerPlugin(pluginData);
+
+ verify(loggingTencentClsPluginDataHandler,
never()).doRefreshConfig(any());
+ }
+
+ @Test
+ public void testHandlerPluginUpdateDifferentConfig() {
+ TencentLogCollectConfig.TencentClsLogConfig existingConfig =
createValidConfig();
+ Singleton.INST.single(existingConfig.getClass(), existingConfig);
+
+ TencentLogCollectConfig.TencentClsLogConfig updatedConfig =
createValidConfig();
+ updatedConfig.setSampleRate("0.1");
+ PluginData pluginData = createPluginData();
+ pluginData.setConfig(GsonUtils.getGson().toJson(updatedConfig));
+
+
doNothing().when(loggingTencentClsPluginDataHandler).doRefreshConfig(any());
+
+ loggingTencentClsPluginDataHandler.handlerPlugin(pluginData);
+
+ verify(loggingTencentClsPluginDataHandler,
times(1)).doRefreshConfig(any());
+ }
+
+ private PluginData createPluginData() {
+ PluginData pluginData = new PluginData();
+ pluginData.setEnabled(true);
+ pluginData.setId(UUID.randomUUID().toString().replace("-", ""));
+ return pluginData;
+ }
+
+ private TencentLogCollectConfig.TencentClsLogConfig createValidConfig() {
+ TencentLogCollectConfig.TencentClsLogConfig config = new
TencentLogCollectConfig.TencentClsLogConfig();
+ config.setSecretId("test");
+ config.setSecretKey("test");
+ config.setEndpoint("ap-guangzhou.cls.tencentcs.com");
+ config.setTopic("shenyu-topic");
+ config.setSendThreadCount(1);
+ config.setTotalSizeInBytes("1024");
+ config.setMaxSendThreadCount("1");
+ config.setMaxBlockSec("60000");
+ config.setMaxBatchSize("1024");
+ config.setMaxBatchCount("1024");
+ config.setLingerMs("2000");
+ config.setRetries("10");
+ config.setMaxReservedAttempts("10");
+ config.setBaseRetryBackoffMs("100");
+ config.setMaxRetryBackoffMs("50000");
+ config.setSampleRate("1");
+ return config;
+ }
}