This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 669f7e26449 Rename MetricsCollectorFixture (#23617)
669f7e26449 is described below
commit 669f7e2644908933b22ab3eff763a5cf1e5dbdd9
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jan 17 22:32:22 2023 +0800
Rename MetricsCollectorFixture (#23617)
---
.../core/advice/RouteResultCountAdvice.java | 4 +-
.../metrics/core/advice/SQLParseCountAdvice.java | 4 +-
.../metrics/core/advice/SQLRouteCountAdvice.java | 4 +-
.../proxy/CommitTransactionsCountAdvice.java | 4 +-
.../proxy/CurrentConnectionsCountAdvice.java | 4 +-
.../advice/proxy/ExecuteErrorsCountAdvice.java | 4 +-
.../proxy/ExecuteLatencyHistogramAdvice.java | 4 +-
.../core/advice/proxy/RequestsCountAdvice.java | 4 +-
.../proxy/RollbackTransactionsCountAdvice.java | 4 +-
.../{wrapper => collector}/MetricsCollector.java | 2 +-
.../MetricsCollectorFactory.java | 2 +-
.../MetricsCollectorRegistry.java | 8 +-
.../type/CounterMetricsCollector.java | 4 +-
.../type/GaugeMetricsCollector.java | 4 +-
.../type/HistogramMetricsCollector.java | 4 +-
.../type/SummaryMetricsCollector.java | 4 +-
.../metrics/core/MetricsCollectorRegistryTest.java | 6 +-
.../plugin/metrics/core/MetricsCollectorTest.java | 44 ------
.../metrics/core/advice/MetricsAdviceBaseTest.java | 2 +-
.../core/advice/RouteResultCountAdviceTest.java | 14 +-
.../core/advice/SQLParseCountAdviceTest.java | 30 ++--
.../core/advice/SQLRouteCountAdviceTest.java | 14 +-
.../proxy/CommitTransactionsCountAdviceTest.java | 8 +-
.../proxy/CurrentConnectionsCountAdviceTest.java | 8 +-
.../advice/proxy/ExecuteErrorsCountAdviceTest.java | 8 +-
.../proxy/ExecuteLatencyHistogramAdviceTest.java | 8 +-
.../core/advice/proxy/RequestsCountAdviceTest.java | 8 +-
.../proxy/RollbackTransactionsCountAdviceTest.java | 8 +-
.../core/fixture/FixtureCollectorFactory.java | 6 +-
...Collector.java => MetricsCollectorFixture.java} | 27 ++--
.../PrometheusPluginLifecycleService.java | 10 +-
.../collector/PrometheusCollectorFactory.java | 92 ++++++++++++
.../{ => business}/BuildInfoCollector.java | 4 +-
.../proxy/ProxyMetaDataInfoCollector.java | 4 +-
.../{ => business}/proxy/ProxyStateCollector.java | 4 +-
.../type/PrometheusCounterCollector.java | 11 +-
.../type/PrometheusGaugeCollector.java | 11 +-
.../type/PrometheusHistogramCollector.java | 63 +++++++++
.../type/PrometheusSummaryCollector.java | 11 +-
.../wrapper/PrometheusCollectorFactory.java | 156 ---------------------
.../wrapper/type/PrometheusHistogramCollector.java | 36 -----
.../PrometheusCollectorFactoryTest.java} | 12 +-
.../{ => business}/BuildInfoCollectorTest.java | 2 +-
.../proxy/ProxyMetaDataInfoCollectorTest.java | 2 +-
.../proxy/ProxyStateCollectorTest.java | 2 +-
.../type/PrometheusCounterCollectorTest.java} | 14 +-
.../type/PrometheusGaugeCollectorTest.java} | 16 ++-
.../type/PrometheusHistogramCollectorTest.java} | 14 +-
.../type/PrometheusSummaryWrapperTest.java | 11 +-
49 files changed, 333 insertions(+), 397 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 8c589ab3cec..dbc83bae331 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,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+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.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
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 290f692320a..bd9bc63e9f7 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
@@ -19,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+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.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.RDLStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
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 24ec981e0b5..88add124e2f 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
@@ -19,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+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.infra.binder.QueryContext;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
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 a71e8d27951..61adb4aaee4 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,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import java.lang.reflect.Method;
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 15fbd4ba91c..883c11a90e3 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,8 +19,8 @@ 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.wrapper.type.GaugeMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import java.lang.reflect.Method;
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 b3d2e200ed6..61cb73a6b6d 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,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import java.lang.reflect.Method;
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 00fe8e9f9ad..4a09f47c16b 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,8 +20,8 @@ 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.wrapper.type.HistogramMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import java.lang.reflect.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 0c779f41d15..19fe44fe745 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,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import java.lang.reflect.Method;
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 c02da86c462..2dd4d291c1e 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,8 +19,8 @@ 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.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import java.lang.reflect.Method;
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollector.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollector.java
similarity index 92%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollector.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollector.java
index 23765f7a13c..07003fbfe35 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollector.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollector.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
/**
* Metrics collector.
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollectorFactory.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
similarity index 93%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollectorFactory.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
index 3e835ac0610..cee359112ca 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollectorFactory.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
/**
* Metrics collector factory.
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollectorRegistry.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
similarity index 86%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollectorRegistry.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
index d2550910648..7ff4b1c2051 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/MetricsCollectorRegistry.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -27,7 +27,7 @@ public final class MetricsCollectorRegistry {
private static final Map<String, MetricsCollector> METRICS_WRAPPERS = new
ConcurrentHashMap<>();
- private static MetricsCollectorFactory metricsCollectorFactory;
+ private static MetricsCollectorFactory factory;
/**
* Set metrics collector factory.
@@ -35,7 +35,7 @@ public final class MetricsCollectorRegistry {
* @param metricsCollectorFactory metrics collector factory
*/
public static void setMetricsFactory(final MetricsCollectorFactory
metricsCollectorFactory) {
- MetricsCollectorRegistry.metricsCollectorFactory =
metricsCollectorFactory;
+ MetricsCollectorRegistry.factory = metricsCollectorFactory;
}
/**
@@ -49,6 +49,6 @@ public final class MetricsCollectorRegistry {
@SuppressWarnings("unchecked")
public static <T extends MetricsCollector> T get(final String id) {
T result = (T) METRICS_WRAPPERS.get(id);
- return (T) (null == result ? METRICS_WRAPPERS.computeIfAbsent(id,
metricsCollectorFactory::create) : result);
+ return (T) (null == result ? METRICS_WRAPPERS.computeIfAbsent(id,
factory::create) : result);
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/CounterMetricsCollector.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/CounterMetricsCollector.java
similarity index 87%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/CounterMetricsCollector.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/CounterMetricsCollector.java
index 2d620a6c499..582aaf4a91f 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/CounterMetricsCollector.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/CounterMetricsCollector.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector.type;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
/**
* Counter metrics collector.
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/GaugeMetricsCollector.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/GaugeMetricsCollector.java
similarity index 88%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/GaugeMetricsCollector.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/GaugeMetricsCollector.java
index 39152bbb7fc..05915333d6f 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/GaugeMetricsCollector.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/GaugeMetricsCollector.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector.type;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
/**
* Gauge metrics collector.
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/HistogramMetricsCollector.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/HistogramMetricsCollector.java
similarity index 86%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/HistogramMetricsCollector.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/HistogramMetricsCollector.java
index 8d20789ccb0..9c9c5376383 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/HistogramMetricsCollector.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/HistogramMetricsCollector.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector.type;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
/**
* Histogram metrics collector.
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/SummaryMetricsCollector.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/SummaryMetricsCollector.java
similarity index 86%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/SummaryMetricsCollector.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/SummaryMetricsCollector.java
index 5c3c5e9365e..24b7b62c2c1 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/wrapper/type/SummaryMetricsCollector.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/type/SummaryMetricsCollector.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type;
+package org.apache.shardingsphere.agent.plugin.metrics.core.collector.type;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
/**
* Summary metrics collector.
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
index 0f3103439bf..af1d6fa151b 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.agent.plugin.metrics.core;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureCollectorFactory;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -30,6 +30,6 @@ public final class MetricsCollectorRegistryTest {
@Test
public void assertGet() {
MetricsCollectorRegistry.setMetricsFactory(new
FixtureCollectorFactory());
- assertThat(MetricsCollectorRegistry.get("test"),
instanceOf(FixtureMetricsCollector.class));
+ assertThat(MetricsCollectorRegistry.get("test"),
instanceOf(MetricsCollectorFixture.class));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorTest.java
deleted file mode 100644
index 45090e495e3..00000000000
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorTest.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;
-
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class MetricsCollectorTest {
-
- @Test
- public void assertCreate() {
- FixtureMetricsCollector fixtureMetricsCollector = new
FixtureMetricsCollector();
- fixtureMetricsCollector.inc();
- assertThat(fixtureMetricsCollector.getFixtureValue(), is(1d));
- fixtureMetricsCollector.inc("a");
- assertThat(fixtureMetricsCollector.getFixtureValue(), is(2d));
- fixtureMetricsCollector.dec();
- assertThat(fixtureMetricsCollector.getFixtureValue(), is(1d));
- fixtureMetricsCollector.dec("c");
- assertThat(fixtureMetricsCollector.getFixtureValue(), is(0d));
- fixtureMetricsCollector.observe(2);
- assertThat(fixtureMetricsCollector.getFixtureValue(), is(2.0d));
- fixtureMetricsCollector.observe(3);
- assertThat(fixtureMetricsCollector.getFixtureValue(), is(3.0d));
- }
-}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
index 8bd25145850..8c40856f160 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureCollectorFactory;
import org.junit.BeforeClass;
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 8632b748120..29a58f09115 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
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+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;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
@@ -36,8 +36,8 @@ public final class RouteResultCountAdviceTest extends
MetricsAdviceBaseTest {
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("routed_data_sources_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("routed_tables_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_data_sources_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_tables_total")).reset();
}
@Test
@@ -47,9 +47,9 @@ public final class RouteResultCountAdviceTest extends
MetricsAdviceBaseTest {
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);
- FixtureMetricsCollector wrapper =
MetricsCollectorRegistry.get("routed_data_sources_total");
- assertThat(wrapper.getFixtureValue(), is(1d));
+ MetricsCollectorFixture wrapper =
MetricsCollectorRegistry.get("routed_data_sources_total");
+ assertThat(wrapper.getValue(), is(1d));
wrapper = MetricsCollectorRegistry.get("routed_tables_total");
- assertThat(wrapper.getFixtureValue(), is(1d));
+ 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 44c4a076370..7629142874f 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
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+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;
import
org.apache.shardingsphere.distsql.parser.statement.rul.sql.FormatStatement;
@@ -47,18 +47,18 @@ public final class SQLParseCountAdviceTest extends
MetricsAdviceBaseTest {
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_insert_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_update_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_delete_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_select_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_ddl_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_dcl_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_dal_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_tcl_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_rql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_rdl_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_ral_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("parsed_rul_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_insert_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_update_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_delete_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_select_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_ddl_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_dcl_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_dal_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_tcl_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_rql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_rdl_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_ral_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("parsed_rul_total")).reset();
}
@Test
@@ -123,6 +123,6 @@ public final class SQLParseCountAdviceTest extends
MetricsAdviceBaseTest {
private void assertParse(final String metricIds, final SQLStatement
sqlStatement) {
new SQLParseCountAdvice().afterMethod(new MockTargetAdviceObject(),
mock(Method.class), new Object[]{}, sqlStatement);
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get(metricIds)).getFixtureValue(), is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(metricIds)).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 9b6b5924ab0..2f81a28f7d8 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
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+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;
import org.apache.shardingsphere.infra.context.ConnectionContext;
@@ -42,10 +42,10 @@ public final class SQLRouteCountAdviceTest extends
MetricsAdviceBaseTest {
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("routed_insert_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("routed_update_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("routed_delete_sql_total")).reset();
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("routed_select_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_insert_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_update_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_delete_sql_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("routed_select_sql_total")).reset();
}
@Test
@@ -74,6 +74,6 @@ public final class SQLRouteCountAdviceTest extends
MetricsAdviceBaseTest {
public void assertRoute(final String metricId, final QueryContext
queryContext) {
advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class),
new Object[]{new ConnectionContext(), queryContext});
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get(metricId)).getFixtureValue(), is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(metricId)).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 e1f60067b13..6dd7af02a56 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
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
@@ -38,12 +38,12 @@ public final class CommitTransactionsCountAdviceTest
extends MetricsAdviceBaseTe
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_commit_transactions_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_commit_transactions_total")).reset();
}
@Test
public void assertMethod() {
advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class),
new Object[]{});
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY)).getFixtureValue(),
is(1D));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY)).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 482458655d0..bf87d1ede68 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
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
@@ -37,7 +37,7 @@ public final class CurrentConnectionsCountAdviceTest extends
MetricsAdviceBaseTe
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_current_connections")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_current_connections")).reset();
}
@Test
@@ -46,7 +46,7 @@ public final class CurrentConnectionsCountAdviceTest extends
MetricsAdviceBaseTe
advice.beforeMethod(targetObject, mockMethod("channelActive"), new
Object[]{});
advice.beforeMethod(targetObject, mockMethod("channelActive"), new
Object[]{});
advice.beforeMethod(targetObject, mockMethod("channelInactive"), new
Object[]{});
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_current_connections")).getFixtureValue(),
is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_current_connections")).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 2e9402f0ddf..4795ce424b2 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
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
@@ -34,13 +34,13 @@ public final class ExecuteErrorsCountAdviceTest extends
MetricsAdviceBaseTest {
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_execute_errors_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_errors_total")).reset();
}
@Test
public void assertCountExecuteErrors() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
new ExecuteErrorsCountAdvice().afterMethod(targetObject,
mock(Method.class), new Object[]{}, null);
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_execute_errors_total")).getFixtureValue(),
is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_errors_total")).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 4c006a259b8..9aea4911f41 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
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
@@ -34,7 +34,7 @@ public final class ExecuteLatencyHistogramAdviceTest extends
MetricsAdviceBaseTe
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_execute_latency_millis")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_latency_millis")).reset();
}
@Test
@@ -45,6 +45,6 @@ public final class ExecuteLatencyHistogramAdviceTest extends
MetricsAdviceBaseTe
advice.beforeMethod(targetObject, method, new Object[]{});
Thread.sleep(500L);
advice.afterMethod(targetObject, method, new Object[]{}, null);
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_execute_latency_millis")).getFixtureValue(),
greaterThanOrEqualTo(500D));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_execute_latency_millis")).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 c9316d13c97..f752e8dd9be 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
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
@@ -36,13 +36,13 @@ public final class RequestsCountAdviceTest extends
MetricsAdviceBaseTest {
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_requests_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_requests_total")).reset();
}
@Test
public void assertCountRequests() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
advice.beforeMethod(targetObject, mock(Method.class), new Object[]{});
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_requests_total")).getFixtureValue(),
is(1d));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_requests_total")).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 70b07d127d2..8b55e26b1ab 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
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
import
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
import org.junit.After;
import org.junit.Test;
@@ -36,12 +36,12 @@ public final class RollbackTransactionsCountAdviceTest
extends MetricsAdviceBase
@After
public void reset() {
- ((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_rollback_transactions_total")).reset();
+ ((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_rollback_transactions_total")).reset();
}
@Test
public void assertMethod() {
advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class),
new Object[]{});
- assertThat(((FixtureMetricsCollector)
MetricsCollectorRegistry.get("proxy_rollback_transactions_total")).getFixtureValue(),
is(1D));
+ assertThat(((MetricsCollectorFixture)
MetricsCollectorRegistry.get("proxy_rollback_transactions_total")).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 1cff17ff0c7..be2403761f7 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
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.fixture;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory;
public final class FixtureCollectorFactory implements MetricsCollectorFactory {
@Override
public MetricsCollector create(final String id) {
- return new FixtureMetricsCollector();
+ return new MetricsCollectorFixture();
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureMetricsCollector.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/MetricsCollectorFixture.java
similarity index 66%
rename from
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureMetricsCollector.java
rename to
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/MetricsCollectorFixture.java
index 7f9d8a52c79..5405f42ff88 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureMetricsCollector.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/MetricsCollectorFixture.java
@@ -18,48 +18,45 @@
package org.apache.shardingsphere.agent.plugin.metrics.core.fixture;
import lombok.Getter;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.CounterMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.GaugeMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.HistogramMetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.SummaryMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.SummaryMetricsCollector;
-/**
- * Fixture metrics collector.
- */
@Getter
-public final class FixtureMetricsCollector implements CounterMetricsCollector,
GaugeMetricsCollector, HistogramMetricsCollector, SummaryMetricsCollector {
+public final class MetricsCollectorFixture implements CounterMetricsCollector,
GaugeMetricsCollector, HistogramMetricsCollector, SummaryMetricsCollector {
- private Double fixtureValue = 0d;
+ private double value;
@Override
public void inc() {
- fixtureValue++;
+ value++;
}
@Override
public void inc(final String... labels) {
- fixtureValue++;
+ value++;
}
@Override
public void dec() {
- fixtureValue--;
+ value--;
}
@Override
public void dec(final String... labels) {
- fixtureValue--;
+ value--;
}
@Override
public void observe(final double value) {
- fixtureValue = value;
+ this.value = value;
}
/**
* Reset.
*/
public void reset() {
- fixtureValue = 0d;
+ value = 0d;
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
index 915c4b31602..1a4e7a9a4fd 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
@@ -23,11 +23,11 @@ import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.agent.api.PluginConfiguration;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollectorRegistry;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.BuildInfoCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.proxy.ProxyMetaDataInfoCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.proxy.ProxyStateCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.PrometheusCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.BuildInfoCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy.ProxyMetaDataInfoCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy.ProxyStateCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
import
org.apache.shardingsphere.agent.plugin.core.config.validator.PluginConfigurationValidator;
import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
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
new file mode 100644
index 00000000000..0c811912894
--- /dev/null
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
@@ -0,0 +1,92 @@
+/*
+ * 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.prometheus.collector;
+
+import io.prometheus.client.GaugeMetricFamily;
+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.core.collector.MetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory;
+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.PrometheusHistogramCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusSummaryCollector;
+
+import java.util.List;
+
+/**
+ * Prometheus metrics collector factory.
+ */
+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) {
+ return create(getMetricConfiguration(id));
+ }
+
+ private MetricsCollector create(final MetricConfiguration metricConfig) {
+ switch (metricConfig.getType().toUpperCase()) {
+ case "COUNTER":
+ return new PrometheusCounterCollector(metricConfig);
+ case "GAUGE":
+ return new PrometheusGaugeCollector(metricConfig);
+ case "HISTOGRAM":
+ return new PrometheusHistogramCollector(metricConfig);
+ case "SUMMARY":
+ return new PrometheusSummaryCollector(metricConfig);
+ default:
+ throw new UnsupportedOperationException(String.format("Can not
support type `%s`.", metricConfig.getType()));
+ }
+ }
+
+ private MetricConfiguration getMetricConfiguration(final String id) {
+ return METRICS_CONFIG.get(id);
+ }
+
+ /**
+ * Create gauge metric family.
+ *
+ * @param id metric id
+ * @return gauge metric family
+ */
+ public GaugeMetricFamily createGaugeMetricFamily(final String id) {
+ MetricConfiguration metricConfig = getMetricConfiguration(id);
+ List<String> labels = metricConfig.getLabels();
+ return labels.isEmpty() ? new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), 1d) : new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), labels);
+ }
+
+ /**
+ * Create gauge metric with value.
+ *
+ * @param id metric id
+ * @param value value
+ * @return gauge metric
+ */
+ public GaugeMetricFamily createGaugeMetric(final String id, final double
value) {
+ MetricConfiguration metricConfig = getMetricConfiguration(id);
+ return new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), value);
+ }
+}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
similarity index 97%
rename from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
rename to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
index 57b69de81be..440477e824b 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/BuildInfoCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollector.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.PrometheusCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
import org.apache.shardingsphere.proxy.Bootstrap;
import java.util.Arrays;
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyMetaDataInfoCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
similarity index 98%
rename from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyMetaDataInfoCollector.java
rename to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
index c831d15b919..9f1f272f3dd 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyMetaDataInfoCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollector.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.proxy;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import lombok.extern.slf4j.Slf4j;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.PrometheusCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
similarity index 96%
rename from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java
rename to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
index e92f21f0f53..29c845bca07 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollector.java
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.proxy;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
import io.prometheus.client.Collector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.PrometheusCollectorFactory;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
import org.apache.shardingsphere.infra.state.StateContext;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusCounterCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
similarity index 74%
rename from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusCounterCollector.java
rename to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
index 7177b72430b..3c0f217701f 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusCounterCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollector.java
@@ -15,20 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Counter;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.CounterMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.CounterMetricsCollector;
/**
* Prometheus counter wrapper.
*/
-@RequiredArgsConstructor
public final class PrometheusCounterCollector implements
CounterMetricsCollector {
private final Counter counter;
+ public PrometheusCounterCollector(final MetricConfiguration config) {
+ counter =
Counter.build().name(config.getId()).help(config.getHelp()).labelNames(config.getLabels().toArray(new
String[0])).register();
+ }
+
@Override
public void inc() {
counter.inc(1d);
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusGaugeCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
similarity index 76%
rename from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusGaugeCollector.java
rename to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
index 6d753de1c38..254afc808e9 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusGaugeCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollector.java
@@ -15,20 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Gauge;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.GaugeMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricsCollector;
/**
* Prometheus gauge wrapper.
*/
-@RequiredArgsConstructor
public final class PrometheusGaugeCollector implements GaugeMetricsCollector {
private final Gauge gauge;
+ public PrometheusGaugeCollector(final MetricConfiguration config) {
+ gauge =
Gauge.build().name(config.getId()).help(config.getHelp()).labelNames(config.getLabels().toArray(new
String[0])).register();
+ }
+
@Override
public void inc() {
gauge.inc(1d);
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
new file mode 100644
index 00000000000..f17e88daef1
--- /dev/null
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollector.java
@@ -0,0 +1,63 @@
+/*
+ * 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.prometheus.collector.type;
+
+import io.prometheus.client.Histogram;
+import io.prometheus.client.Histogram.Builder;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
+
+import java.util.Map;
+
+/**
+ * Prometheus histogram wrapper.
+ */
+public final class PrometheusHistogramCollector implements
HistogramMetricsCollector {
+
+ private final Histogram histogram;
+
+ public PrometheusHistogramCollector(final MetricConfiguration config) {
+ Builder builder =
Histogram.build().name(config.getId()).help(config.getHelp()).labelNames(config.getLabels().toArray(new
String[0]));
+ appendProperties(builder, config.getProps());
+ histogram = builder.register();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void appendProperties(final Builder builder, final Map<String,
Object> props) {
+ Map<String, Object> buckets = (Map<String, Object>)
props.get("buckets");
+ if (null == buckets) {
+ return;
+ }
+ if ("exp".equals(buckets.get("type"))) {
+ double start = null == buckets.get("start") ? 1 :
Double.parseDouble(buckets.get("start").toString());
+ double factor = null == buckets.get("factor") ? 1 :
Double.parseDouble(buckets.get("factor").toString());
+ int count = null == buckets.get("count") ? 1 : (int)
buckets.get("count");
+ builder.exponentialBuckets(start, factor, count);
+ } else if ("linear".equals(buckets.get("type"))) {
+ double start = null == buckets.get("start") ? 1 :
Double.parseDouble(buckets.get("start").toString());
+ double width = null == buckets.get("width") ? 1 :
Double.parseDouble(buckets.get("width").toString());
+ int count = null == buckets.get("count") ? 1 : (int)
buckets.get("count");
+ builder.linearBuckets(start, width, count);
+ }
+ }
+
+ @Override
+ public void observe(final double value) {
+ histogram.observe(value);
+ }
+}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusSummaryCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
similarity index 73%
rename from
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusSummaryCollector.java
rename to
agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
index 09aac8c7899..f142ffee90e 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusSummaryCollector.java
+++
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryCollector.java
@@ -15,20 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Summary;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.SummaryMetricsCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.SummaryMetricsCollector;
/**
* Prometheus summary wrapper.
*/
-@RequiredArgsConstructor
public final class PrometheusSummaryCollector implements
SummaryMetricsCollector {
private final Summary summary;
+ public PrometheusSummaryCollector(final MetricConfiguration config) {
+ summary =
Summary.build().name(config.getId()).help(config.getHelp()).labelNames(config.getLabels().toArray(new
String[0])).register();
+ }
+
@Override
public void observe(final double value) {
summary.observe(value);
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusCollectorFactory.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusCollectorFactory.java
deleted file mode 100644
index e8750579a4e..00000000000
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusCollectorFactory.java
+++ /dev/null
@@ -1,156 +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.prometheus.wrapper;
-
-import io.prometheus.client.Counter;
-import io.prometheus.client.Gauge;
-import io.prometheus.client.GaugeMetricFamily;
-import io.prometheus.client.Histogram;
-import io.prometheus.client.Summary;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.MetricsCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.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.wrapper.type.PrometheusCounterCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusGaugeCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusHistogramCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusSummaryCollector;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Prometheus metrics collector factory.
- */
-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) {
- return create(getMetricConfiguration(id));
- }
-
- private MetricsCollector create(final MetricConfiguration metricConfig) {
- switch (metricConfig.getType().toUpperCase()) {
- case "COUNTER":
- return createCounter(metricConfig);
- case "GAUGE":
- return createGauge(metricConfig);
- case "HISTOGRAM":
- return createHistogram(metricConfig);
- case "SUMMARY":
- return createSummary(metricConfig);
- default:
- throw new UnsupportedOperationException(String.format("Can not
support type `%s`.", metricConfig.getType()));
- }
- }
-
- private MetricConfiguration getMetricConfiguration(final String id) {
- return METRICS_CONFIG.get(id);
- }
-
- private MetricsCollector createCounter(final MetricConfiguration
metricConfig) {
- Counter.Builder builder =
Counter.build().name(metricConfig.getId()).help(metricConfig.getHelp());
- List<String> labels = metricConfig.getLabels();
- if (!labels.isEmpty()) {
- builder.labelNames(labels.toArray(new String[0]));
- }
- return new PrometheusCounterCollector(builder.register());
- }
-
- private MetricsCollector createGauge(final MetricConfiguration
metricConfig) {
- Gauge.Builder builder =
Gauge.build().name(metricConfig.getId()).help(metricConfig.getHelp());
- List<String> labels = metricConfig.getLabels();
- if (!labels.isEmpty()) {
- builder.labelNames(labels.toArray(new String[0]));
- }
- return new PrometheusGaugeCollector(builder.register());
- }
-
- private MetricsCollector createHistogram(final MetricConfiguration
metricConfig) {
- Histogram.Builder builder =
Histogram.build().name(metricConfig.getId()).help(metricConfig.getHelp());
- List<String> labels = metricConfig.getLabels();
- if (!labels.isEmpty()) {
- builder.labelNames(labels.toArray(new String[0]));
- }
- Map<String, Object> props = metricConfig.getProps();
- if (!props.isEmpty()) {
- parseHistogramProperties(builder, props);
- }
- return new PrometheusHistogramCollector(builder.register());
- }
-
- @SuppressWarnings("unchecked")
- private void parseHistogramProperties(final Histogram.Builder builder,
final Map<String, Object> props) {
- Map<String, Object> buckets = (Map<String, Object>)
props.get("buckets");
- if (null == buckets) {
- return;
- }
- if ("exp".equals(buckets.get("type"))) {
- double start = null == buckets.get("start") ? 1 :
Double.parseDouble(buckets.get("start").toString());
- double factor = null == buckets.get("factor") ? 1 :
Double.parseDouble(buckets.get("factor").toString());
- int count = null == buckets.get("count") ? 1 : (int)
buckets.get("count");
- builder.exponentialBuckets(start, factor, count);
- } else if ("linear".equals(buckets.get("type"))) {
- double start = null == buckets.get("start") ? 1 :
Double.parseDouble(buckets.get("start").toString());
- double width = null == buckets.get("width") ? 1 :
Double.parseDouble(buckets.get("width").toString());
- int count = null == buckets.get("count") ? 1 : (int)
buckets.get("count");
- builder.linearBuckets(start, width, count);
- }
- }
-
- private MetricsCollector createSummary(final MetricConfiguration
metricConfig) {
- Summary.Builder builder =
Summary.build().name(metricConfig.getId()).help(metricConfig.getHelp());
- List<String> labels = metricConfig.getLabels();
- if (!labels.isEmpty()) {
- builder.labelNames(labels.toArray(new String[0]));
- }
- return new PrometheusSummaryCollector(builder.register());
- }
-
- /**
- * Create gauge metric family.
- *
- * @param id metric id
- * @return gauge metric family
- */
- public GaugeMetricFamily createGaugeMetricFamily(final String id) {
- MetricConfiguration metricConfig = getMetricConfiguration(id);
- List<String> labels = metricConfig.getLabels();
- return labels.isEmpty() ? new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), 1d) : new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), labels);
- }
-
- /**
- * Create gauge metric with value.
- *
- * @param id metric id
- * @param value value
- * @return gauge metric
- */
- public GaugeMetricFamily createGaugeMetric(final String id, final double
value) {
- MetricConfiguration metricConfig = getMetricConfiguration(id);
- return new GaugeMetricFamily(metricConfig.getId(),
metricConfig.getHelp(), value);
- }
-}
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusHistogramCollector.java
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusHistogramCollector.java
deleted file mode 100644
index f6133a4f8f6..00000000000
---
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusHistogramCollector.java
+++ /dev/null
@@ -1,36 +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.prometheus.wrapper.type;
-
-import io.prometheus.client.Histogram;
-import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.wrapper.type.HistogramMetricsCollector;
-
-/**
- * Prometheus histogram wrapper.
- */
-@RequiredArgsConstructor
-public final class PrometheusHistogramCollector implements
HistogramMetricsCollector {
-
- private final Histogram histogram;
-
- @Override
- public void observe(final double value) {
- histogram.observe(value);
- }
-}
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
similarity index 88%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
index 8f0fe2f9596..e892bae19b8 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactoryTest.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper;
+package org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusCounterCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusGaugeCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusHistogramCollector;
-import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type.PrometheusSummaryCollector;
+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.PrometheusHistogramCollector;
+import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type.PrometheusSummaryCollector;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-public final class PrometheusWrapperFactoryTest {
+public final class PrometheusCollectorFactoryTest {
@Test
public void assertCreate() {
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/BuildInfoCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
similarity index 98%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/BuildInfoCollectorTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
index 78b167a4014..a2a54c99686 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/BuildInfoCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/BuildInfoCollectorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business;
import org.junit.Test;
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyMetaDataInfoCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollectorTest.java
similarity index 98%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyMetaDataInfoCollectorTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollectorTest.java
index 8b8da121046..9db96d5201c 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyMetaDataInfoCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyMetaDataInfoCollectorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.proxy;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.ProxyContextRestorer;
import org.apache.shardingsphere.mode.manager.ContextManager;
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollectorTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollectorTest.java
similarity index 98%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollectorTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollectorTest.java
index 04db3f908a6..439ef37d947 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/proxy/ProxyStateCollectorTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/business/proxy/ProxyStateCollectorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.proxy;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy;
import
org.apache.shardingsphere.agent.plugin.metrics.prometheus.ProxyContextRestorer;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusCounterWrapperTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
similarity index 69%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusCounterWrapperTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
index 4cd617a420f..d71a11113f2 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusCounterWrapperTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusCounterCollectorTest.java
@@ -15,23 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Counter;
+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.MatcherAssert.assertThat;
-public final class PrometheusCounterWrapperTest {
+public final class PrometheusCounterCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- Counter counter = Counter.build().name("a").help("help").create();
- PrometheusCounterCollector counterWrapper = new
PrometheusCounterCollector(counter);
- counterWrapper.inc();
- counter = (Counter)
Plugins.getMemberAccessor().get(PrometheusCounterCollector.class.getDeclaredField("counter"),
counterWrapper);
+ 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));
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusGaugeWrapperTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
similarity index 67%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusGaugeWrapperTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
index fe948a1f314..6a063bd37e1 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusGaugeWrapperTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusGaugeCollectorTest.java
@@ -15,23 +15,27 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Gauge;
+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.MatcherAssert.assertThat;
-public final class PrometheusGaugeWrapperTest {
+public final class PrometheusGaugeCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- Gauge gauge = Gauge.build().name("a").help("help").create();
- PrometheusGaugeCollector gaugeWrapper = new
PrometheusGaugeCollector(gauge);
- gaugeWrapper.inc();
- gauge = (Gauge)
Plugins.getMemberAccessor().get(PrometheusGaugeCollector.class.getDeclaredField("gauge"),
gaugeWrapper);
+ PrometheusGaugeCollector collector = new PrometheusGaugeCollector(new
MetricConfiguration("foo_gauge", "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));
+ collector.dec();
+ assertThat(gauge.get(), is(0d));
}
}
diff --git
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusHistogramWrapperTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
similarity index 68%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusHistogramWrapperTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
index e1aea449052..46dcd7b8dc7 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusHistogramWrapperTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusHistogramCollectorTest.java
@@ -15,23 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Histogram;
+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.MatcherAssert.assertThat;
-public final class PrometheusHistogramWrapperTest {
+public final class PrometheusHistogramCollectorTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- Histogram histogram =
Histogram.build().name("a").help("help").create();
- PrometheusHistogramCollector histogramWrapper = new
PrometheusHistogramCollector(histogram);
- histogramWrapper.observe(1);
- histogram = (Histogram)
Plugins.getMemberAccessor().get(PrometheusHistogramCollector.class.getDeclaredField("histogram"),
histogramWrapper);
+ PrometheusHistogramCollector collector = new
PrometheusHistogramCollector(new MetricConfiguration("foo_histogram",
"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/wrapper/type/PrometheusSummaryWrapperTest.java
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
similarity index 79%
rename from
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusSummaryWrapperTest.java
rename to
agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
index 5e8a31a906e..13acd71db6b 100644
---
a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/wrapper/type/PrometheusSummaryWrapperTest.java
+++
b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusSummaryWrapperTest.java
@@ -15,12 +15,15 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.prometheus.wrapper.type;
+package
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.type;
import io.prometheus.client.Summary;
+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.MatcherAssert.assertThat;
@@ -28,9 +31,9 @@ public final class PrometheusSummaryWrapperTest {
@Test
public void assertCreate() throws ReflectiveOperationException {
- PrometheusSummaryCollector summaryWrapper = new
PrometheusSummaryCollector(Summary.build().name("a").help("help").create());
- summaryWrapper.observe(1);
- Summary summary = (Summary)
Plugins.getMemberAccessor().get(PrometheusSummaryCollector.class.getDeclaredField("summary"),
summaryWrapper);
+ PrometheusSummaryCollector collector = new
PrometheusSummaryCollector(new MetricConfiguration("foo_summary", "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));
}
}