You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/08/13 11:39:17 UTC
[shardingsphere] branch master updated: Refactor metrics (#11804)
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 6433e60 Refactor metrics (#11804)
6433e60 is described below
commit 6433e6036ceccc997cc522f5f0bfd6b34499cc28
Author: Dachuan J <46...@users.noreply.github.com>
AuthorDate: Fri Aug 13 19:38:46 2021 +0800
Refactor metrics (#11804)
---
.../agent/metrics/api/advice/DataSourceAdvice.java | 40 -------
.../metrics/api/advice/PacketCodecAdvice.java | 58 ----------
.../agent/metrics/api/constant/MetricIds.java | 6 -
.../src/main/resources/interceptors.yaml | 12 --
.../metrics/api/advice/DataSourceAdviceTest.java | 49 --------
.../metrics/api/advice/PacketCodecAdviceTest.java | 71 ------------
.../MetricsPluginDefinitionServiceTest.java | 2 +-
.../handler/PrometheusMetricsHandler.java | 47 --------
.../prometheus/hikari/HikariMetricsTracker.java | 79 -------------
.../hikari/HikariMetricsTrackerFactory.java | 65 -----------
.../prometheus/hikari/HikariPoolStatCollector.java | 92 ---------------
.../prometheus/hikari/HikariSimpleMetrics.java | 124 ---------------------
.../prometheus/wrapper/DelegateWrapper.java | 36 ------
.../wrapper/PrometheusWrapperFactory.java | 28 +++--
.../src/main/resources/metrics.yaml | 24 ----
.../handler/PrometheusMetricsHandlerTest.java | 40 -------
.../hikari/HikariMetricsTrackerFactoryTest.java | 62 -----------
.../hikari/HikariMetricsTrackerTest.java | 61 ----------
.../hikari/HikariPoolStatCollectorTest.java | 57 ----------
.../prometheus/hikari/HikariSimpleMetricsTest.java | 44 --------
.../prometheus/wrapper/DelegateWrapperTest.java | 33 ------
.../wrapper/PrometheusWrapperFactoryTest.java | 2 -
.../src/test/resources/metrics.yaml | 8 --
.../agent/test/metrics/MetricsPluginIT.java | 6 -
24 files changed, 14 insertions(+), 1032 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/DataSourceAdvice.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/DataSourceAdvice.java
deleted file mode 100644
index 101c26d..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/DataSourceAdvice.java
+++ /dev/null
@@ -1,40 +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.metrics.api.advice;
-
-import org.apache.shardingsphere.agent.api.advice.ClassStaticMethodAroundAdvice;
-import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
-import org.apache.shardingsphere.agent.metrics.api.MetricsPool;
-import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
-
-import java.lang.reflect.Method;
-
-/**
- * Data Source advice.
- */
-public final class DataSourceAdvice implements ClassStaticMethodAroundAdvice {
-
- static {
- MetricsPool.create(MetricIds.HIKARI_SET_METRICS_FACTORY);
- }
-
- @Override
- public void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final MethodInvocationResult result) {
- MetricsPool.get(MetricIds.HIKARI_SET_METRICS_FACTORY).ifPresent(m -> m.delegate(result.getResult()));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/PacketCodecAdvice.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/PacketCodecAdvice.java
deleted file mode 100644
index eb30f8e..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/PacketCodecAdvice.java
+++ /dev/null
@@ -1,58 +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.metrics.api.advice;
-
-import io.netty.buffer.ByteBuf;
-import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
-import org.apache.shardingsphere.agent.api.advice.InstanceMethodAroundAdvice;
-import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
-import org.apache.shardingsphere.agent.metrics.api.MetricsPool;
-import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
-
-import java.lang.reflect.Method;
-
-/**
- * Packet codec advice.
- */
-public final class PacketCodecAdvice implements InstanceMethodAroundAdvice {
-
- public static final String METHOD_ENCODE = "encode";
-
- public static final String METHOD_DECODE = "decode";
-
- static {
- MetricsPool.create(MetricIds.PROXY_REQUEST_BYTES);
- MetricsPool.create(MetricIds.PROXY_RESPONSE_BYTES);
- }
-
- @Override
- public void beforeMethod(final AdviceTargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
- if (METHOD_DECODE.equals(method.getName())) {
- ByteBuf in = (ByteBuf) args[1];
- MetricsPool.get(MetricIds.PROXY_REQUEST_BYTES).ifPresent(m -> m.observe(in.readableBytes()));
- }
- }
-
- @Override
- public void afterMethod(final AdviceTargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
- if (METHOD_ENCODE.equals(method.getName())) {
- ByteBuf out = (ByteBuf) args[2];
- MetricsPool.get(MetricIds.PROXY_RESPONSE_BYTES).ifPresent(m -> m.observe(out.readableBytes()));
- }
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/constant/MetricIds.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/constant/MetricIds.java
index 0bedbd9..ac5d807 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/constant/MetricIds.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/constant/MetricIds.java
@@ -27,10 +27,6 @@ public final class MetricIds {
public static final String PROXY_EXECUTE_ERROR = "proxy_execute_error_total";
- public static final String PROXY_REQUEST_BYTES = "proxy_request_bytes";
-
- public static final String PROXY_RESPONSE_BYTES = "proxy_response_bytes";
-
public static final String ROUTE_SQL_SELECT = "route_sql_select_total";
public static final String ROUTE_SQL_UPDATE = "route_sql_update_total";
@@ -47,8 +43,6 @@ public final class MetricIds {
public static final String TRANSACTION_ROLLBACK = "proxy_transaction_rollback_total";
- public static final String HIKARI_SET_METRICS_FACTORY = "hikari_set_metrics_factory";
-
public static final String PROXY_INFO = "proxy_info";
public static final String BUILD_INFO = "build_info";
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml
index d95bd1d..9c55f17 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml
@@ -44,18 +44,6 @@ interceptors:
name: commit
- type: instance
name: rollback
- - target: org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper
- staticAdvice: org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice
- points:
- - type: static
- name: decorate
- - target: org.apache.shardingsphere.db.protocol.codec.PacketCodec
- instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.PacketCodecAdvice
- points:
- - type: instance
- name: decode
- - type: instance
- name: encode
- target: org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine
instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.SQLParserEngineAdvice
points:
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/DataSourceAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/DataSourceAdviceTest.java
deleted file mode 100644
index 2bb086e..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/DataSourceAdviceTest.java
+++ /dev/null
@@ -1,49 +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.metrics.api.advice;
-
-import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
-import org.apache.shardingsphere.agent.metrics.api.MetricsPool;
-import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
-import org.apache.shardingsphere.agent.metrics.api.fixture.FixtureWrapper;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.lang.reflect.Method;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class DataSourceAdviceTest extends MetricsAdviceBaseTest {
-
- private final DataSourceAdvice dataSourceAdvice = new DataSourceAdvice();
-
- @Mock
- private Method decorate;
-
- @Test
- public void assertDataSourceDelegate() {
- dataSourceAdvice.afterMethod(DataSourceAdviceTest.class, decorate, new Object[]{}, new MethodInvocationResult());
- FixtureWrapper wrapper = (FixtureWrapper) MetricsPool.get(MetricIds.HIKARI_SET_METRICS_FACTORY).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(-1.0d));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/PacketCodecAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/PacketCodecAdviceTest.java
deleted file mode 100644
index 5dfdb41..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/PacketCodecAdviceTest.java
+++ /dev/null
@@ -1,71 +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.metrics.api.advice;
-
-import io.netty.buffer.ByteBuf;
-import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
-import org.apache.shardingsphere.agent.metrics.api.MetricsPool;
-import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
-import org.apache.shardingsphere.agent.metrics.api.fixture.FixtureWrapper;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.lang.reflect.Method;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class PacketCodecAdviceTest extends MetricsAdviceBaseTest {
-
- private final PacketCodecAdvice advice = new PacketCodecAdvice();
-
- @Mock
- private Method encode;
-
- @Mock
- private Method decode;
-
- @Mock
- private ByteBuf buf;
-
- @Test
- public void assertResponse() {
- when(encode.getName()).thenReturn(PacketCodecAdvice.METHOD_ENCODE);
- MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
- when(buf.readableBytes()).thenReturn(100);
- advice.afterMethod(targetObject, encode, new Object[]{new Object(), new Object(), buf}, new MethodInvocationResult());
- FixtureWrapper wrapper = (FixtureWrapper) MetricsPool.get(MetricIds.PROXY_RESPONSE_BYTES).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(100d));
- }
-
- @Test
- public void assertRequest() {
- when(decode.getName()).thenReturn(PacketCodecAdvice.METHOD_DECODE);
- MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
- when(buf.readableBytes()).thenReturn(200);
- advice.beforeMethod(targetObject, decode, new Object[]{new Object(), buf}, new MethodInvocationResult());
- FixtureWrapper wrapper = (FixtureWrapper) MetricsPool.get(MetricIds.PROXY_REQUEST_BYTES).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(200d));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/definition/MetricsPluginDefinitionServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/definition/MetricsPluginDefinitionServiceTest.java
index 7b37848..3d76737 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/definition/MetricsPluginDefinitionServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/definition/MetricsPluginDefinitionServiceTest.java
@@ -31,7 +31,7 @@ public final class MetricsPluginDefinitionServiceTest {
@Test
public void assertDefine() {
Collection<PluginInterceptorPoint> interceptorPointList = metricsPluginDefinitionService.install();
- assertThat(interceptorPointList.size(), is(7));
+ assertThat(interceptorPointList.size(), is(5));
}
@Test
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/handler/PrometheusMetricsHandler.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/handler/PrometheusMetricsHandler.java
deleted file mode 100644
index 809659a..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/handler/PrometheusMetricsHandler.java
+++ /dev/null
@@ -1,47 +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.metrics.prometheus.handler;
-
-import com.zaxxer.hikari.HikariDataSource;
-import io.prometheus.client.CollectorRegistry;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
-import org.apache.shardingsphere.agent.metrics.prometheus.hikari.HikariMetricsTrackerFactory;
-
-/**
- * Prometheus metrics handler.
- */
-@Slf4j
-public final class PrometheusMetricsHandler {
-
- /**
- * Handle the delegate metric.
- *
- * @param id metric id
- * @param object delegate parameter object
- */
- public static void handle(final String id, final Object object) {
- if (MetricIds.HIKARI_SET_METRICS_FACTORY.equals(id)) {
- if (object instanceof HikariDataSource) {
- HikariDataSource dataSource = (HikariDataSource) object;
- dataSource.setMetricsTrackerFactory(HikariMetricsTrackerFactory.getInstance(CollectorRegistry.defaultRegistry));
- log.info("Set metrics factory to {}", dataSource);
- }
- }
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTracker.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTracker.java
deleted file mode 100644
index b7a2894..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTracker.java
+++ /dev/null
@@ -1,79 +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.metrics.prometheus.hikari;
-
-import com.zaxxer.hikari.metrics.IMetricsTracker;
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.CollectorRegistry;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Hikari metrics tracker.
- */
-class HikariMetricsTracker implements IMetricsTracker {
-
- private static final Map<CollectorRegistry, Integer> REGISTRY_STAT_MAP = new ConcurrentHashMap<>();
-
- private static final HikariPoolStatCollector HIKARI_POOL_STAT_COLLECTOR = new HikariPoolStatCollector();
-
- private final String poolName;
-
- private final HikariSimpleMetrics hikariSimpleMetrics;
-
- HikariMetricsTracker(final String poolName, final PoolStats poolStats, final CollectorRegistry collectorRegistry) {
- hikariSimpleMetrics = new HikariSimpleMetrics(poolName);
- this.poolName = poolName;
- HIKARI_POOL_STAT_COLLECTOR.addPoolStats(poolName, poolStats);
- registerMetrics(collectorRegistry);
- }
-
- private void registerMetrics(final CollectorRegistry collectorRegistry) {
- if (null == REGISTRY_STAT_MAP.putIfAbsent(collectorRegistry, 1)) {
- HIKARI_POOL_STAT_COLLECTOR.register(collectorRegistry);
- hikariSimpleMetrics.register(collectorRegistry);
- }
- }
-
- @Override
- public void recordConnectionAcquiredNanos(final long elapsedAcquiredNanos) {
- hikariSimpleMetrics.observe(HikariSimpleMetrics.MetricsType.CONNECTION_ACQUIRED_NANOS, elapsedAcquiredNanos);
- }
-
- @Override
- public void recordConnectionUsageMillis(final long elapsedBorrowedMillis) {
- hikariSimpleMetrics.observe(HikariSimpleMetrics.MetricsType.CONNECTION_USAGE_MILLIS, elapsedBorrowedMillis);
- }
-
- @Override
- public void recordConnectionCreatedMillis(final long connectionCreatedMillis) {
- hikariSimpleMetrics.observe(HikariSimpleMetrics.MetricsType.CONNECTION_CREATED_MILLIS, connectionCreatedMillis);
- }
-
- @Override
- public void recordConnectionTimeout() {
- hikariSimpleMetrics.observe(HikariSimpleMetrics.MetricsType.CONNECTION_TIMEOUT_COUNT, 1);
- }
-
- @Override
- public void close() {
- HIKARI_POOL_STAT_COLLECTOR.removePoolStats(poolName);
- hikariSimpleMetrics.closeMetrics();
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerFactory.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerFactory.java
deleted file mode 100644
index 616623f..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerFactory.java
+++ /dev/null
@@ -1,65 +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.metrics.prometheus.hikari;
-
-import com.zaxxer.hikari.metrics.IMetricsTracker;
-import com.zaxxer.hikari.metrics.MetricsTrackerFactory;
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.CollectorRegistry;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Hikari metrics tracker factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class HikariMetricsTrackerFactory implements MetricsTrackerFactory {
-
- private static volatile HikariMetricsTrackerFactory instance;
-
- private CollectorRegistry collectorRegistry;
-
- private HikariMetricsTrackerFactory(final CollectorRegistry collectorRegistry) {
- this.collectorRegistry = collectorRegistry;
- }
-
- /**
- * Get the factory with the specific registry.
- *
- * @param collectorRegistry the metrics registry
- * @return default metrics tracker factory
- */
- public static HikariMetricsTrackerFactory getInstance(final CollectorRegistry collectorRegistry) {
- if (null == instance) {
- instance = new HikariMetricsTrackerFactory(collectorRegistry);
- }
- return instance;
- }
-
- /**
- * Create the metric tracker.
- *
- * @param poolName the hikariCP pool name
- * @param poolStats the hikariCP pool state
- * @return the created metrics tracker
- */
- @Override
- public IMetricsTracker create(final String poolName, final PoolStats poolStats) {
- return new HikariMetricsTracker(poolName, poolStats, this.collectorRegistry);
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariPoolStatCollector.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariPoolStatCollector.java
deleted file mode 100644
index a58c01f..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariPoolStatCollector.java
+++ /dev/null
@@ -1,92 +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.metrics.prometheus.hikari;
-
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
-import io.prometheus.client.GaugeMetricFamily;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Hikari PoolStat Collector.
- */
-public final class HikariPoolStatCollector extends Collector {
-
- private final Map<String, PoolStats> poolStatsMap = new ConcurrentHashMap<>();
-
- @Override
- public List<MetricFamilySamples> collect() {
- GaugeMetricFamily activeConnections = new GaugeMetricFamily(
- "hikaricp_active_connections",
- "Active connections",
- Collections.singletonList("pool"));
- poolStatsMap.forEach((k, v) ->
- activeConnections.addMetric(Collections.singletonList(k), v.getActiveConnections()));
- GaugeMetricFamily idleConnections = new GaugeMetricFamily(
- "hikaricp_idle_connections",
- "Idle connections",
- Collections.singletonList("pool"));
- poolStatsMap.forEach((k, v) ->
- idleConnections.addMetric(Collections.singletonList(k), v.getIdleConnections()));
- GaugeMetricFamily pendingThreads = new GaugeMetricFamily(
- "hikaricp_pending_threads",
- "Pending threads",
- Collections.singletonList("pool"));
- poolStatsMap.forEach((k, v) ->
- pendingThreads.addMetric(Collections.singletonList(k), v.getPendingThreads()));
- GaugeMetricFamily totalConnections = new GaugeMetricFamily(
- "hikaricp_connections",
- "Total connections",
- Collections.singletonList("pool"));
- poolStatsMap.forEach((k, v) ->
- totalConnections.addMetric(Collections.singletonList(k), v.getTotalConnections()));
- GaugeMetricFamily maxConnections = new GaugeMetricFamily(
- "hikaricp_max_connections",
- "Max connections",
- Collections.singletonList("pool"));
- poolStatsMap.forEach((k, v) ->
- maxConnections.addMetric(Collections.singletonList(k), v.getMaxConnections()));
- GaugeMetricFamily minConnections = new GaugeMetricFamily(
- "hikaricp_min_connections",
- "Min connections",
- Collections.singletonList("pool"));
- poolStatsMap.forEach((k, v) ->
- minConnections.addMetric(Collections.singletonList(k), v.getMinConnections()));
- List<MetricFamilySamples> result = new LinkedList<>();
- result.add(activeConnections);
- result.add(idleConnections);
- result.add(pendingThreads);
- result.add(totalConnections);
- result.add(maxConnections);
- result.add(minConnections);
- return result;
- }
-
- void addPoolStats(final String poolName, final PoolStats poolStats) {
- poolStatsMap.put(poolName, poolStats);
- }
-
- void removePoolStats(final String poolName) {
- poolStatsMap.remove(poolName);
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariSimpleMetrics.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariSimpleMetrics.java
deleted file mode 100644
index 645ca2b..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariSimpleMetrics.java
+++ /dev/null
@@ -1,124 +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.metrics.prometheus.hikari;
-
-import io.prometheus.client.CollectorRegistry;
-import io.prometheus.client.Counter;
-import io.prometheus.client.Histogram;
-
-/**
- * Hikari Metrics.
- */
-public final class HikariSimpleMetrics {
-
- private static final Counter CONNECTION_TIMEOUT_COUNTER = Counter.build()
- .name("hikaricp_connection_timeout_total")
- .labelNames("pool")
- .help("Connection timeout total count")
- .create();
-
- private static final Histogram ELAPSED_ACQUIRED =
- createHistogram("hikaricp_connection_acquired_nanos", "Connection acquired time (ns)", 1_000);
-
- private static final Histogram ELAPSED_USAGE =
- createHistogram("hikaricp_connection_usage_millis", "Connection usage (ms)", 1);
-
- private static final Histogram ELAPSED_CREATION =
- createHistogram("hikaricp_connection_creation_millis", "Connection creation (ms)", 1);
-
- private final Counter.Child connectionTimeoutCounterChild;
-
- private final Histogram.Child elapsedAcquiredChild;
-
- private final Histogram.Child elapsedUsageChild;
-
- private final Histogram.Child elapsedCreationChild;
-
- private final String poolName;
-
- public enum MetricsType {
- CONNECTION_ACQUIRED_NANOS,
- CONNECTION_USAGE_MILLIS,
- CONNECTION_CREATED_MILLIS,
- CONNECTION_TIMEOUT_COUNT
- }
-
- public HikariSimpleMetrics(final String poolName) {
- this.poolName = poolName;
- connectionTimeoutCounterChild = CONNECTION_TIMEOUT_COUNTER.labels(poolName);
- elapsedAcquiredChild = ELAPSED_ACQUIRED.labels(poolName);
- elapsedUsageChild = ELAPSED_USAGE.labels(poolName);
- elapsedCreationChild = ELAPSED_CREATION.labels(poolName);
- }
-
- private static Histogram createHistogram(final String name, final String help, final double bucketStart) {
- return Histogram.build()
- .name(name)
- .labelNames("pool")
- .help(help)
- .exponentialBuckets(bucketStart, 2.0, 11)
- .create();
- }
-
- /**
- * register metrics.
- *
- * @param registry the metrics register
- */
- public void register(final CollectorRegistry registry) {
- CONNECTION_TIMEOUT_COUNTER.register(registry);
- ELAPSED_ACQUIRED.register(registry);
- ELAPSED_USAGE.register(registry);
- ELAPSED_CREATION.register(registry);
- }
-
- /**
- * observe metrics.
- *
- * @param type the metrics type
- * @param value the metrics value
- */
- public void observe(final MetricsType type, final double value) {
- switch (type) {
- case CONNECTION_ACQUIRED_NANOS:
- elapsedAcquiredChild.observe(value);
- break;
- case CONNECTION_USAGE_MILLIS:
- elapsedUsageChild.observe(value);
- break;
- case CONNECTION_CREATED_MILLIS:
- elapsedCreationChild.observe(value);
- break;
- case CONNECTION_TIMEOUT_COUNT:
- connectionTimeoutCounterChild.inc();
- break;
- default:
- break;
- }
- }
-
- /**
- * close metrics.
- */
- public void closeMetrics() {
- CONNECTION_TIMEOUT_COUNTER.remove(poolName);
- ELAPSED_ACQUIRED.remove(poolName);
- ELAPSED_USAGE.remove(poolName);
- ELAPSED_CREATION.remove(poolName);
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/DelegateWrapper.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/DelegateWrapper.java
deleted file mode 100644
index 0605e5c..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/DelegateWrapper.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.metrics.prometheus.wrapper;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.agent.metrics.api.MetricsWrapper;
-import org.apache.shardingsphere.agent.metrics.prometheus.handler.PrometheusMetricsHandler;
-
-/**
- * Prometheus delegate wrapper.
- */
-@RequiredArgsConstructor
-public final class DelegateWrapper implements MetricsWrapper {
-
- private final String id;
-
- @Override
- public void delegate(final Object value) {
- PrometheusMetricsHandler.handle(id, value);
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactory.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactory.java
index ff2ad71..e4ee864 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactory.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactory.java
@@ -37,7 +37,7 @@ import java.util.Optional;
* Prometheus metrics wrapper factory.
*/
@Slf4j
-public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
+public class PrometheusWrapperFactory implements MetricsWrapperFactory {
private static List metrics;
@@ -102,14 +102,12 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
return createHistogram(metric);
case "SUMMARY":
return createSummary(metric);
- case "DELEGATE":
- return Optional.of(new DelegateWrapper(id));
default:
return Optional.empty();
}
}
- private Optional<MetricsWrapper> createCounter(final Map metric) {
+ protected Optional<MetricsWrapper> createCounter(final Map metric) {
Counter.Builder builder = Counter.build()
.name(getName(metric))
.help(getHelp(metric));
@@ -121,7 +119,7 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
return Optional.of(wrapper);
}
- private Optional<MetricsWrapper> createGauge(final Map metric) {
+ protected Optional<MetricsWrapper> createGauge(final Map metric) {
Gauge.Builder builder = Gauge.build()
.name(getName(metric))
.help(getHelp(metric));
@@ -133,7 +131,7 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
return Optional.of(wrapper);
}
- private Optional<MetricsWrapper> createHistogram(final Map metric) {
+ protected Optional<MetricsWrapper> createHistogram(final Map metric) {
Histogram.Builder builder = Histogram.build()
.name(getName(metric))
.help(getHelp(metric));
@@ -148,7 +146,7 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
return Optional.of(wrapper);
}
- private Optional<MetricsWrapper> createSummary(final Map metric) {
+ protected Optional<MetricsWrapper> createSummary(final Map metric) {
Summary.Builder builder = Summary.build()
.name(getName(metric))
.help(getHelp(metric));
@@ -160,7 +158,7 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
return Optional.of(wrapper);
}
- private void parserHistogramProps(final Histogram.Builder builder, final Map props) {
+ protected void parserHistogramProps(final Histogram.Builder builder, final Map props) {
if (null == props.get("buckets")) {
return;
}
@@ -178,31 +176,31 @@ public final class PrometheusWrapperFactory implements MetricsWrapperFactory {
}
}
- private Optional<Map> findById(final String id) {
+ protected Optional<Map> findById(final String id) {
return metrics.stream().filter(m -> id.equals(getId((Map) m))).findFirst();
}
- private String getId(final Map metric) {
+ protected String getId(final Map metric) {
return (String) metric.get("id");
}
- private String getType(final Map metric) {
+ protected String getType(final Map metric) {
return (String) metric.get("type");
}
- private String getName(final Map metric) {
+ protected String getName(final Map metric) {
return (String) metric.get("name");
}
- private String getHelp(final Map metric) {
+ protected String getHelp(final Map metric) {
return (String) metric.get("help");
}
- private List<String> getLabels(final Map metric) {
+ protected List<String> getLabels(final Map metric) {
return (List<String>) metric.get("labels");
}
- private Map getProps(final Map metric) {
+ protected Map getProps(final Map metric) {
return (Map) metric.get("props");
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/resources/metrics.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/resources/metrics.yaml
index 600b037..530932d 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/resources/metrics.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/resources/metrics.yaml
@@ -24,10 +24,6 @@ metrics:
type: GAUGE
name: proxy_connection_total
help: the shardingsphere proxy connection total
- - id: hikari_set_metrics_factory
- type: DELEGATE
- name:
- help:
- id: proxy_execute_latency_millis
type: HISTOGRAM
name: proxy_execute_latency_millis
@@ -42,26 +38,6 @@ metrics:
type: COUNTER
name: proxy_execute_error_total
help: the shardingsphere proxy executor error
- - id: proxy_request_bytes
- name: proxy_request_bytes
- type: HISTOGRAM
- help: the shardingsphere proxy request bytes
- props:
- buckets:
- type: exp
- start: 4
- factor: 2
- count: 10
- - id: proxy_response_bytes
- name: proxy_response_bytes
- type: HISTOGRAM
- help: the shardingsphere proxy response bytes
- props:
- buckets:
- type: exp
- start: 4
- factor: 2
- count: 10
- id: route_sql_select_total
name: route_sql_select_total
type: COUNTER
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/handler/PrometheusMetricsHandlerTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/handler/PrometheusMetricsHandlerTest.java
deleted file mode 100644
index 6290904..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/handler/PrometheusMetricsHandlerTest.java
+++ /dev/null
@@ -1,40 +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.metrics.prometheus.handler;
-
-import com.zaxxer.hikari.HikariDataSource;
-import org.apache.shardingsphere.agent.metrics.api.MetricsWrapper;
-import org.apache.shardingsphere.agent.metrics.prometheus.wrapper.PrometheusWrapperFactory;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.junit.Assert.assertNotNull;
-
-public final class PrometheusMetricsHandlerTest {
-
- @Test
- public void assertHandle() {
- PrometheusWrapperFactory factory = new PrometheusWrapperFactory();
- Optional<MetricsWrapper> delegateWrapper = factory.create("hikari_set_metrics_factory");
- assertNotNull(delegateWrapper.get());
- HikariDataSource dataSource = new HikariDataSource();
- PrometheusMetricsHandler.handle("hikari_set_metrics_factory", dataSource);
- assertNotNull(dataSource.getMetricsTrackerFactory());
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerFactoryTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerFactoryTest.java
deleted file mode 100644
index 0e07e8a..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerFactoryTest.java
+++ /dev/null
@@ -1,62 +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.metrics.prometheus.hikari;
-
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
-import io.prometheus.client.CollectorRegistry;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class HikariMetricsTrackerFactoryTest {
-
- @Mock
- private PoolStats poolStats;
-
- @Test
- public void assertObserve() {
- when(poolStats.getActiveConnections()).thenReturn(1);
- when(poolStats.getIdleConnections()).thenReturn(5);
- when(poolStats.getMaxConnections()).thenReturn(100);
- when(poolStats.getMinConnections()).thenReturn(1);
- when(poolStats.getPendingThreads()).thenReturn(0);
- when(poolStats.getTotalConnections()).thenReturn(50);
- HikariMetricsTrackerFactory factory = HikariMetricsTrackerFactory.getInstance(CollectorRegistry.defaultRegistry);
- HikariMetricsTracker tracker = (HikariMetricsTracker) factory.create("pool-1", poolStats);
- HikariPoolStatCollector collector = (HikariPoolStatCollector) ReflectiveUtil.getFieldValue(tracker, "HIKARI_POOL_STAT_COLLECTOR");
- assertNotNull(collector);
- List<Collector.MetricFamilySamples> data = collector.collect();
- assertThat(data.size(), is(6));
- assertThat(data.get(0).samples.size(), is(1));
- tracker.close();
- data = collector.collect();
- assertThat(data.size(), is(6));
- assertThat(data.get(0).samples.size(), is(0));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerTest.java
deleted file mode 100644
index 3475263..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariMetricsTrackerTest.java
+++ /dev/null
@@ -1,61 +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.metrics.prometheus.hikari;
-
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
-import io.prometheus.client.CollectorRegistry;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class HikariMetricsTrackerTest {
-
- @Mock
- private PoolStats poolStats;
-
- @Test
- public void assertCollect() {
- when(poolStats.getActiveConnections()).thenReturn(1);
- when(poolStats.getIdleConnections()).thenReturn(5);
- when(poolStats.getMaxConnections()).thenReturn(100);
- when(poolStats.getMinConnections()).thenReturn(1);
- when(poolStats.getPendingThreads()).thenReturn(0);
- when(poolStats.getTotalConnections()).thenReturn(50);
- HikariMetricsTracker tracker = new HikariMetricsTracker("pool-1", poolStats, CollectorRegistry.defaultRegistry);
- HikariPoolStatCollector collector = (HikariPoolStatCollector) ReflectiveUtil.getFieldValue(tracker, "HIKARI_POOL_STAT_COLLECTOR");
- assertNotNull(collector);
- List<Collector.MetricFamilySamples> data = collector.collect();
- assertThat(data.size(), is(6));
- assertThat(data.get(0).samples.size(), is(1));
- tracker.close();
- data = collector.collect();
- assertThat(data.size(), is(6));
- assertThat(data.get(0).samples.size(), is(0));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariPoolStatCollectorTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariPoolStatCollectorTest.java
deleted file mode 100644
index de0e2c6..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariPoolStatCollectorTest.java
+++ /dev/null
@@ -1,57 +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.metrics.prometheus.hikari;
-
-import com.zaxxer.hikari.metrics.PoolStats;
-import io.prometheus.client.Collector;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class HikariPoolStatCollectorTest {
-
- @Mock
- private PoolStats poolStats;
-
- @Test
- public void assertCollect() {
- when(poolStats.getActiveConnections()).thenReturn(1);
- when(poolStats.getIdleConnections()).thenReturn(5);
- when(poolStats.getMaxConnections()).thenReturn(100);
- when(poolStats.getMinConnections()).thenReturn(1);
- when(poolStats.getPendingThreads()).thenReturn(0);
- when(poolStats.getTotalConnections()).thenReturn(50);
- HikariPoolStatCollector collector = new HikariPoolStatCollector();
- collector.addPoolStats("pool-1", poolStats);
- List<Collector.MetricFamilySamples> data = collector.collect();
- assertThat(data.size(), is(6));
- assertThat(data.get(0).samples.size(), is(1));
- collector.removePoolStats("pool-1");
- data = collector.collect();
- assertThat(data.size(), is(6));
- assertThat(data.get(0).samples.size(), is(0));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariSimpleMetricsTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariSimpleMetricsTest.java
deleted file mode 100644
index 26d96d5..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/hikari/HikariSimpleMetricsTest.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.metrics.prometheus.hikari;
-
-import io.prometheus.client.Counter;
-import io.prometheus.client.Histogram;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
-import org.hamcrest.Matchers;
-import org.junit.Test;
-
-public final class HikariSimpleMetricsTest {
-
- @Test
- public void assertObserve() {
- HikariSimpleMetrics simpleMetrics = new HikariSimpleMetrics("pool-1");
- simpleMetrics.observe(org.apache.shardingsphere.agent.metrics.prometheus.hikari.HikariSimpleMetrics.MetricsType.CONNECTION_ACQUIRED_NANOS, 100);
- simpleMetrics.observe(org.apache.shardingsphere.agent.metrics.prometheus.hikari.HikariSimpleMetrics.MetricsType.CONNECTION_USAGE_MILLIS, 10);
- simpleMetrics.observe(org.apache.shardingsphere.agent.metrics.prometheus.hikari.HikariSimpleMetrics.MetricsType.CONNECTION_CREATED_MILLIS, 5);
- simpleMetrics.observe(org.apache.shardingsphere.agent.metrics.prometheus.hikari.HikariSimpleMetrics.MetricsType.CONNECTION_TIMEOUT_COUNT, 1);
- Histogram.Child elapsedAcquiredChild = (Histogram.Child) ReflectiveUtil.getFieldValue(simpleMetrics, "elapsedAcquiredChild");
- org.hamcrest.MatcherAssert.assertThat(elapsedAcquiredChild.get().sum, Matchers.is(100.0));
- Histogram.Child elapsedUsageChild = (Histogram.Child) ReflectiveUtil.getFieldValue(simpleMetrics, "elapsedUsageChild");
- org.hamcrest.MatcherAssert.assertThat(elapsedUsageChild.get().sum, Matchers.is(10.0));
- Histogram.Child elapsedCreationChild = (Histogram.Child) ReflectiveUtil.getFieldValue(simpleMetrics, "elapsedCreationChild");
- org.hamcrest.MatcherAssert.assertThat(elapsedCreationChild.get().sum, Matchers.is(5.0));
- Counter.Child connectionTimeoutCounterChild = (Counter.Child) ReflectiveUtil.getFieldValue(simpleMetrics, "connectionTimeoutCounterChild");
- org.hamcrest.MatcherAssert.assertThat(connectionTimeoutCounterChild.get(), Matchers.is(1.0));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/DelegateWrapperTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/DelegateWrapperTest.java
deleted file mode 100644
index 11b98b6..0000000
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/DelegateWrapperTest.java
+++ /dev/null
@@ -1,33 +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.metrics.prometheus.wrapper;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-
-public final class DelegateWrapperTest {
-
- @Test
- public void assertCreate() {
- Object a = new Object();
- DelegateWrapper delegateWrapper = new DelegateWrapper("a");
- delegateWrapper.delegate(a);
- assertNotNull(delegateWrapper);
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java
index 49c2e79..e8476d2 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/PrometheusWrapperFactoryTest.java
@@ -39,7 +39,5 @@ public final class PrometheusWrapperFactoryTest {
assertNotNull(histogramWrapper2.get());
Optional<MetricsWrapper> summaryWrapper = factory.create("e");
assertNotNull(summaryWrapper.get());
- Optional<MetricsWrapper> delegateWrapper = factory.create("test");
- assertNotNull(delegateWrapper.get());
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/resources/metrics.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/resources/metrics.yaml
index ac4545a..78d535a 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/resources/metrics.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/resources/metrics.yaml
@@ -52,14 +52,6 @@ metrics:
name: proxy_execute_latency_mins
help: proxy execute latency mins
props:
- - id: test
- type: DELEGATE
- name:
- help:
- - id: hikari_set_metrics_factory
- type: DELEGATE
- name:
- help:
- id: proxy_info
name: proxy_info
type: GaugeMetricFamily
diff --git a/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/java/org/apache/shardingsphere/integration/agent/test/metrics/MetricsPluginIT.java b/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/java/org/apache/shardingsphere/integration/agent/test/metrics/MetricsPluginIT.java
index af80e63..3e844b9 100644
--- a/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/java/org/apache/shardingsphere/integration/agent/test/metrics/MetricsPluginIT.java
+++ b/shardingsphere-test/shardingsphere-integration-agent-test/shardingsphere-integration-agent-test-plugins/shardingsphere-integration-agent-test-metrics/src/test/java/org/apache/shardingsphere/integration/agent/test/metrics/MetricsPluginIT.java
@@ -48,10 +48,6 @@ public final class MetricsPluginIT {
public static final String PROXY_EXECUTE_ERROR = "proxy_execute_error_total";
- public static final String PROXY_REQUEST_BYTES = "proxy_request_bytes";
-
- public static final String PROXY_RESPONSE_BYTES = "proxy_response_bytes";
-
public static final String SQL_SELECT = "sql_select_total";
public static final String SQL_UPDATE = "sql_update_total";
@@ -123,8 +119,6 @@ public final class MetricsPluginIT {
result.add(TRANSACTION_COMMIT);
result.add(TRANSACTION_ROLLBACK);
result.add(PROXY_EXECUTE_ERROR);
- result.add(PROXY_REQUEST_BYTES);
- result.add(PROXY_RESPONSE_BYTES);
return result;
}