You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/02/28 11:18:40 UTC
[shardingsphere] branch master updated: optimize the transactions total metrics (#24380)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 98ee5f03015 optimize the transactions total metrics (#24380)
98ee5f03015 is described below
commit 98ee5f03015567f6561f7edbe405c6b0da5b1aa4
Author: jiangML <10...@qq.com>
AuthorDate: Tue Feb 28 19:18:26 2023 +0800
optimize the transactions total metrics (#24380)
* merge proxy_commit_transactions_total, proxy_rollback_transactions_total metrics to proxy_transactions_total
* optimize agent file plugin e2e test
---
.../proxy/CommitTransactionsCountAdvice.java | 6 +++---
.../proxy/RollbackTransactionsCountAdvice.java | 6 +++---
.../proxy/CommitTransactionsCountAdviceTest.java | 4 ++--
.../proxy/RollbackTransactionsCountAdviceTest.java | 4 ++--
.../observability/_index.cn.md | 3 +--
.../observability/_index.en.md | 17 ++++++++--------
.../test/e2e/agent/file/FilePluginE2EIT.java | 2 +-
.../test/e2e/agent/file/asserts/ContentAssert.java | 2 +-
.../cases/proxy_rollback_transactions_total.xml | 23 ----------------------
...ions_total.xml => proxy_transactions_total.xml} | 5 +++--
10 files changed, 24 insertions(+), 48 deletions(-)
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
index 6d7cf4de869..bbde9a20542 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
@@ -32,11 +32,11 @@ import java.util.Collections;
*/
public final class CommitTransactionsCountAdvice implements InstanceMethodAdvice {
- private final MetricConfiguration config = new MetricConfiguration("proxy_commit_transactions_total",
- MetricCollectorType.COUNTER, "Total commit transactions of ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+ private final MetricConfiguration config = new MetricConfiguration("proxy_transactions_total",
+ MetricCollectorType.COUNTER, "Total transactions of ShardingSphere-Proxy", Collections.singletonList("type"), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
- MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc();
+ MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc("commit");
}
}
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
index 8cae089d964..d40a8fa2ba4 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
@@ -32,11 +32,11 @@ import java.util.Collections;
*/
public final class RollbackTransactionsCountAdvice implements InstanceMethodAdvice {
- private final MetricConfiguration config = new MetricConfiguration("proxy_rollback_transactions_total",
- MetricCollectorType.COUNTER, "Total rollback transactions of ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+ private final MetricConfiguration config = new MetricConfiguration("proxy_transactions_total",
+ MetricCollectorType.COUNTER, "Total transactions of ShardingSphere-Proxy", Collections.singletonList("type"), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
- MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc();
+ MetricsCollectorRegistry.<CounterMetricsCollector>get(config, pluginType).inc("rollback");
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
index b008099af29..cd20b79a02e 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
@@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock;
public final class CommitTransactionsCountAdviceTest {
- private final MetricConfiguration config = new MetricConfiguration("proxy_commit_transactions_total", MetricCollectorType.COUNTER, null, Collections.emptyList(), Collections.emptyMap());
+ private final MetricConfiguration config = new MetricConfiguration("proxy_transactions_total", MetricCollectorType.COUNTER, null, Collections.singletonList("type"), Collections.emptyMap());
private final CommitTransactionsCountAdvice advice = new CommitTransactionsCountAdvice();
@@ -46,6 +46,6 @@ public final class CommitTransactionsCountAdviceTest {
@Test
public void assertMethod() {
advice.beforeMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, "FIXTURE");
- assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("1"));
+ assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("commit=1"));
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
index 59c348f4823..c0462b7941d 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
@@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock;
public final class RollbackTransactionsCountAdviceTest {
- private final MetricConfiguration config = new MetricConfiguration("proxy_rollback_transactions_total", MetricCollectorType.COUNTER, null, Collections.emptyList(), Collections.emptyMap());
+ private final MetricConfiguration config = new MetricConfiguration("proxy_transactions_total", MetricCollectorType.COUNTER, null, Collections.singletonList("type"), Collections.emptyMap());
private final RollbackTransactionsCountAdvice advice = new RollbackTransactionsCountAdvice();
@@ -46,6 +46,6 @@ public final class RollbackTransactionsCountAdviceTest {
@Test
public void assertMethod() {
advice.beforeMethod(new TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, "FIXTURE");
- assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("1"));
+ assertThat(MetricsCollectorRegistry.get(config, "FIXTURE").toString(), is("rollback=1"));
}
}
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
index d7ad6ecc1c2..700f09d331d 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
@@ -164,7 +164,6 @@ services:
| proxy_meta_data_info | GAUGE_METRIC_FAMILY | ShardingSphere-Proxy 元数据信息,database_count:逻辑库数量,storage_unit_count:存储节点数量 |
| proxy_current_connections | GAUGE | ShardingSphere-Proxy 的当前连接数 |
| proxy_requests_total | COUNTER | ShardingSphere-Proxy 的接受请求总数 |
-| proxy_commit_transactions_total | COUNTER | ShardingSphere-Proxy 的事务提交总数 |
-| proxy_rollback_transactions_total | COUNTER | ShardingSphere-Proxy 的事务回滚总数 |
+| proxy_transactions_total | COUNTER | ShardingSphere-Proxy 的事务总数,按 commit,rollback 分类 |
| proxy_execute_latency_millis | HISTOGRAM | ShardingSphere-Proxy 的执行耗时毫秒直方图 |
| proxy_execute_errors_total | COUNTER | ShardingSphere-Proxy 的执行异常总数 |
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
index 499a54795cc..0a042dfb9d8 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
@@ -157,17 +157,16 @@ services:
## Metrics
-| Name | Type | Description |
-| :-------------------------------- | :------------------ | :--------------------------------------------------------------------------------------------------------------------------------------- |
-| build_info | GAUGE_METRIC_FAMILY | Build information |
-| parsed_sql_total | COUNTER | Total count of parsed by type (INSERT, UPDATE, DELETE, SELECT, DDL, DCL, DAL, TCL, RQL, RDL, RAL, RUL) |
-| routed_sql_total | COUNTER | Total count of routed by type (INSERT, UPDATE, DELETE, SELECT) |
-| routed_result_total | COUNTER | Total count of routed result (data source routed, table routed) |
-| proxy_state | GAUGE_METRIC_FAMILY | Status information of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK |
+| Name | Type | Description |
+| :-------------------------------- | :------------------ |:------------------------------------------------------------------------------------------------------------------------------------------|
+| build_info | GAUGE_METRIC_FAMILY | Build information |
+| parsed_sql_total | COUNTER | Total count of parsed by type (INSERT, UPDATE, DELETE, SELECT, DDL, DCL, DAL, TCL, RQL, RDL, RAL, RUL) |
+| routed_sql_total | COUNTER | Total count of routed by type (INSERT, UPDATE, DELETE, SELECT) |
+| routed_result_total | COUNTER | Total count of routed result (data source routed, table routed) |
+| proxy_state | GAUGE_METRIC_FAMILY | Status information of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK |
| proxy_meta_data_info | GAUGE_METRIC_FAMILY | Meta data information of ShardingSphere-Proxy. database_count is logic number of databases; storage_unit_count is number of storage units |
| proxy_current_connections | GAUGE | Current connections of ShardingSphere-Proxy |
| proxy_requests_total | COUNTER | Total requests of ShardingSphere-Proxy |
-| proxy_commit_transactions_total | COUNTER | Total commit transactions of ShardingSphere-Proxy |
-| proxy_rollback_transactions_total | COUNTER | Total rollback transactions of ShardingSphere-Proxy |
+| proxy_transactions_total | COUNTER | Total transactions of ShardingSphere-Proxy, classify by commit, rollback |
| proxy_execute_latency_millis | HISTOGRAM | Execute latency millis histogram of ShardingSphere-Proxy |
| proxy_execute_errors_total | COUNTER | Total executor errors of ShardingSphere-Proxy |
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
index 7fd1132d37b..b36e11494e6 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
@@ -42,7 +42,7 @@ public final class FilePluginE2EIT extends BasePluginE2EIT {
private Collection<String> getExpectedLogRegex() {
Collection<String> result = new LinkedList<>();
- result.add("Build meta data contexts finished, cost [1-9]* milliseconds");
+ result.add("Build meta data contexts finished, cost\\s(?=[1-9]+)");
return result;
}
}
diff --git a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
index fa5465de1b4..35a075424e2 100644
--- a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
+++ b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
@@ -38,7 +38,7 @@ public final class ContentAssert {
*/
public static void assertIs(final String expectedLogRegex) {
Collection<String> actualLogLines = LogLoader.getLogLines();
- assertThat(String.format("Actual log is empty"), actualLogLines.size(), greaterThan(0));
+ assertThat("Actual log is empty", actualLogLines.size(), greaterThan(0));
Pattern pattern = Pattern.compile(expectedLogRegex);
Collection<String> expectedLogs = actualLogLines.stream().filter(each -> pattern.matcher(each).find()).collect(Collectors.toList());
assertThat(String.format("The log for the specified regular `%s` does not exist", expectedLogRegex), expectedLogs.size(), greaterThan(0));
diff --git a/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_rollback_transactions_total.xml b/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_rollback_transactions_total.xml
deleted file mode 100644
index c6f063ba9b5..00000000000
--- a/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_rollback_transactions_total.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<integration-test-cases>
- <test-case metric-name="proxy_rollback_transactions_total" metric-type="counter">
- <query-assertion metric="proxy_rollback_transactions_total" query="proxy_rollback_transactions_total{}" />
- </test-case>
-</integration-test-cases>
diff --git a/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_commit_transactions_total.xml b/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_transactions_total.xml
similarity index 75%
rename from test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_commit_transactions_total.xml
rename to test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_transactions_total.xml
index a2f61925237..5ee7a3a3608 100644
--- a/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_commit_transactions_total.xml
+++ b/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/cases/proxy_transactions_total.xml
@@ -17,7 +17,8 @@
-->
<integration-test-cases>
- <test-case metric-name="proxy_commit_transactions_total" metric-type="counter">
- <query-assertion metric="proxy_commit_transactions_total" query="proxy_commit_transactions_total{}" />
+ <test-case metric-name="proxy_transactions_total" metric-type="counter">
+ <query-assertion metric="proxy_transactions_total" query="proxy_transactions_total{type='commit'}" />
+ <query-assertion metric="proxy_transactions_total" query="proxy_transactions_total{type='rollback'}" />
</test-case>
</integration-test-cases>