This is an automated email from the ASF dual-hosted git repository.
yx9o 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 cd60a19ec32 Use inline code instead of yaml config for metrics (#23642)
cd60a19ec32 is described below
commit cd60a19ec3230b7f8d36d832b56b7586a0e02b81
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jan 19 01:22:59 2023 +0800
Use inline code instead of yaml config for metrics (#23642)
* Use inline code instead of yaml config for metrics
* Add MetricCollectorType
---
.../core/advice/RouteResultCountAdvice.java | 15 +++--
.../metrics/core/advice/SQLParseCountAdvice.java | 8 ++-
.../metrics/core/advice/SQLRouteCountAdvice.java | 8 ++-
.../proxy/CommitTransactionsCountAdvice.java | 10 ++-
.../proxy/CurrentConnectionsCountAdvice.java | 12 ++--
.../advice/proxy/ExecuteErrorsCountAdvice.java | 10 ++-
.../proxy/ExecuteLatencyHistogramAdvice.java | 21 +++++-
.../core/advice/proxy/RequestsCountAdvice.java | 10 ++-
.../proxy/RollbackTransactionsCountAdvice.java | 10 ++-
.../core/collector/MetricsCollectorFactory.java | 5 +-
.../core/collector/MetricsCollectorRegistry.java | 11 ++--
...Configuration.java => MetricCollectorType.java} | 20 +++---
.../metrics/core/config/MetricConfiguration.java | 2 +-
.../metrics/core/config/MetricsConfiguration.java | 42 ------------
.../yaml/entity/YamlMetricConfiguration.java | 44 -------------
.../loader/YamlMetricConfigurationsLoader.java | 43 ------------
.../swapper/YamlMetricConfigurationSwapper.java | 53 ---------------
.../swapper/YamlMetricsConfigurationSwapper.java | 48 --------------
.../core/advice/RouteResultCountAdviceTest.java | 16 +++--
.../core/advice/SQLParseCountAdviceTest.java | 35 +++++-----
.../core/advice/SQLRouteCountAdviceTest.java | 19 +++---
.../proxy/CommitTransactionsCountAdviceTest.java | 10 ++-
.../proxy/CurrentConnectionsCountAdviceTest.java | 10 ++-
.../advice/proxy/ExecuteErrorsCountAdviceTest.java | 10 ++-
.../proxy/ExecuteLatencyHistogramAdviceTest.java | 10 ++-
.../core/advice/proxy/RequestsCountAdviceTest.java | 10 ++-
.../proxy/RollbackTransactionsCountAdviceTest.java | 10 ++-
.../core/fixture/FixtureCollectorFactory.java | 3 +-
.../collector/PrometheusCollectorFactory.java | 24 ++-----
.../collector/business/BuildInfoCollector.java | 7 +-
.../business/proxy/ProxyMetaDataInfoCollector.java | 27 ++++----
.../business/proxy/ProxyStateCollector.java | 7 +-
.../META-INF/conf/prometheus-metrics.yaml | 76 ----------------------
.../collector/PrometheusCollectorFactoryTest.java | 39 +++++++++--
.../type/PrometheusCounterCollectorTest.java | 4 +-
.../type/PrometheusGaugeCollectorTest.java | 4 +-
... PrometheusGaugeMetricFamilyCollectorTest.java} | 15 +++--
.../type/PrometheusHistogramCollectorTest.java | 4 +-
.../type/PrometheusSummaryWrapperTest.java | 4 +-
.../META-INF/conf/prometheus-metrics.yaml | 63 ------------------
40 files changed, 267 insertions(+), 512 deletions(-)
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
index 4ae18259aed..9ea89c66f9a 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
@@ -19,22 +19,27 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import java.lang.reflect.Method;
+import java.util.Collections;
/**
* Route result count advice.
*/
public final class RouteResultCountAdvice implements InstanceMethodAdvice {
- private static final String ROUTED_DATA_SOURCES_METRIC_KEY =
"routed_data_sources_total";
+ private final MetricConfiguration routedDataSourcesConfig = new
MetricConfiguration("routed_data_sources_total",
+ MetricCollectorType.COUNTER, "Total count of data source routed",
Collections.singletonList("name"), Collections.emptyMap());
- private static final String ROUTED_TABLES_METRIC_KEY =
"routed_tables_total";
+ private final MetricConfiguration routedTablesConfig = new
MetricConfiguration("routed_tables_total",
+ MetricCollectorType.COUNTER, "Total count of table routed",
Collections.singletonList("name"), Collections.emptyMap());
@Override
public void afterMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final Object result, final String pluginType) {
@@ -43,8 +48,8 @@ public final class RouteResultCountAdvice implements
InstanceMethodAdvice {
}
for (RouteUnit each : ((RouteContext) result).getRouteUnits()) {
RouteMapper dataSourceMapper = each.getDataSourceMapper();
-
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_DATA_SOURCES_METRIC_KEY,
pluginType).inc(dataSourceMapper.getActualName());
- each.getTableMappers().forEach(table ->
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_TABLES_METRIC_KEY,
pluginType).inc(table.getActualName()));
+
MetricsCollectorRegistry.<CounterMetricsCollector>get(routedDataSourcesConfig,
pluginType).inc(dataSourceMapper.getActualName());
+ each.getTableMappers().forEach(table ->
MetricsCollectorRegistry.<CounterMetricsCollector>get(routedTablesConfig,
pluginType).inc(table.getActualName()));
}
}
}
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 bba78ee98ac..7f1016be8b3 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
@@ -21,6 +21,8 @@ import
org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
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;
@@ -36,6 +38,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateState
import
org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.TCLStatement;
import java.lang.reflect.Method;
+import java.util.Collections;
import java.util.Optional;
/**
@@ -43,11 +46,12 @@ import java.util.Optional;
*/
public final class SQLParseCountAdvice implements InstanceMethodAdvice {
- private static final String PARSED_SQL_METRIC_KEY = "parsed_sql_total";
+ private final MetricConfiguration config = new
MetricConfiguration("parsed_sql_total",
+ MetricCollectorType.COUNTER, "Total count of parsed SQL",
Collections.singletonList("type"), Collections.emptyMap());
@Override
public void afterMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final Object result, final String pluginType) {
- getSQLType((SQLStatement) result).ifPresent(optional ->
MetricsCollectorRegistry.<CounterMetricsCollector>get(PARSED_SQL_METRIC_KEY,
pluginType).inc(optional));
+ getSQLType((SQLStatement) result).ifPresent(optional ->
MetricsCollectorRegistry.<CounterMetricsCollector>get(config,
pluginType).inc(optional));
}
private Optional<String> getSQLType(final SQLStatement sqlStatement) {
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
index f146628d6e2..149160cce94 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
@@ -21,6 +21,8 @@ import
org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
@@ -29,6 +31,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectState
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
import java.lang.reflect.Method;
+import java.util.Collections;
import java.util.Optional;
/**
@@ -36,13 +39,14 @@ import java.util.Optional;
*/
public final class SQLRouteCountAdvice implements InstanceMethodAdvice {
- private static final String ROUTED_SQL_METRIC_KEY = "routed_sql_total";
+ private final MetricConfiguration config = new
MetricConfiguration("routed_sql_total",
+ MetricCollectorType.COUNTER, "Total count of routed SQL",
Collections.singletonList("type"), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final String pluginType) {
QueryContext queryContext = (QueryContext) args[1];
SQLStatement sqlStatement =
queryContext.getSqlStatementContext().getSqlStatement();
- getSQLType(sqlStatement).ifPresent(optional ->
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_SQL_METRIC_KEY,
pluginType).inc(optional));
+ getSQLType(sqlStatement).ifPresent(optional ->
MetricsCollectorRegistry.<CounterMetricsCollector>get(config,
pluginType).inc(optional));
}
private Optional<String> getSQLType(final SQLStatement sqlStatement) {
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 cff9aadf4a2..6d7cf4de869 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
@@ -19,20 +19,24 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.lang.reflect.Method;
+import java.util.Collections;
/**
* Commit transactions count advice for ShardingSphere-Proxy.
*/
public final class CommitTransactionsCountAdvice implements
InstanceMethodAdvice {
- private static final String PROXY_COMMIT_TRANSACTIONS_METRIC_KEY =
"proxy_commit_transactions_total";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_commit_transactions_total",
+ MetricCollectorType.COUNTER, "Total commit transactions of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final String pluginType) {
-
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY,
pluginType).inc();
+ MetricsCollectorRegistry.<CounterMetricsCollector>get(config,
pluginType).inc();
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
index d2114c251ce..23ad3da638b 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
@@ -19,26 +19,30 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.lang.reflect.Method;
+import java.util.Collections;
/**
* Current connections count advice for ShardingSphere-Proxy.
*/
public final class CurrentConnectionsCountAdvice implements
InstanceMethodAdvice {
- private static final String PROXY_CURRENT_CONNECTIONS_METRIC_KEY =
"proxy_current_connections";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_current_connections",
+ MetricCollectorType.GAUGE, "Current connections of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final String pluginType) {
switch (method.getName()) {
case "channelActive":
-
MetricsCollectorRegistry.<GaugeMetricsCollector>get(PROXY_CURRENT_CONNECTIONS_METRIC_KEY,
pluginType).inc();
+ MetricsCollectorRegistry.<GaugeMetricsCollector>get(config,
pluginType).inc();
break;
case "channelInactive":
-
MetricsCollectorRegistry.<GaugeMetricsCollector>get(PROXY_CURRENT_CONNECTIONS_METRIC_KEY,
pluginType).dec();
+ MetricsCollectorRegistry.<GaugeMetricsCollector>get(config,
pluginType).dec();
break;
default:
break;
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
index 3d456947e9e..425103378f3 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
@@ -19,20 +19,24 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.lang.reflect.Method;
+import java.util.Collections;
/**
* Execute errors count advice for ShardingSphere-Proxy.
*/
public final class ExecuteErrorsCountAdvice implements InstanceMethodAdvice {
- private static final String PROXY_EXECUTE_ERRORS_METRIC_KEY =
"proxy_execute_errors_total";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_execute_errors_total",
+ MetricCollectorType.COUNTER, "Total execute errors of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
public void afterMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final Object result, final String pluginType) {
-
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_EXECUTE_ERRORS_METRIC_KEY,
pluginType).inc();
+ MetricsCollectorRegistry.<CounterMetricsCollector>get(config,
pluginType).inc();
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
index 4b9931d2e33..ca876f45052 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
@@ -20,20 +20,35 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.plugin.core.recorder.MethodTimeRecorder;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
* Execute latency histogram advance for ShardingSphere-Proxy.
*/
public final class ExecuteLatencyHistogramAdvice implements
InstanceMethodAdvice {
- private static final String PROXY_EXECUTE_LATENCY_MILLIS_METRIC_KEY =
"proxy_execute_latency_millis";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_execute_latency_millis",
+ MetricCollectorType.HISTOGRAM, "Execute latency millis histogram
of ShardingSphere-Proxy", Collections.emptyList(),
Collections.singletonMap("buckets", getBuckets()));
private final MethodTimeRecorder methodTimeRecorder = new
MethodTimeRecorder(ExecuteLatencyHistogramAdvice.class);
+ private static Map<String, Object> getBuckets() {
+ Map<String, Object> result = new HashMap<>(4, 1);
+ result.put("type", "exp");
+ result.put("start", 1);
+ result.put("factor", 2);
+ result.put("count", 13);
+ return result;
+ }
+
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final String pluginType) {
methodTimeRecorder.record(method);
@@ -41,6 +56,6 @@ public final class ExecuteLatencyHistogramAdvice implements
InstanceMethodAdvice
@Override
public void afterMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final Object result, final String pluginType) {
-
MetricsCollectorRegistry.<HistogramMetricsCollector>get(PROXY_EXECUTE_LATENCY_MILLIS_METRIC_KEY,
pluginType).observe(methodTimeRecorder.getElapsedTimeAndClean(method));
+ MetricsCollectorRegistry.<HistogramMetricsCollector>get(config,
pluginType).observe(methodTimeRecorder.getElapsedTimeAndClean(method));
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
index 43f8452cff7..fd5327f59b7 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
@@ -19,20 +19,24 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.lang.reflect.Method;
+import java.util.Collections;
/**
* Requests count advice for ShardingSphere-Proxy.
*/
public final class RequestsCountAdvice implements InstanceMethodAdvice {
- private static final String PROXY_REQUESTS_METRIC_KEY =
"proxy_requests_total";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_requests_total",
+ MetricCollectorType.COUNTER, "Total requests of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final String pluginType) {
-
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_REQUESTS_METRIC_KEY,
pluginType).inc();
+ MetricsCollectorRegistry.<CounterMetricsCollector>get(config,
pluginType).inc();
}
}
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 bd3a7b1dbe9..8cae089d964 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
@@ -19,20 +19,24 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.lang.reflect.Method;
+import java.util.Collections;
/**
* Rollback transactions count advice for ShardingSphere-Proxy.
*/
public final class RollbackTransactionsCountAdvice implements
InstanceMethodAdvice {
- private static final String PROXY_ROLLBACK_TRANSACTIONS_METRIC_KEY =
"proxy_rollback_transactions_total";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_rollback_transactions_total",
+ MetricCollectorType.COUNTER, "Total rollback transactions of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final String pluginType) {
-
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_ROLLBACK_TRANSACTIONS_METRIC_KEY,
pluginType).inc();
+ MetricsCollectorRegistry.<CounterMetricsCollector>get(config,
pluginType).inc();
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
index 7724136a107..06661d88b66 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
import org.apache.shardingsphere.agent.plugin.core.spi.PluginTypedSPI;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
/**
* Metrics collector factory.
@@ -27,8 +28,8 @@ public interface MetricsCollectorFactory extends
PluginTypedSPI {
/**
* Create metrics collector.
*
- * @param id metrics ID
+ * @param metricConfig metrics configuration
* @return metrics collector
*/
- MetricsCollector create(String id);
+ MetricsCollector create(MetricConfiguration metricConfig);
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
index 96d4be07d16..0b70b90ffd1 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
import org.apache.shardingsphere.agent.plugin.core.spi.PluginServiceLoader;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,15 +33,17 @@ public final class MetricsCollectorRegistry {
/**
* Get metrics collector.
*
- * @param id metric ID
+ * @param metricConfig metric configuration
* @param pluginType plugin type
* @param <T> type of metrics collector
* @return metrics collector
* @see <a
href="https://bugs.openjdk.java.net/browse/JDK-8161372">JDK-8161372</a>
*/
@SuppressWarnings("unchecked")
- public static <T extends MetricsCollector> T get(final String id, final
String pluginType) {
- T result = (T) COLLECTORS.get(id);
- return (T) (null == result ? COLLECTORS.computeIfAbsent(id,
PluginServiceLoader.getServiceLoader(MetricsCollectorFactory.class).getService(pluginType)::create)
: result);
+ public static <T extends MetricsCollector> T get(final MetricConfiguration
metricConfig, final String pluginType) {
+ T result = (T) COLLECTORS.get(metricConfig.getId());
+ return (T) (null == result
+ ? COLLECTORS.computeIfAbsent(metricConfig.getId(), key ->
PluginServiceLoader.getServiceLoader(MetricsCollectorFactory.class).getService(pluginType).create(metricConfig))
+ : result);
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/entity/YamlMetricsConfiguration.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricCollectorType.java
similarity index 75%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/entity/YamlMetricsConfiguration.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricCollectorType.java
index 6475c6bc952..0aeb4eff47b 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/entity/YamlMetricsConfiguration.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricCollectorType.java
@@ -15,20 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.entity;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import java.util.Collection;
-import java.util.LinkedList;
+package org.apache.shardingsphere.agent.plugin.metrics.core.config;
/**
- * YAML metrics configuration.
+ * Metric collector type.
*/
-@Getter
-@Setter
-public final class YamlMetricsConfiguration {
+public enum MetricCollectorType {
- private Collection<YamlMetricConfiguration> metrics = new LinkedList<>();
+ COUNTER,
+ GAUGE,
+ HISTOGRAM,
+ SUMMARY,
+ GAUGE_METRIC_FAMILY
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
index 576b2cdba22..16dc85d0f28 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
@@ -32,7 +32,7 @@ public final class MetricConfiguration {
private final String id;
- private final String type;
+ private final MetricCollectorType type;
private final String help;
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricsConfiguration.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricsConfiguration.java
deleted file mode 100644
index fc814166185..00000000000
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricsConfiguration.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.shardingsphere.agent.plugin.metrics.core.config;
-
-import lombok.RequiredArgsConstructor;
-
-import java.util.Collection;
-
-/**
- * Metric configuration.
- */
-@RequiredArgsConstructor
-public final class MetricsConfiguration {
-
- private final Collection<MetricConfiguration> metrics;
-
- /**
- * Get metric configuration.
- *
- * @param id metric ID
- * @return metric configuration
- */
- public MetricConfiguration get(final String id) {
- return metrics.stream()
- .filter(each ->
id.equals(each.getId())).findFirst().orElseThrow(() -> new
IllegalArgumentException(String.format("Can not find ID `%s` from metrics
configuration.", id)));
- }
-}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/entity/YamlMetricConfiguration.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/entity/YamlMetricConfiguration.java
deleted file mode 100644
index 865e552b844..00000000000
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/entity/YamlMetricConfiguration.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.shardingsphere.agent.plugin.metrics.core.config.yaml.entity;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * YAML metric configuration.
- */
-@Getter
-@Setter
-public final class YamlMetricConfiguration {
-
- private String id;
-
- private String type;
-
- private String help;
-
- private List<String> labels = new LinkedList<>();
-
- private Map<String, Object> props = new HashMap<>();
-}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/loader/YamlMetricConfigurationsLoader.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/loader/YamlMetricConfigurationsLoader.java
deleted file mode 100644
index 56ae717ee2d..00000000000
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/loader/YamlMetricConfigurationsLoader.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.shardingsphere.agent.plugin.metrics.core.config.yaml.loader;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.entity.YamlMetricsConfiguration;
-import org.yaml.snakeyaml.Yaml;
-
-import java.io.InputStream;
-
-/**
- * YAML Metric configuration loader.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlMetricConfigurationsLoader {
-
- /**
- * Load advisors configuration.
- *
- * @param inputStream input stream
- * @return loaded advisors configuration
- */
- public static YamlMetricsConfiguration load(final InputStream inputStream)
{
- YamlMetricsConfiguration result = new Yaml().loadAs(inputStream,
YamlMetricsConfiguration.class);
- return null == result ? new YamlMetricsConfiguration() : result;
- }
-}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/swapper/YamlMetricConfigurationSwapper.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/swapper/YamlMetricConfigurationSwapper.java
deleted file mode 100644
index f2d5ec9f584..00000000000
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/swapper/YamlMetricConfigurationSwapper.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.shardingsphere.agent.plugin.metrics.core.config.yaml.swapper;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.entity.YamlMetricConfiguration;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * YAML metric configuration swapper.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlMetricConfigurationSwapper {
-
- /**
- * Swap from YAML metric configuration to metric configuration.
- *
- * @param yamlConfig YAML metric configuration
- * @return metric configuration
- */
- public static MetricConfiguration swap(final YamlMetricConfiguration
yamlConfig) {
- String id = yamlConfig.getId();
- Preconditions.checkArgument(!Strings.isNullOrEmpty(id), "Metric ID can
not be null.");
- String type = yamlConfig.getType();
- Preconditions.checkArgument(!Strings.isNullOrEmpty(type), "Metric type
can not be null.");
- String help = yamlConfig.getHelp();
- List<String> labels = null == yamlConfig.getLabels() ?
Collections.emptyList() : yamlConfig.getLabels();
- Map<String, Object> props = null == yamlConfig.getProps() ?
Collections.emptyMap() : yamlConfig.getProps();
- return new MetricConfiguration(id, type, help, labels, props);
- }
-}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/swapper/YamlMetricsConfigurationSwapper.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/swapper/YamlMetricsConfigurationSwapper.java
deleted file mode 100644
index 9f2c54c5c6e..00000000000
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/yaml/swapper/YamlMetricsConfigurationSwapper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.shardingsphere.agent.plugin.metrics.core.config.yaml.swapper;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricsConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.entity.YamlMetricsConfiguration;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-/**
- * YAML metrics configuration swapper.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlMetricsConfigurationSwapper {
-
- /**
- * Swap from YAML metrics configuration to metrics configuration.
- *
- * @param yamlConfig YAML metrics configuration
- * @return metrics configuration
- */
- public static MetricsConfiguration swap(final YamlMetricsConfiguration
yamlConfig) {
- Collection<MetricConfiguration> metricConfigs = null ==
yamlConfig.getMetrics()
- ? Collections.emptyList()
- :
yamlConfig.getMetrics().stream().map(YamlMetricConfigurationSwapper::swap).collect(Collectors.toList());
- return new MetricsConfiguration(metricConfigs);
- }
-}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
index b5f430d1f25..b71539407cd 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
@@ -34,10 +36,16 @@ import static org.mockito.Mockito.mock;
public final class RouteResultCountAdviceTest {
+ private final MetricConfiguration routedDataSourcesConfig = new
MetricConfiguration("routed_data_sources_total",
+ MetricCollectorType.COUNTER, "Total count of data source routed",
Collections.singletonList("name"), Collections.emptyMap());
+
+ private final MetricConfiguration routedTablesConfig = new
MetricConfiguration("routed_tables_total",
+ MetricCollectorType.COUNTER, "Total count of table routed",
Collections.singletonList("name"), Collections.emptyMap());
+
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_data_sources_total", "FIXTURE")).reset();
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_tables_total", "FIXTURE")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get(routedDataSourcesConfig, "FIXTURE")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get(routedTablesConfig, "FIXTURE")).reset();
}
@Test
@@ -47,9 +55,9 @@ public final class RouteResultCountAdviceTest {
RouteMapper tableMapper = new RouteMapper("t_order", "t_order_0");
routeContext.getRouteUnits().add(new RouteUnit(dataSourceMapper,
Collections.singleton(tableMapper)));
new RouteResultCountAdvice().afterMethod(new MockTargetAdviceObject(),
mock(Method.class), new Object[]{}, routeContext, "FIXTURE");
- MetricsCollectorFixture wrapper =
MetricsCollectorRegistry.get("routed_data_sources_total", "FIXTURE");
+ MetricsCollectorFixture wrapper =
MetricsCollectorRegistry.get(routedDataSourcesConfig, "FIXTURE");
assertThat(wrapper.getValue(), is(1d));
- wrapper = MetricsCollectorRegistry.get("routed_tables_total",
"FIXTURE");
+ wrapper = MetricsCollectorRegistry.get(routedTablesConfig, "FIXTURE");
assertThat(wrapper.getValue(), is(1d));
}
}
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 2a07de649ef..a4c5f720484 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
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.RegisterStorageUnitStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowStorageUnitsStatement;
@@ -45,75 +47,76 @@ import static org.mockito.Mockito.mock;
public final class SQLParseCountAdviceTest {
- private static final String PARSED_SQL_METRIC_KEY = "parsed_sql_total";
+ private final MetricConfiguration config = new
MetricConfiguration("parsed_sql_total",
+ MetricCollectorType.COUNTER, "Total count of parsed SQL",
Collections.singletonList("type"), Collections.emptyMap());
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get(PARSED_SQL_METRIC_KEY, "FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
public void assertParseInsertSQL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLInsertStatement());
+ assertParse(new MySQLInsertStatement());
}
@Test
public void assertParseDeleteSQL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLDeleteStatement());
+ assertParse(new MySQLDeleteStatement());
}
@Test
public void assertParseUpdateSQL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLUpdateStatement());
+ assertParse(new MySQLUpdateStatement());
}
@Test
public void assertParseSelectSQL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLSelectStatement());
+ assertParse(new MySQLSelectStatement());
}
@Test
public void assertParseDDL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLCreateDatabaseStatement());
+ assertParse(new MySQLCreateDatabaseStatement());
}
@Test
public void assertParseDCL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLCreateUserStatement());
+ assertParse(new MySQLCreateUserStatement());
}
@Test
public void assertParseDAL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLShowDatabasesStatement());
+ assertParse(new MySQLShowDatabasesStatement());
}
@Test
public void assertParseTCL() {
- assertParse(PARSED_SQL_METRIC_KEY, new MySQLCommitStatement());
+ assertParse(new MySQLCommitStatement());
}
@Test
public void assertParseRQL() {
- assertParse(PARSED_SQL_METRIC_KEY, new ShowStorageUnitsStatement(new
DatabaseSegment(0, 0, null), null));
+ assertParse(new ShowStorageUnitsStatement(new DatabaseSegment(0, 0,
null), null));
}
@Test
public void assertParseRDL() {
- assertParse(PARSED_SQL_METRIC_KEY, new
RegisterStorageUnitStatement(false, Collections.emptyList()));
+ assertParse(new RegisterStorageUnitStatement(false,
Collections.emptyList()));
}
@Test
public void assertParseRAL() {
- assertParse(PARSED_SQL_METRIC_KEY, new ShowMigrationListStatement());
+ assertParse(new ShowMigrationListStatement());
}
@Test
public void assertParseRUL() {
- assertParse(PARSED_SQL_METRIC_KEY, new FormatStatement("SELECT * FROM
t_order"));
+ assertParse(new FormatStatement("SELECT * FROM t_order"));
}
- private void assertParse(final String metricIds, final SQLStatement
sqlStatement) {
+ private void assertParse(final SQLStatement sqlStatement) {
new SQLParseCountAdvice().afterMethod(new MockTargetAdviceObject(),
mock(Method.class), new Object[]{}, sqlStatement, "FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(metricIds, "FIXTURE")).getValue(), is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1d));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
index 068e0693fe0..9e6ac7142f9 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.apache.shardingsphere.infra.binder.QueryContext;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
@@ -38,41 +40,42 @@ import static org.mockito.Mockito.mock;
public final class SQLRouteCountAdviceTest {
- private static final String ROUTED_SQL_METRIC_KEY = "routed_sql_total";
+ private final MetricConfiguration config = new
MetricConfiguration("routed_sql_total",
+ MetricCollectorType.COUNTER, "Total count of routed SQL",
Collections.singletonList("type"), Collections.emptyMap());
private final SQLRouteCountAdvice advice = new SQLRouteCountAdvice();
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get(ROUTED_SQL_METRIC_KEY, "FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
public void assertInsertRoute() {
QueryContext queryContext = new QueryContext(new
CommonSQLStatementContext<>(new MySQLInsertStatement()), "",
Collections.emptyList());
- assertRoute(ROUTED_SQL_METRIC_KEY, queryContext);
+ assertRoute(queryContext);
}
@Test
public void assertUpdateRoute() {
QueryContext queryContext = new QueryContext(new
CommonSQLStatementContext<>(new MySQLUpdateStatement()), "",
Collections.emptyList());
- assertRoute(ROUTED_SQL_METRIC_KEY, queryContext);
+ assertRoute(queryContext);
}
@Test
public void assertDeleteRoute() {
QueryContext queryContext = new QueryContext(new
CommonSQLStatementContext<>(new MySQLDeleteStatement()), "",
Collections.emptyList());
- assertRoute(ROUTED_SQL_METRIC_KEY, queryContext);
+ assertRoute(queryContext);
}
@Test
public void assertSelectRoute() {
QueryContext queryContext = new QueryContext(new
CommonSQLStatementContext<>(new MySQLSelectStatement()), "",
Collections.emptyList());
- assertRoute(ROUTED_SQL_METRIC_KEY, queryContext);
+ assertRoute(queryContext);
}
- public void assertRoute(final String metricId, final QueryContext
queryContext) {
+ public void assertRoute(final QueryContext queryContext) {
advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class),
new Object[]{new ConnectionContext(), queryContext}, "FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(metricId, "FIXTURE")).getValue(), is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1d));
}
}
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 3d58b48c8a3..34a795a8d4a 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
@@ -19,11 +19,14 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Method;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,18 +34,19 @@ import static org.mockito.Mockito.mock;
public final class CommitTransactionsCountAdviceTest {
- private static final String PROXY_COMMIT_TRANSACTIONS_METRIC_KEY =
"proxy_commit_transactions_total";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_commit_transactions_total",
+ MetricCollectorType.COUNTER, "Total commit transactions of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
private final CommitTransactionsCountAdvice advice = new
CommitTransactionsCountAdvice();
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_commit_transactions_total",
"FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
public void assertMethod() {
advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class),
new Object[]{}, "FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY,
"FIXTURE")).getValue(), is(1D));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1D));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
index 5c2635bdc28..6256e8c88da 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
@@ -19,11 +19,14 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Method;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -32,11 +35,14 @@ import static org.mockito.Mockito.when;
public final class CurrentConnectionsCountAdviceTest {
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_current_connections",
+ MetricCollectorType.GAUGE, "Current connections of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+
private final CurrentConnectionsCountAdvice advice = new
CurrentConnectionsCountAdvice();
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_current_connections", "FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
@@ -45,7 +51,7 @@ public final class CurrentConnectionsCountAdviceTest {
advice.beforeMethod(targetObject, mockMethod("channelActive"), new
Object[]{}, "FIXTURE");
advice.beforeMethod(targetObject, mockMethod("channelActive"), new
Object[]{}, "FIXTURE");
advice.beforeMethod(targetObject, mockMethod("channelInactive"), new
Object[]{}, "FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_current_connections",
"FIXTURE")).getValue(), is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1d));
}
private Method mockMethod(final String methodName) {
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
index 19000e13222..352224310da 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
@@ -19,11 +19,14 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Method;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,15 +34,18 @@ import static org.mockito.Mockito.mock;
public final class ExecuteErrorsCountAdviceTest {
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_execute_errors_total",
+ MetricCollectorType.COUNTER, "Total execute errors of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_errors_total", "FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
public void assertCountExecuteErrors() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
new ExecuteErrorsCountAdvice().afterMethod(targetObject,
mock(Method.class), new Object[]{}, null, "FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_errors_total",
"FIXTURE")).getValue(), is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1d));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
index d40c0098bb0..001f5a5f94d 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
@@ -19,11 +19,14 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Method;
+import java.util.Collections;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -31,9 +34,12 @@ import static org.mockito.Mockito.mock;
public final class ExecuteLatencyHistogramAdviceTest {
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_execute_latency_millis",
+ MetricCollectorType.HISTOGRAM, "Execute latency millis histogram
of ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_latency_millis",
"FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
@@ -44,6 +50,6 @@ public final class ExecuteLatencyHistogramAdviceTest {
advice.beforeMethod(targetObject, method, new Object[]{}, "FIXTURE");
Thread.sleep(500L);
advice.afterMethod(targetObject, method, new Object[]{}, null,
"FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_latency_millis",
"FIXTURE")).getValue(), greaterThanOrEqualTo(500D));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(),
greaterThanOrEqualTo(500D));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
index 152abbf4dd5..ecc1eb0aad0 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
@@ -19,11 +19,14 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Method;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,17 +34,20 @@ import static org.mockito.Mockito.mock;
public final class RequestsCountAdviceTest {
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_requests_total",
+ MetricCollectorType.COUNTER, "Total requests of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+
private final RequestsCountAdvice advice = new RequestsCountAdvice();
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_requests_total", "FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
public void assertCountRequests() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
advice.beforeMethod(targetObject, mock(Method.class), new Object[]{},
"FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_requests_total", "FIXTURE")).getValue(),
is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1d));
}
}
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 e83d8d5d112..c02162a9d65 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
@@ -19,11 +19,14 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Method;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -31,16 +34,19 @@ import static org.mockito.Mockito.mock;
public final class RollbackTransactionsCountAdviceTest {
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_rollback_transactions_total",
+ MetricCollectorType.COUNTER, "Total rollback transactions of
ShardingSphere-Proxy", Collections.emptyList(), Collections.emptyMap());
+
private final RollbackTransactionsCountAdvice advice = new
RollbackTransactionsCountAdvice();
@After
public void reset() {
- ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_rollback_transactions_total",
"FIXTURE")).reset();
+ ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config,
"FIXTURE")).reset();
}
@Test
public void assertMethod() {
advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class),
new Object[]{}, "FIXTURE");
- assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_rollback_transactions_total",
"FIXTURE")).getValue(), is(1D));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(config, "FIXTURE")).getValue(), is(1D));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
index ab964f0c561..ee6b32057c1 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
@@ -19,11 +19,12 @@ package
org.apache.shardingsphere.agent.plugin.metrics.core.fixture;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
public final class FixtureCollectorFactory implements MetricsCollectorFactory {
@Override
- public MetricsCollector create(final String id) {
+ public MetricsCollector create(final MetricConfiguration metricConfig) {
return new MetricsCollectorFixture();
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
index 1d87deed2d2..08c4b62b3d3 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
@@ -20,9 +20,6 @@ package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricsConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.loader.YamlMetricConfigurationsLoader;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.config.yaml.swapper.YamlMetricsConfigurationSwapper;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusCounterCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeMetricFamilyCollector;
@@ -34,25 +31,18 @@ import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.
*/
public final class PrometheusCollectorFactory implements
MetricsCollectorFactory {
- private static final MetricsConfiguration METRICS_CONFIG;
-
- static {
- METRICS_CONFIG =
YamlMetricsConfigurationSwapper.swap(YamlMetricConfigurationsLoader.load(PrometheusCollectorFactory.class.getResourceAsStream("/META-INF/conf/prometheus-metrics.yaml")));
- }
-
@Override
- public MetricsCollector create(final String id) {
- MetricConfiguration metricConfig = METRICS_CONFIG.get(id);
- switch (metricConfig.getType().toUpperCase()) {
- case "COUNTER":
+ public MetricsCollector create(final MetricConfiguration metricConfig) {
+ switch (metricConfig.getType()) {
+ case COUNTER:
return new PrometheusCounterCollector(metricConfig);
- case "GAUGE":
+ case GAUGE:
return new PrometheusGaugeCollector(metricConfig);
- case "HISTOGRAM":
+ case HISTOGRAM:
return new PrometheusHistogramCollector(metricConfig);
- case "SUMMARY":
+ case SUMMARY:
return new PrometheusSummaryCollector(metricConfig);
- case "GAUGE_METRIC_FAMILY":
+ case GAUGE_METRIC_FAMILY:
return new PrometheusGaugeMetricFamilyCollector(metricConfig);
default:
throw new UnsupportedOperationException(String.format("Can not
support type `%s`.", metricConfig.getType()));
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
index 5cceec954bb..7957a0ed102 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
@@ -22,6 +22,8 @@ import io.prometheus.client.GaugeMetricFamily;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.apache.shardingsphere.proxy.Bootstrap;
import java.util.Arrays;
@@ -34,13 +36,14 @@ import java.util.List;
@RequiredArgsConstructor
public final class BuildInfoCollector extends Collector {
- private static final String BUILD_INFO_METRIC_KEY = "build_info";
+ private final MetricConfiguration config = new
MetricConfiguration("build_info",
+ MetricCollectorType.GAUGE_METRIC_FAMILY, "Build information",
Arrays.asList("version", "name"), Collections.emptyMap());
private final boolean isEnhancedForProxy;
@Override
public List<MetricFamilySamples> collect() {
- GaugeMetricFamilyMetricsCollector artifactInfo =
MetricsCollectorRegistry.get(BUILD_INFO_METRIC_KEY, "Prometheus");
+ GaugeMetricFamilyMetricsCollector artifactInfo =
MetricsCollectorRegistry.get(config, "Prometheus");
addMetric(artifactInfo, getClass().getPackage());
if (isEnhancedForProxy) {
addMetric(artifactInfo, Bootstrap.class.getPackage());
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
index 3f22d324b28..4038bce626c 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
@@ -22,6 +22,8 @@ import io.prometheus.client.GaugeMetricFamily;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -43,27 +45,22 @@ import java.util.Optional;
@Slf4j
public final class ProxyMetaDataInfoCollector extends Collector {
- private static final String PROXY_METADATA_INFO_METRIC_KEY =
"proxy_meta_data_info";
-
- private static final String LOGIC_DB_COUNT = "schema_count";
-
- private static final String ACTUAL_DB_COUNT = "database_count";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_meta_data_info",
+ MetricCollectorType.GAUGE_METRIC_FAMILY, "Meta data information of
ShardingSphere-Proxy. schema_count is logic number of databases; database_count
is actual number of databases",
+ Collections.singletonList("name"), Collections.emptyMap());
@Override
public List<MetricFamilySamples> collect() {
List<MetricFamilySamples> result = new LinkedList<>();
- GaugeMetricFamilyMetricsCollector metaDataInfo =
MetricsCollectorRegistry.get(PROXY_METADATA_INFO_METRIC_KEY, "Prometheus");
- if (null != ProxyContext.getInstance().getContextManager()) {
- collectProxy(metaDataInfo);
- result.add((GaugeMetricFamily)
metaDataInfo.getRawMetricFamilyObject());
+ if (null == ProxyContext.getInstance().getContextManager()) {
+ return result;
}
- return result;
- }
-
- private void collectProxy(final GaugeMetricFamilyMetricsCollector
collector) {
+ GaugeMetricFamilyMetricsCollector metaDataInfo =
MetricsCollectorRegistry.get(config, "Prometheus");
MetaDataContexts metaDataContexts =
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- collector.addMetric(Collections.singletonList(LOGIC_DB_COUNT),
metaDataContexts.getMetaData().getDatabases().size());
- collector.addMetric(Collections.singletonList(ACTUAL_DB_COUNT),
getDatabaseNames(metaDataContexts).size());
+ metaDataInfo.addMetric(Collections.singletonList("schema_count"),
metaDataContexts.getMetaData().getDatabases().size());
+ metaDataInfo.addMetric(Collections.singletonList("database_count"),
getDatabaseNames(metaDataContexts).size());
+ result.add((GaugeMetricFamily)
metaDataInfo.getRawMetricFamilyObject());
+ return result;
}
private Collection<String> getDatabaseNames(final MetaDataContexts
metaDataContexts) {
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
index a45e9640279..aa05acce15f 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
@@ -20,6 +20,8 @@ package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.busi
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeMetricFamilyCollector;
import org.apache.shardingsphere.infra.state.StateContext;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -34,7 +36,8 @@ import java.util.Optional;
*/
public final class ProxyStateCollector extends Collector {
- public static final String PROXY_STATE_METRIC_KEY = "proxy_state";
+ private final MetricConfiguration config = new
MetricConfiguration("proxy_state",
+ MetricCollectorType.GAUGE_METRIC_FAMILY, "State of
ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK",
Collections.emptyList(), Collections.emptyMap());
@Override
public List<MetricFamilySamples> collect() {
@@ -46,7 +49,7 @@ public final class ProxyStateCollector extends Collector {
if (!stateContext.isPresent()) {
return result;
}
- PrometheusGaugeMetricFamilyCollector collector =
MetricsCollectorRegistry.get(PROXY_STATE_METRIC_KEY, "Prometheus");
+ PrometheusGaugeMetricFamilyCollector collector =
MetricsCollectorRegistry.get(config, "Prometheus");
collector.addMetric(Collections.emptyList(),
stateContext.get().getCurrentState().ordinal());
result.add((GaugeMetricFamily) collector.getRawMetricFamilyObject());
return result;
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
deleted file mode 100644
index e8fdc771d86..00000000000
---
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# 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.
-#
-
-metrics:
- - id: build_info
- type: GAUGE_METRIC_FAMILY
- help: Build information
- labels:
- - version
- - name
- - id: parsed_sql_total
- type: COUNTER
- help: Total count of parsed by type
- labels:
- - type
- - id: routed_sql_total
- type: COUNTER
- help: Total count of routed by type
- labels:
- - type
- - id: routed_data_sources_total
- type: COUNTER
- labels:
- - name
- help: Total count of data source routed
- - id: routed_tables_total
- type: COUNTER
- help: Total count of table routed
- labels:
- - name
- - id: proxy_meta_data_info
- type: GAUGE_METRIC_FAMILY
- help: Meta data information of ShardingSphere-Proxy. schema_count is logic
number of databases; database_count is actual number of databases
- labels:
- - name
- - id: proxy_state
- type: GAUGE_METRIC_FAMILY
- help: State of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK
- - id: proxy_current_connections
- type: GAUGE
- help: Current connections of ShardingSphere-Proxy
- - id: proxy_requests_total
- type: COUNTER
- help: Total requests of ShardingSphere-Proxy
- - id: proxy_commit_transactions_total
- type: COUNTER
- help: Total commit transactions of ShardingSphere-Proxy
- - id: proxy_rollback_transactions_total
- type: COUNTER
- help: Total rollback transactions of ShardingSphere-Proxy
- - id: proxy_execute_latency_millis
- type: HISTOGRAM
- help: Execute latency millis histogram of ShardingSphere-Proxy
- props:
- buckets:
- type: exp
- start: 1
- factor: 2
- count: 13
- - id: proxy_execute_errors_total
- type: COUNTER
- help: Total execute errors of ShardingSphere-Proxy
\ No newline at end of file
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
index e892bae19b8..e5d1ce86be3 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
@@ -17,24 +17,49 @@
package org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusCounterCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusGaugeMetricFamilyCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusHistogramCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusSummaryCollector;
import org.junit.Test;
+import java.util.Collections;
+
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
public final class PrometheusCollectorFactoryTest {
@Test
- public void assertCreate() {
- PrometheusCollectorFactory factory = new PrometheusCollectorFactory();
- assertThat(factory.create("a"),
instanceOf(PrometheusCounterCollector.class));
- assertThat(factory.create("b"),
instanceOf(PrometheusGaugeCollector.class));
- assertThat(factory.create("c"),
instanceOf(PrometheusHistogramCollector.class));
- assertThat(factory.create("d"),
instanceOf(PrometheusHistogramCollector.class));
- assertThat(factory.create("e"),
instanceOf(PrometheusSummaryCollector.class));
+ public void assertCreateCounterCollector() {
+ MetricConfiguration config = new MetricConfiguration("test_counter",
MetricCollectorType.COUNTER, null, Collections.emptyList(),
Collections.emptyMap());
+ assertThat(new PrometheusCollectorFactory().create(config),
instanceOf(PrometheusCounterCollector.class));
+ }
+
+ @Test
+ public void assertCreateGaugeCollector() {
+ MetricConfiguration config = new MetricConfiguration("test_gauge",
MetricCollectorType.GAUGE, null, Collections.emptyList(),
Collections.emptyMap());
+ assertThat(new PrometheusCollectorFactory().create(config),
instanceOf(PrometheusGaugeCollector.class));
+ }
+
+ @Test
+ public void assertCreateHistogramCollector() {
+ MetricConfiguration config = new MetricConfiguration("test_histogram",
MetricCollectorType.HISTOGRAM, null, Collections.emptyList(),
Collections.emptyMap());
+ assertThat(new PrometheusCollectorFactory().create(config),
instanceOf(PrometheusHistogramCollector.class));
+ }
+
+ @Test
+ public void assertCreateSummaryCollector() {
+ MetricConfiguration config = new MetricConfiguration("test_summary",
MetricCollectorType.SUMMARY, null, Collections.emptyList(),
Collections.emptyMap());
+ assertThat(new PrometheusCollectorFactory().create(config),
instanceOf(PrometheusSummaryCollector.class));
+ }
+
+ @Test
+ public void assertCreateGaugeMetricFamilyCollector() {
+ MetricConfiguration config = new MetricConfiguration("test_summary",
MetricCollectorType.GAUGE_METRIC_FAMILY, null, Collections.emptyList(),
Collections.emptyMap());
+ assertThat(new PrometheusCollectorFactory().create(config),
instanceOf(PrometheusGaugeMetricFamilyCollector.class));
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
index d71a11113f2..8aaf356b2a8 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
@@ -18,6 +18,7 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Counter;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -31,7 +32,8 @@ public final class PrometheusCounterCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- PrometheusCounterCollector collector = new
PrometheusCounterCollector(new MetricConfiguration("foo_counter", "COUNTER",
"foo_help", Collections.emptyList(), Collections.emptyMap()));
+ PrometheusCounterCollector collector = new
PrometheusCounterCollector(new MetricConfiguration("foo_counter",
+ MetricCollectorType.COUNTER, "foo_help",
Collections.emptyList(), Collections.emptyMap()));
collector.inc();
Counter counter = (Counter)
Plugins.getMemberAccessor().get(PrometheusCounterCollector.class.getDeclaredField("counter"),
collector);
assertThat(counter.get(), is(1d));
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
index 6a063bd37e1..387006a17c7 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
@@ -18,6 +18,7 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Gauge;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -31,7 +32,8 @@ public final class PrometheusGaugeCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- PrometheusGaugeCollector collector = new PrometheusGaugeCollector(new
MetricConfiguration("foo_gauge", "GAUGE", "foo_help", Collections.emptyList(),
Collections.emptyMap()));
+ PrometheusGaugeCollector collector = new PrometheusGaugeCollector(new
MetricConfiguration("foo_gauge",
+ MetricCollectorType.GAUGE, "foo_help",
Collections.emptyList(), Collections.emptyMap()));
collector.inc();
Gauge gauge = (Gauge)
Plugins.getMemberAccessor().get(PrometheusGaugeCollector.class.getDeclaredField("gauge"),
collector);
assertThat(gauge.get(), is(1d));
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeMetricFamilyCollectorTest.java
similarity index 61%
copy from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
copy to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeMetricFamilyCollectorTest.java
index d71a11113f2..e36e67874e7 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeMetricFamilyCollectorTest.java
@@ -17,23 +17,24 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
-import io.prometheus.client.Counter;
+import io.prometheus.client.GaugeMetricFamily;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
import java.util.Collections;
-import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-public final class PrometheusCounterCollectorTest {
+public final class PrometheusGaugeMetricFamilyCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- PrometheusCounterCollector collector = new
PrometheusCounterCollector(new MetricConfiguration("foo_counter", "COUNTER",
"foo_help", Collections.emptyList(), Collections.emptyMap()));
- collector.inc();
- Counter counter = (Counter)
Plugins.getMemberAccessor().get(PrometheusCounterCollector.class.getDeclaredField("counter"),
collector);
- assertThat(counter.get(), is(1d));
+ PrometheusGaugeMetricFamilyCollector collector = new
PrometheusGaugeMetricFamilyCollector(new
MetricConfiguration("foo_gauge_metric_family",
+ MetricCollectorType.GAUGE_METRIC_FAMILY, "foo_help",
Collections.emptyList(), Collections.emptyMap()));
+ collector.addMetric(Collections.emptyList(), 1d);
+
assertThat(Plugins.getMemberAccessor().get(PrometheusGaugeMetricFamilyCollector.class.getDeclaredField("gaugeMetricFamily"),
collector), instanceOf(GaugeMetricFamily.class));
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
index 46dcd7b8dc7..39210bc987f 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
@@ -18,6 +18,7 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Histogram;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -31,7 +32,8 @@ public final class PrometheusHistogramCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- PrometheusHistogramCollector collector = new
PrometheusHistogramCollector(new MetricConfiguration("foo_histogram",
"HISTOGRAM", "foo_help", Collections.emptyList(), Collections.emptyMap()));
+ PrometheusHistogramCollector collector = new
PrometheusHistogramCollector(new MetricConfiguration("foo_histogram",
+ MetricCollectorType.HISTOGRAM, "foo_help",
Collections.emptyList(), Collections.emptyMap()));
collector.observe(1);
Histogram histogram = (Histogram)
Plugins.getMemberAccessor().get(PrometheusHistogramCollector.class.getDeclaredField("histogram"),
collector);
assertThat(histogram.collect().size(), is(1));
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
index 13acd71db6b..4a46bec487c 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
@@ -18,6 +18,7 @@
package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Summary;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
import org.junit.Test;
import org.mockito.internal.configuration.plugins.Plugins;
@@ -31,7 +32,8 @@ public final class PrometheusSummaryWrapperTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- PrometheusSummaryCollector collector = new
PrometheusSummaryCollector(new MetricConfiguration("foo_summary", "SUMMARY",
"foo_help", Collections.emptyList(), Collections.emptyMap()));
+ PrometheusSummaryCollector collector = new
PrometheusSummaryCollector(new MetricConfiguration("foo_summary",
+ MetricCollectorType.SUMMARY, "foo_help",
Collections.emptyList(), Collections.emptyMap()));
collector.observe(1);
Summary summary = (Summary)
Plugins.getMemberAccessor().get(PrometheusSummaryCollector.class.getDeclaredField("summary"),
collector);
assertThat(summary.collect().size(), is(1));
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
b/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
deleted file mode 100644
index 1750a9a8fc2..00000000000
---
a/agent/plugins/metrics/type/prometheus/src/test/resources/META-INF/conf/prometheus-metrics.yaml
+++ /dev/null
@@ -1,63 +0,0 @@
-#
-# 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.
-#
-
-metrics:
- - id: a
- type: COUNTER
- help: Total requests of ShardingSphere-Proxy
- - id: b
- type: GAUGE
- help: Current connections of ShardingSphere-Proxy
- - id: c
- type: HISTOGRAM
- help: Executor latency millis of ShardingSphere-Proxy
- labels:
- - name
- props:
- buckets:
- type: exp
- start: 8
- factor: 2
- count: 10
- good:
- - value
- - id: d
- type: HISTOGRAM
- props:
- buckets:
- type: linear
- start: 0
- width: 10
- count: 10
- - id: e
- type: SUMMARY
- help: proxy execute latency mins
- props:
- - id: proxy_state
- type: GAUGE_METRIC_FAMILY
- help: State of ShardingSphere-Proxy
- - id: build_info
- type: GAUGE_METRIC_FAMILY
- help: build information
- labels:
- - version
- - name
- - id: proxy_meta_data_info
- type: GAUGE_METRIC_FAMILY
- help: Meta data information of ShardingSphere-Proxy. schema_count is logic
number of databases; database_count is actual number of databases
- labels:
- - name