This is an automated email from the ASF dual-hosted git repository.
jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new 1e2812ddc0 optimize: remove client id metric (#7484)
1e2812ddc0 is described below
commit 1e2812ddc066404739907bc4f9a17130ee368167
Author: Jingliu <[email protected]>
AuthorDate: Wed Aug 6 14:41:14 2025 +0800
optimize: remove client id metric (#7484)
---
changes/en-us/2.x.md | 1 +
changes/zh-cn/2.x.md | 1 +
.../apache/seata/core/event/RateLimitEvent.java | 18 +-------
.../seata/core/event/RateLimitEventTest.java | 51 ++++++++++++++++++++++
.../java/org/apache/seata/metrics/IdConstants.java | 2 -
.../server/limit/ratelimit/RateLimitInfo.java | 19 +-------
.../server/limit/ratelimit/RateLimiterHandler.java | 5 +--
.../seata/server/metrics/MetricsPublisher.java | 1 -
.../seata/server/metrics/MetricsSubscriber.java | 2 -
.../server/ratelimiter/RateLimitInfoTest.java | 47 ++++++++++++++++++++
.../server/ratelimiter/RateLimiterHandlerTest.java | 28 ++++++++++--
11 files changed, 129 insertions(+), 46 deletions(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 450b2fb421..5c1f38d133 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -34,6 +34,7 @@ Add changes here for all PR submitted to the 2.x branch.
### optimize:
+- [[#7478](https://github.com/apache/incubator-seata/pull/7484)] optimize:
remove client id metric
- [[#7557](https://github.com/seata/seata/pull/7557)] upgrade some npmjs
dependencies
### security:
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index c2537d284f..06f3a4a73e 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -35,6 +35,7 @@
### optimize:
+- [[#7478](https://github.com/apache/incubator-seata/pull/7484)] 删除client id指标
- [[#7557](https://github.com/seata/seata/pull/7557)] 升级 npmjs 依赖
### security:
diff --git a/core/src/main/java/org/apache/seata/core/event/RateLimitEvent.java
b/core/src/main/java/org/apache/seata/core/event/RateLimitEvent.java
index 68f53d94c0..fc09ad5bbe 100644
--- a/core/src/main/java/org/apache/seata/core/event/RateLimitEvent.java
+++ b/core/src/main/java/org/apache/seata/core/event/RateLimitEvent.java
@@ -33,11 +33,6 @@ public class RateLimitEvent implements Event {
*/
private String applicationId;
- /**
- * The Client id.
- */
- private String clientId;
-
/**
* The Server ip address and port.
*/
@@ -67,14 +62,6 @@ public class RateLimitEvent implements Event {
this.applicationId = applicationId;
}
- public String getClientId() {
- return clientId;
- }
-
- public void setClientId(String clientId) {
- this.clientId = clientId;
- }
-
public String getServerIpAddressAndPort() {
return serverIpAddressAndPort;
}
@@ -83,12 +70,10 @@ public class RateLimitEvent implements Event {
this.serverIpAddressAndPort = serverIpAddressAndPort;
}
- public RateLimitEvent(
- String traceId, String limitType, String applicationId, String
clientId, String serverIpAddressAndPort) {
+ public RateLimitEvent(String traceId, String limitType, String
applicationId, String serverIpAddressAndPort) {
this.traceId = traceId;
this.limitType = limitType;
this.applicationId = applicationId;
- this.clientId = clientId;
this.serverIpAddressAndPort = serverIpAddressAndPort;
}
@@ -98,7 +83,6 @@ public class RateLimitEvent implements Event {
+ traceId + '\'' + ", limitType='"
+ limitType + '\'' + ", applicationId='"
+ applicationId + '\'' + ", clientId='"
- + clientId + '\'' + ", serverIpAddressAndPort='"
+ serverIpAddressAndPort + '\'' + '}';
}
}
diff --git
a/core/src/test/java/org/apache/seata/core/event/RateLimitEventTest.java
b/core/src/test/java/org/apache/seata/core/event/RateLimitEventTest.java
new file mode 100644
index 0000000000..07009529b9
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/event/RateLimitEventTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.seata.core.event;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * RateLimitEventTest
+ */
+public class RateLimitEventTest {
+ @Test
+ public void test() {
+ String traceId = "trace123";
+ String limitType = "GlobalBeginFailed";
+ String applicationId = "app123";
+ String serverIpAddressAndPort = "127.0.0.1:8080";
+
+ RateLimitEvent event = new RateLimitEvent(traceId, limitType,
applicationId, serverIpAddressAndPort);
+
+ assertEquals(traceId, event.getTraceId());
+ assertEquals(limitType, event.getLimitType());
+ assertEquals(applicationId, event.getApplicationId());
+ assertEquals(serverIpAddressAndPort,
event.getServerIpAddressAndPort());
+
+ event.setTraceId("newTraceId");
+ event.setLimitType("NewLimitType");
+ event.setApplicationId("newAppId");
+ event.setServerIpAddressAndPort("192.168.1.1:9090");
+
+ assertEquals("newTraceId", event.getTraceId());
+ assertEquals("NewLimitType", event.getLimitType());
+ assertEquals("newAppId", event.getApplicationId());
+ assertEquals("192.168.1.1:9090", event.getServerIpAddressAndPort());
+ }
+}
diff --git
a/metrics/seata-metrics-api/src/main/java/org/apache/seata/metrics/IdConstants.java
b/metrics/seata-metrics-api/src/main/java/org/apache/seata/metrics/IdConstants.java
index 7a67bfa60d..ffd29c5d7c 100644
---
a/metrics/seata-metrics-api/src/main/java/org/apache/seata/metrics/IdConstants.java
+++
b/metrics/seata-metrics-api/src/main/java/org/apache/seata/metrics/IdConstants.java
@@ -85,8 +85,6 @@ public interface IdConstants {
String LIMIT_TYPE_KEY = "limitType";
- String CLIENT_ID_KEY = "clientId";
-
String HOST_AND_PORT = "hostAndPort";
String STATUS_VALUE_COMMIT_RETRYING_KEY = "CommitRetrying";
diff --git
a/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimitInfo.java
b/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimitInfo.java
index ccedaac3e8..3967a07f59 100644
---
a/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimitInfo.java
+++
b/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimitInfo.java
@@ -43,11 +43,6 @@ public class RateLimitInfo {
*/
private String applicationId;
- /**
- * The Client id.
- */
- private String clientId;
-
/**
* The Server ip address and port.
*/
@@ -56,12 +51,11 @@ public class RateLimitInfo {
private RateLimitInfo() {}
public static RateLimitInfo generateRateLimitInfo(
- String applicationId, String type, String clientId, String
serverIpAddressAndPort) {
+ String applicationId, String type, String serverIpAddressAndPort) {
RateLimitInfo rateLimitInfo = new RateLimitInfo();
rateLimitInfo.setTraceId(String.valueOf(UUIDGenerator.generateUUID()));
rateLimitInfo.setLimitType(type);
rateLimitInfo.setApplicationId(applicationId);
- rateLimitInfo.setClientId(clientId);
rateLimitInfo.setServerIpAddressAndPort(serverIpAddressAndPort);
return rateLimitInfo;
}
@@ -90,14 +84,6 @@ public class RateLimitInfo {
this.applicationId = applicationId;
}
- public String getClientId() {
- return clientId;
- }
-
- public void setClientId(String clientId) {
- this.clientId = clientId;
- }
-
public String getServerIpAddressAndPort() {
return serverIpAddressAndPort;
}
@@ -111,8 +97,7 @@ public class RateLimitInfo {
return "RateLimitInfo{" + "traceId='"
+ traceId + '\'' + ", limitType='"
+ limitType + '\'' + ", applicationId='"
- + applicationId + '\'' + ", clientId='"
- + clientId + '\'' + ", serverIpAddressAndPort='"
+ + applicationId + '\'' + ", serverIpAddressAndPort='"
+ serverIpAddressAndPort + '\'' + '}';
}
}
diff --git
a/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimiterHandler.java
b/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimiterHandler.java
index ceb8fda604..60974e6c22 100644
---
a/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimiterHandler.java
+++
b/server/src/main/java/org/apache/seata/server/limit/ratelimit/RateLimiterHandler.java
@@ -81,10 +81,7 @@ public class RateLimiterHandler extends
AbstractTransactionRequestHandler implem
response.setTransactionExceptionCode(TransactionExceptionCode.BeginFailed);
response.setResultCode(ResultCode.Failed);
RateLimitInfo rateLimitInfo =
RateLimitInfo.generateRateLimitInfo(
- context.getApplicationId(),
- RateLimitInfo.GLOBAL_BEGIN_FAILED,
- context.getClientId(),
- XID.getIpAddressAndPort());
+ context.getApplicationId(),
RateLimitInfo.GLOBAL_BEGIN_FAILED, XID.getIpAddressAndPort());
MetricsPublisher.postRateLimitEvent(rateLimitInfo);
response.setMsg(String.format(
"TransactionException[rate limit exception, rate limit
info: %s]", rateLimitInfo));
diff --git
a/server/src/main/java/org/apache/seata/server/metrics/MetricsPublisher.java
b/server/src/main/java/org/apache/seata/server/metrics/MetricsPublisher.java
index f9419e24af..fed18e0b66 100644
--- a/server/src/main/java/org/apache/seata/server/metrics/MetricsPublisher.java
+++ b/server/src/main/java/org/apache/seata/server/metrics/MetricsPublisher.java
@@ -128,7 +128,6 @@ public class MetricsPublisher {
rateLimitInfo.getTraceId(),
rateLimitInfo.getLimitType(),
rateLimitInfo.getApplicationId(),
- rateLimitInfo.getClientId(),
rateLimitInfo.getServerIpAddressAndPort()));
}
}
diff --git
a/server/src/main/java/org/apache/seata/server/metrics/MetricsSubscriber.java
b/server/src/main/java/org/apache/seata/server/metrics/MetricsSubscriber.java
index 0ebadff820..1be4364d22 100644
---
a/server/src/main/java/org/apache/seata/server/metrics/MetricsSubscriber.java
+++
b/server/src/main/java/org/apache/seata/server/metrics/MetricsSubscriber.java
@@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import static org.apache.seata.metrics.IdConstants.APP_ID_KEY;
-import static org.apache.seata.metrics.IdConstants.CLIENT_ID_KEY;
import static org.apache.seata.metrics.IdConstants.GROUP_KEY;
import static org.apache.seata.metrics.IdConstants.HOST_AND_PORT;
import static org.apache.seata.metrics.IdConstants.LIMIT_TYPE_KEY;
@@ -232,7 +231,6 @@ public class MetricsSubscriber {
registry.getSummary(MeterIdConstants.SUMMARY_RATE_LIMIT
.withTag(LIMIT_TYPE_KEY, event.getLimitType())
.withTag(APP_ID_KEY, event.getApplicationId())
- .withTag(CLIENT_ID_KEY, event.getClientId())
.withTag(HOST_AND_PORT,
event.getServerIpAddressAndPort()))
.increase(1);
}
diff --git
a/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimitInfoTest.java
b/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimitInfoTest.java
new file mode 100644
index 0000000000..f0b13bad19
--- /dev/null
+++
b/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimitInfoTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.seata.server.ratelimiter;
+
+import org.apache.seata.server.limit.ratelimit.RateLimitInfo;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ *
+ */
+public class RateLimitInfoTest {
+
+ @Test
+ void testGenerateRateLimitInfo() {
+ // Mock输入数据
+ String applicationId = "testApp";
+ String type = "globalBeginFailed";
+ String serverIpAddressAndPort = "127.0.0.1:8080";
+
+ // 调用生成方法
+ RateLimitInfo rateLimitInfo =
RateLimitInfo.generateRateLimitInfo(applicationId, type,
serverIpAddressAndPort);
+
+ // 验证生成的对象
+ assertNotNull(rateLimitInfo);
+ assertNotNull(rateLimitInfo.getTraceId());
+ assertEquals(type, rateLimitInfo.getLimitType());
+ assertEquals(applicationId, rateLimitInfo.getApplicationId());
+ assertEquals(serverIpAddressAndPort,
rateLimitInfo.getServerIpAddressAndPort());
+ }
+}
diff --git
a/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimiterHandlerTest.java
b/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimiterHandlerTest.java
index 4c02aff9d0..a5e7a02366 100644
---
a/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimiterHandlerTest.java
+++
b/server/src/test/java/org/apache/seata/server/ratelimiter/RateLimiterHandlerTest.java
@@ -21,6 +21,7 @@ import org.apache.seata.core.rpc.RpcContext;
import org.apache.seata.server.DynamicPortTestConfig;
import org.apache.seata.server.limit.ratelimit.RateLimiter;
import org.apache.seata.server.limit.ratelimit.RateLimiterHandler;
+import org.apache.seata.server.limit.ratelimit.RateLimiterHandlerConfig;
import org.apache.seata.server.limit.ratelimit.TokenBucketLimiter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -55,11 +56,32 @@ public class RateLimiterHandlerTest {
@Test
public void testHandleNotPass() {
- RateLimiter rateLimiter = new TokenBucketLimiter(true, 1, 1, 0);
+ RateLimiter rateLimiter = new RateLimiter() {
+ @Override
+ public boolean canPass() {
+ return false;
+ }
+
+ @Override
+ public void reInit(RateLimiterHandlerConfig config) {
+ LOGGER.info("Static anonymous RateLimiter reInit called, but
it always fails.");
+ }
+
+ @Override
+ public RateLimiterHandlerConfig obtainConfig() {
+ RateLimiterHandlerConfig config = new
RateLimiterHandlerConfig();
+ config.setEnable(false);
+ return config;
+ }
+
+ @Override
+ public boolean isEnable() {
+ return true;
+ }
+ };
rateLimiterHandler = new RateLimiterHandler(rateLimiter);
GlobalBeginRequest request = new GlobalBeginRequest();
RpcContext rpcContext = new RpcContext();
- Assertions.assertThrowsExactly(
- NullPointerException.class, () ->
rateLimiterHandler.handle(request, rpcContext));
+ Assertions.assertDoesNotThrow(() -> rateLimiterHandler.handle(request,
rpcContext));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]