You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/01/17 03:24:19 UTC
[shardingsphere] branch master updated: agent add parsed_rul_total metric (#23585)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 8c58db88d87 agent add parsed_rul_total metric (#23585)
8c58db88d87 is described below
commit 8c58db88d879428ec80d98ae04ff4661d7dde0af
Author: jiangML <10...@qq.com>
AuthorDate: Tue Jan 17 11:24:13 2023 +0800
agent add parsed_rul_total metric (#23585)
* add parsed_rul_total metric
* update doc for parsed_rul_total metric
* add test for parsed_rul_total metric
* fix error
* optimize code
* update doc
---
.../metrics/core/advice/SQLParseCountAdvice.java | 5 ++
.../metrics/core/advice/MetricsAdviceBaseTest.java | 1 +
.../core/advice/SQLParseCountAdviceTest.java | 6 ++
.../collector/proxy/ProxyStateCollector.java | 2 +-
.../wrapper/PrometheusWrapperFactory.java | 17 ++---
.../META-INF/conf/prometheus-metrics.yaml | 3 +
.../observability/_index.cn.md | 77 +++++++++++-----------
.../observability/_index.en.md | 1 +
8 files changed, 61 insertions(+), 51 deletions(-)
diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
index b23441b4437..dd0007942c9 100644
--- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
+++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.RDLStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
+import org.apache.shardingsphere.distsql.parser.statement.rul.RULStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DCLStatement;
@@ -62,6 +63,8 @@ public final class SQLParseCountAdvice implements InstanceMethodAdvice {
private static final String PARSED_RAL_METRIC_KEY = "parsed_ral_total";
+ private static final String PARSED_RUL_METRIC_KEY = "parsed_rul_total";
+
@Override
public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result) {
SQLStatement sqlStatement = (SQLStatement) result;
@@ -96,6 +99,8 @@ public final class SQLParseCountAdvice implements InstanceMethodAdvice {
MetricsWrapperRegistry.get(PARSED_RDL_METRIC_KEY).inc();
} else if (sqlStatement instanceof RALStatement) {
MetricsWrapperRegistry.get(PARSED_RAL_METRIC_KEY).inc();
+ } else if (sqlStatement instanceof RULStatement) {
+ MetricsWrapperRegistry.get(PARSED_RUL_METRIC_KEY).inc();
}
}
}
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
index 7b9cc11ad5e..da96fe3b8e9 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
@@ -43,6 +43,7 @@ public abstract class MetricsAdviceBaseTest {
((FixtureWrapper) MetricsWrapperRegistry.get("parsed_rql_total")).reset();
((FixtureWrapper) MetricsWrapperRegistry.get("parsed_rdl_total")).reset();
((FixtureWrapper) MetricsWrapperRegistry.get("parsed_ral_total")).reset();
+ ((FixtureWrapper) MetricsWrapperRegistry.get("parsed_rul_total")).reset();
((FixtureWrapper) MetricsWrapperRegistry.get("routed_insert_sql_total")).reset();
((FixtureWrapper) MetricsWrapperRegistry.get("routed_update_sql_total")).reset();
((FixtureWrapper) MetricsWrapperRegistry.get("routed_delete_sql_total")).reset();
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
index 6bec1395358..f86a6e1d61a 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapperRegistr
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureWrapper;
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.RegisterStorageUnitStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowStorageUnitsStatement;
+import org.apache.shardingsphere.distsql.parser.statement.rul.sql.FormatStatement;
import org.apache.shardingsphere.migration.distsql.statement.ShowMigrationListStatement;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -98,6 +99,11 @@ public final class SQLParseCountAdviceTest extends MetricsAdviceBaseTest {
assertParse("parsed_ral_total", new ShowMigrationListStatement());
}
+ @Test
+ public void assertParseRUL() {
+ assertParse("parsed_rul_total", new FormatStatement("SELECT * FROM t_order"));
+ }
+
private void assertParse(final String metricIds, final SQLStatement sqlStatement) {
new SQLParseCountAdvice().afterMethod(new MockTargetAdviceObject(), mock(Method.class), new Object[]{}, sqlStatement);
assertThat(((FixtureWrapper) MetricsWrapperRegistry.get(metricIds)).getFixtureValue(), is(1d));
diff --git a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java
index 0650f2ebfe3..92f4eb49000 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java
+++ b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java
@@ -42,7 +42,7 @@ public final class ProxyStateCollector extends Collector {
return result;
}
Optional<StateContext> stateContext = ProxyContext.getInstance().getStateContext();
- stateContext.ifPresent(optional -> result.add(FACTORY.createGaugeMetricFamily(PROXY_STATE_METRIC_KEY, stateContext.get().getCurrentState().ordinal())));
+ stateContext.ifPresent(optional -> result.add(FACTORY.createGaugeMetric(PROXY_STATE_METRIC_KEY, stateContext.get().getCurrentState().ordinal())));
return result;
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactory.java b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactory.java
index 50609e434ce..b2c218f99b3 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactory.java
+++ b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactory.java
@@ -67,13 +67,7 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
}
}
- /**
- * Get metric configuration.
- *
- * @param id metric id
- * @return metric configuration
- */
- public MetricConfiguration getMetricConfiguration(final String id) {
+ private MetricConfiguration getMetricConfiguration(final String id) {
return METRICS_CONFIG.get(id);
}
@@ -149,15 +143,14 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
}
/**
- * Create gauge metric family.
+ * Create gauge metric with value.
*
* @param id metric id
* @param value value
- * @return gauge metric family
+ * @return gauge metric
*/
- public GaugeMetricFamily createGaugeMetricFamily(final String id, final double value) {
+ public GaugeMetricFamily createGaugeMetric(final String id, final double value) {
MetricConfiguration metricConfig = getMetricConfiguration(id);
- List<String> labels = metricConfig.getLabels();
- return labels.isEmpty() ? new GaugeMetricFamily(metricConfig.getId(), metricConfig.getHelp(), value) : new GaugeMetricFamily(metricConfig.getId(), metricConfig.getHelp(), labels);
+ return new GaugeMetricFamily(metricConfig.getId(), metricConfig.getHelp(), value);
}
}
diff --git a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
index 5e0a69b1734..392281704b1 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
+++ b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
@@ -55,6 +55,9 @@ metrics:
- id: parsed_ral_total
type: COUNTER
help: Total count of parsed RAL
+ - id: parsed_rul_total
+ type: COUNTER
+ help: Total count of parsed RUL
- id: routed_insert_sql_total
type: COUNTER
help: Total count of routed INSERT
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 33956e2a923..f22bc251bbe 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
@@ -91,20 +91,20 @@ plugins:
* 参数说明;
| 名称 | 说明 | 取值范围 | 默认值 |
-|:----------------------------------|:--------------------------|:------------------------------------------------------------------------------------------------------------------------|:----------------------------------|
+|:----------------------------------|:-----------------------------|:------------------------------------------------------------------------------------------------------------------------|:----------------------------------|
| jvm-information-collector-enabled | 是否开启 JVM 采集器 | true、false | true |
| service-name | 链路跟踪的服务名称 | 自定义 | shardingsphere |
-| jaeger-sampler-type | Jaeger 采样率类型 | const、probabilistic、ratelimiting、remote | const |
-| jaeger-sampler-param | Jaeger 采样率参数 | const:0、1,probabilistic:0.0 - 1.0,ratelimiting:> 0,自定义每秒采集数量,remote:需要自定义配置远程采样率管理服务地址,JAEGER_SAMPLER_MANAGER_HOST_PORT | 1(const 类型) |
-| jaeger-reporter-flush-interval | Jaeger 上报数据刷新间隔(毫秒) | 自定义 | 1000 |
-| jaeger-reporter-max-queue-size | Jaeger 上报 span 时最大队列大小 | 自定义 | 100 |
+| jaeger-sampler-type | Jaeger 采样率类型 | const、probabilistic、ratelimiting、remote | const |
+| jaeger-sampler-param | Jaeger 采样率参数 | const:0、1,probabilistic:0.0 - 1.0,ratelimiting:> 0,自定义每秒采集数量,remote:需要自定义配置远程采样率管理服务地址,JAEGER_SAMPLER_MANAGER_HOST_PORT | 1(const 类型)|
+| jaeger-reporter-flush-interval | Jaeger 上报数据刷新间隔(毫秒) | 自定义 | 1000 |
+| jaeger-reporter-max-queue-size | Jaeger 上报 span 时最大队列大小 | 自定义 | 100 |
| url-version | Zipkin url 地址 | 自定义 | /api/v2/spans |
| sampler-type | Zipkin 采样率类型 | const、counting、ratelimiting、boundary | const |
-| sampler-param | Zipkin 采样率参数 | const: 0、1,counting:0.01 - 1.0,ratelimiting:> 0,自定义每秒采集数量,boundary: 0.0001 - 1.0 | 1(const 类型) |
-| otel-resource-attributes | opentelemetry 资源属性 | 字符串键值对(,分割) | service.name=shardingsphere-agent |
-| otel-traces-exporter | Tracing expoter | zipkin、jaeger | zipkin |
-| otel-traces-sampler | opentelemetry 采样率类型 | always_on、always_off、traceidratio | always_on |
-| otel-traces-sampler-arg | opentelemetry 采样率参数 | traceidratio:0.0 - 1.0 | 1.0 |
+| sampler-param | Zipkin 采样率参数 | const: 0、1,counting:0.01 - 1.0,ratelimiting:> 0,自定义每秒采集数量,boundary: 0.0001 - 1.0 | 1(const 类型) |
+| otel-resource-attributes | opentelemetry 资源属性 | 字符串键值对(,分割) | service.name=shardingsphere-agent |
+| otel-traces-exporter | Tracing expoter | zipkin、jaeger | zipkin |
+| otel-traces-sampler | opentelemetry 采样率类型 | always_on、always_off、traceidratio | always_on |
+| otel-traces-sampler-arg | opentelemetry 采样率参数 | traceidratio:0.0 - 1.0 | 1.0 |
## ShardingSphere-Proxy 中使用
@@ -154,31 +154,32 @@ services:
## Metrics
-| 指标名称 | 指标类型 | 指标描述 |
-| :-------------------------------- |:--------------------|:-------------------------------------------------------------------------------------|
-| build_info | GAUGE | 构建信息 |
-| parsed_insert_sql_total | COUNTER | INSERT 的解析总数 |
-| parsed_update_sql_total | COUNTER | UPDATE 的解析总数 |
-| parsed_delete_sql_total | COUNTER | DELETE 的解析总数 |
-| parsed_select_sql_total | COUNTER | SELECT 的解析总数 |
-| parsed_ddl_total | COUNTER | DDL 的解析总数 |
-| parsed_dcl_total | COUNTER | DCL 的解析总数 |
-| parsed_dal_total | COUNTER | DAL 的解析总数 |
-| parsed_tcl_total | COUNTER | TCL 的解析总数 |
-| parsed_rql_total | COUNTER | RQL 的解析总数 |
-| parsed_rdl_total | COUNTER | RDL 的解析总数 |
-| parsed_ral_total | COUNTER | RAL 的解析总数 |
-| routed_insert_sql_total | COUNTER | INSERT 的路由总数 |
-| routed_update_sql_total | COUNTER | UPDATE 的路由总数 |
-| routed_delete_sql_total | COUNTER | DELETE 的路由总数 |
-| routed_select_sql_total | COUNTER | SELECT 的路由总数 |
-| routed_data_sources_total | COUNTER | 数据源路由总数 |
-| routed_tables_total | COUNTER | 表路由总数 |
-| proxy_state | GAUGE | ShardingSphere-Proxy 状态信息。0 表示正常状态;1 表示熔断状态;2 锁定状态 |
-| proxy_meta_data_info | GAUGE_METRIC_FAMILY | ShardingSphere-Proxy 元数据信息,schema_count:逻辑库数量, database_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_execute_latency_millis | HISTOGRAM | ShardingSphere-Proxy 的执行耗时毫秒直方图 |
-| proxy_execute_errors_total | COUNTER | ShardingSphere-Proxy 的执行异常总数 |
+| 指标名称 | 指标类型 | 指标描述 |
+| :-------------------------------- |:--------------------|:--------------------------------------------------------------------------|
+| build_info | GAUGE | 构建信息 |
+| parsed_insert_sql_total | COUNTER | INSERT 的解析总数 |
+| parsed_update_sql_total | COUNTER | UPDATE 的解析总数 |
+| parsed_delete_sql_total | COUNTER | DELETE 的解析总数 |
+| parsed_select_sql_total | COUNTER | SELECT 的解析总数 |
+| parsed_ddl_total | COUNTER | DDL 的解析总数 |
+| parsed_dcl_total | COUNTER | DCL 的解析总数 |
+| parsed_dal_total | COUNTER | DAL 的解析总数 |
+| parsed_tcl_total | COUNTER | TCL 的解析总数 |
+| parsed_rql_total | COUNTER | RQL 的解析总数 |
+| parsed_rdl_total | COUNTER | RDL 的解析总数 |
+| parsed_ral_total | COUNTER | RAL 的解析总数 |
+| parsed_rul_total | COUNTER | RUL 的解析总数 |
+| routed_insert_sql_total | COUNTER | INSERT 的路由总数 |
+| routed_update_sql_total | COUNTER | UPDATE 的路由总数 |
+| routed_delete_sql_total | COUNTER | DELETE 的路由总数 |
+| routed_select_sql_total | COUNTER | SELECT 的路由总数 |
+| routed_data_sources_total | COUNTER | 数据源路由总数 |
+| routed_tables_total | COUNTER | 表路由总数 |
+| proxy_state | GAUGE | ShardingSphere-Proxy 状态信息。0 表示正常状态;1 表示熔断状态;2 锁定状态 |
+| proxy_meta_data_info | GAUGE_METRIC_FAMILY | ShardingSphere-Proxy 元数据信息,schema_count:逻辑库数量, database_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_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 787102fdee6..b9320948c08 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
@@ -171,6 +171,7 @@ services:
| parsed_rql_total | COUNTER | Total count of parsed RQL |
| parsed_rdl_total | COUNTER | Total count of parsed RDL |
| parsed_ral_total | COUNTER | Total count of parsed RAL |
+| parsed_rul_total | COUNTER | Total count of parsed RUL |
| routed_insert_sql_total | COUNTER | Total count of routed INSERT |
| routed_update_sql_total | COUNTER | Total count of routed UPDATE |
| routed_delete_sql_total | COUNTER | Total count of routed DELETE |