This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 4ddbd2c0953 Split CommandExecutorTaskAdvice to
ExecuteLatencyHistogramAdvice and ExecuteErrorsCountAdvice (#23484)
4ddbd2c0953 is described below
commit 4ddbd2c09534a747fadf837e95285c54c0197db6
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 11 05:23:17 2023 +0800
Split CommandExecutorTaskAdvice to ExecuteLatencyHistogramAdvice and
ExecuteErrorsCountAdvice (#23484)
---
.../proxy/CurrentConnectionsCountAdvice.java | 6 +-
...ntAdvice.java => ExecuteErrorsCountAdvice.java} | 10 ++--
.../ExecuteLatencyHistogramAdvice.java} | 30 +++-------
...tsCountAdvice.java => RequestsCountAdvice.java} | 4 +-
.../plugin/metrics/core/constant/MetricIds.java | 4 +-
.../core/advice/CommandExecutorTaskAdviceTest.java | 70 ----------------------
.../metrics/core/advice/MetricsAdviceBaseTest.java | 4 +-
.../proxy/CurrentConnectionsCountAdviceTest.java | 6 +-
...Test.java => ExecuteErrorsCountAdviceTest.java} | 14 ++---
...java => ExecuteLatencyHistogramAdviceTest.java} | 15 ++---
...dviceTest.java => RequestsCountAdviceTest.java} | 6 +-
.../META-INF/conf/prometheus-metrics.yaml | 12 ++--
.../META-INF/conf/prometheus-proxy-advisors.yaml | 7 ++-
.../observability/_index.cn.md | 2 +-
.../observability/_index.en.md | 6 +-
.../test/e2e/agent/metrics/MetricsPluginE2EIT.java | 12 ++--
16 files changed, 65 insertions(+), 143 deletions(-)
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 f408be825ff..3c8cf1108ed 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
@@ -31,17 +31,17 @@ import java.lang.reflect.Method;
public final class CurrentConnectionsCountAdvice implements
InstanceMethodAdvice {
static {
- MetricsPool.create(MetricIds.CURRENT_PROXY_CONNECTIONS);
+ MetricsPool.create(MetricIds.PROXY_CURRENT_CONNECTIONS);
}
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args) {
switch (method.getName()) {
case "channelActive":
-
MetricsPool.get(MetricIds.CURRENT_PROXY_CONNECTIONS).ifPresent(MetricsWrapper::inc);
+
MetricsPool.get(MetricIds.PROXY_CURRENT_CONNECTIONS).ifPresent(MetricsWrapper::inc);
break;
case "channelInactive":
-
MetricsPool.get(MetricIds.CURRENT_PROXY_CONNECTIONS).ifPresent(MetricsWrapper::dec);
+
MetricsPool.get(MetricIds.PROXY_CURRENT_CONNECTIONS).ifPresent(MetricsWrapper::dec);
break;
default:
break;
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
similarity index 77%
copy from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdvice.java
copy to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
index bc79a4440aa..aed040e4ec2 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
@@ -26,16 +26,16 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.constant.MetricIds;
import java.lang.reflect.Method;
/**
- * Total requests count advice for ShardingSphere-Proxy.
+ * Execute errors count advice for ShardingSphere-Proxy.
*/
-public final class TotalRequestsCountAdvice implements InstanceMethodAdvice {
+public final class ExecuteErrorsCountAdvice implements InstanceMethodAdvice {
static {
- MetricsPool.create(MetricIds.PROXY_REQUESTS);
+ MetricsPool.create(MetricIds.PROXY_EXECUTE_ERRORS);
}
@Override
- public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args) {
-
MetricsPool.get(MetricIds.PROXY_REQUESTS).ifPresent(MetricsWrapper::inc);
+ public void afterMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final Object result) {
+
MetricsPool.get(MetricIds.PROXY_EXECUTE_ERRORS).ifPresent(MetricsWrapper::inc);
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/CommandExecutorTaskAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
similarity index 62%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/CommandExecutorTaskAdvice.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
index 8046bcddde5..ae774f68c14 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/CommandExecutorTaskAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
@@ -15,48 +15,36 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+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.util.TimeRecorder;
import org.apache.shardingsphere.agent.plugin.metrics.core.MetricsPool;
-import org.apache.shardingsphere.agent.plugin.metrics.core.MetricsWrapper;
import org.apache.shardingsphere.agent.plugin.metrics.core.constant.MetricIds;
-import org.apache.shardingsphere.agent.plugin.core.util.TimeRecorder;
import java.lang.reflect.Method;
/**
- * Command executor task advice.
+ * Execute latency histogram advance for ShardingSphere-Proxy.
*/
-public final class CommandExecutorTaskAdvice implements InstanceMethodAdvice {
-
- public static final String COMMAND_EXECUTOR_RUN = "run";
-
- public static final String COMMAND_EXECUTOR_EXCEPTION = "processException";
+public final class ExecuteLatencyHistogramAdvice implements
InstanceMethodAdvice {
static {
- MetricsPool.create(MetricIds.PROXY_EXECUTE_ERROR);
MetricsPool.create(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS);
}
@Override
public void beforeMethod(final TargetAdviceObject target, final Method
method, final Object[] args) {
- if (COMMAND_EXECUTOR_RUN.equals(method.getName())) {
- TimeRecorder.INSTANCE.record();
- }
+ TimeRecorder.INSTANCE.record();
}
@Override
public void afterMethod(final TargetAdviceObject target, final Method
method, final Object[] args, final Object result) {
- if (COMMAND_EXECUTOR_RUN.equals(method.getName())) {
- try {
-
MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).ifPresent(optional ->
optional.observe(TimeRecorder.INSTANCE.getElapsedTime()));
- } finally {
- TimeRecorder.INSTANCE.clean();
- }
- } else if (COMMAND_EXECUTOR_EXCEPTION.equals(method.getName())) {
-
MetricsPool.get(MetricIds.PROXY_EXECUTE_ERROR).ifPresent(MetricsWrapper::inc);
+ try {
+
MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).ifPresent(optional ->
optional.observe(TimeRecorder.INSTANCE.getElapsedTime()));
+ } finally {
+ TimeRecorder.INSTANCE.clean();
}
}
}
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
similarity index 92%
rename from
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdvice.java
rename to
agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
index bc79a4440aa..9036816e0bd 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
@@ -26,9 +26,9 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.constant.MetricIds;
import java.lang.reflect.Method;
/**
- * Total requests count advice for ShardingSphere-Proxy.
+ * Requests count advice for ShardingSphere-Proxy.
*/
-public final class TotalRequestsCountAdvice implements InstanceMethodAdvice {
+public final class RequestsCountAdvice implements InstanceMethodAdvice {
static {
MetricsPool.create(MetricIds.PROXY_REQUESTS);
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/constant/MetricIds.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/constant/MetricIds.java
index 3377e283b58..7362de3ed2d 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/constant/MetricIds.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/constant/MetricIds.java
@@ -24,11 +24,11 @@ public final class MetricIds {
public static final String PROXY_REQUESTS = "proxy_requests_total";
- public static final String CURRENT_PROXY_CONNECTIONS =
"current_proxy_connections";
+ public static final String PROXY_CURRENT_CONNECTIONS =
"current_proxy_connections";
public static final String PROXY_EXECUTE_LATENCY_MILLIS =
"proxy_execute_latency_millis";
- public static final String PROXY_EXECUTE_ERROR =
"proxy_execute_error_total";
+ public static final String PROXY_EXECUTE_ERRORS =
"proxy_execute_errors_total";
public static final String ROUTE_SQL_SELECT = "route_sql_select_total";
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/CommandExecutorTaskAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/CommandExecutorTaskAdviceTest.java
deleted file mode 100644
index b5d03d4f997..00000000000
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/CommandExecutorTaskAdviceTest.java
+++ /dev/null
@@ -1,70 +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.advice;
-
-import org.apache.shardingsphere.agent.plugin.metrics.core.MetricsPool;
-import org.apache.shardingsphere.agent.plugin.metrics.core.constant.MetricIds;
-import
org.apache.shardingsphere.agent.plugin.metrics.core.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.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class CommandExecutorTaskAdviceTest extends MetricsAdviceBaseTest
{
-
- @Mock
- private Method run;
-
- @Mock
- private Method processException;
-
- @Test
- public void assertExecuteLatency() {
-
when(run.getName()).thenReturn(CommandExecutorTaskAdvice.COMMAND_EXECUTOR_RUN);
- CommandExecutorTaskAdvice advice = new CommandExecutorTaskAdvice();
- MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
- advice.beforeMethod(targetObject, run, new Object[]{});
- try {
- Thread.sleep(500L);
- } catch (final InterruptedException ex) {
- ex.printStackTrace();
- }
- advice.afterMethod(targetObject, run, new Object[]{}, null);
- FixtureWrapper requestWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).get();
-
assertTrue(MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).isPresent());
- assertThat(requestWrapper.getFixtureValue(), greaterThan(0.0));
- }
-
- @Test
- public void assertExecuteErrorTotal() {
-
when(processException.getName()).thenReturn(CommandExecutorTaskAdvice.COMMAND_EXECUTOR_EXCEPTION);
- MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
- new CommandExecutorTaskAdvice().afterMethod(targetObject,
processException, new Object[]{}, null);
- FixtureWrapper requestWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_EXECUTE_ERROR).get();
- assertTrue(MetricsPool.get(MetricIds.PROXY_EXECUTE_ERROR).isPresent());
- assertThat(requestWrapper.getFixtureValue(), greaterThan(0.0));
- }
-}
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 658ed8e55a3..bc9e8cadb55 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
@@ -33,7 +33,9 @@ public abstract class MetricsAdviceBaseTest {
@After
public void reset() {
-
MetricsPool.get(MetricIds.CURRENT_PROXY_CONNECTIONS).ifPresent(optional ->
((FixtureWrapper) optional).reset());
+
MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).ifPresent(optional ->
((FixtureWrapper) optional).reset());
+ MetricsPool.get(MetricIds.PROXY_EXECUTE_ERRORS).ifPresent(optional ->
((FixtureWrapper) optional).reset());
+
MetricsPool.get(MetricIds.PROXY_CURRENT_CONNECTIONS).ifPresent(optional ->
((FixtureWrapper) optional).reset());
MetricsPool.get(MetricIds.PROXY_REQUESTS).ifPresent(optional ->
((FixtureWrapper) optional).reset());
}
}
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 43e6544a172..ddf108a0006 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
@@ -37,13 +37,13 @@ public final class CurrentConnectionsCountAdviceTest
extends MetricsAdviceBaseTe
private final CurrentConnectionsCountAdvice advice = new
CurrentConnectionsCountAdvice();
@Test
- public void assertBeforeMethod() {
+ public void assertCountCurrentConnections() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
advice.beforeMethod(targetObject, mockMethod("channelActive"), new
Object[]{});
advice.beforeMethod(targetObject, mockMethod("channelActive"), new
Object[]{});
advice.beforeMethod(targetObject, mockMethod("channelInactive"), new
Object[]{});
-
assertTrue(MetricsPool.get(MetricIds.CURRENT_PROXY_CONNECTIONS).isPresent());
- assertThat(((FixtureWrapper)
MetricsPool.get(MetricIds.CURRENT_PROXY_CONNECTIONS).get()).getFixtureValue(),
is(1d));
+
assertTrue(MetricsPool.get(MetricIds.PROXY_CURRENT_CONNECTIONS).isPresent());
+ assertThat(((FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_CURRENT_CONNECTIONS).get()).getFixtureValue(),
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/TotalRequestsCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
similarity index 81%
copy from
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
copy to
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
index 1924bb3317d..a9885a9e1c8 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
@@ -26,20 +26,18 @@ import org.junit.Test;
import java.lang.reflect.Method;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-public final class TotalRequestsCountAdviceTest extends MetricsAdviceBaseTest {
-
- private final TotalRequestsCountAdvice advice = new
TotalRequestsCountAdvice();
+public final class ExecuteErrorsCountAdviceTest extends MetricsAdviceBaseTest {
@Test
- public void assertBeforeMethod() {
+ public void assertCountExecuteErrors() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
- advice.beforeMethod(targetObject, mock(Method.class), new Object[]{});
- assertTrue(MetricsPool.get(MetricIds.PROXY_REQUESTS).isPresent());
- assertThat(((FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_REQUESTS).get()).getFixtureValue(), is(1d));
+ new ExecuteErrorsCountAdvice().afterMethod(targetObject,
mock(Method.class), new Object[]{}, null);
+
assertTrue(MetricsPool.get(MetricIds.PROXY_EXECUTE_ERRORS).isPresent());
+ assertThat(((FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_EXECUTE_ERRORS).get()).getFixtureValue(),
is(1d));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
similarity index 75%
copy from
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
copy to
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
index 1924bb3317d..367eab29142 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
@@ -26,20 +26,21 @@ import org.junit.Test;
import java.lang.reflect.Method;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-public final class TotalRequestsCountAdviceTest extends MetricsAdviceBaseTest {
-
- private final TotalRequestsCountAdvice advice = new
TotalRequestsCountAdvice();
+public final class ExecuteLatencyHistogramAdviceTest extends
MetricsAdviceBaseTest {
@Test
- public void assertBeforeMethod() {
+ public void assertExecuteLatencyHistogram() throws InterruptedException {
+ ExecuteLatencyHistogramAdvice advice = new
ExecuteLatencyHistogramAdvice();
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
advice.beforeMethod(targetObject, mock(Method.class), new Object[]{});
- assertTrue(MetricsPool.get(MetricIds.PROXY_REQUESTS).isPresent());
- assertThat(((FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_REQUESTS).get()).getFixtureValue(), is(1d));
+ Thread.sleep(500L);
+ advice.afterMethod(targetObject, mock(Method.class), new Object[]{},
null);
+
assertTrue(MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).isPresent());
+ assertThat(((FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).get()).getFixtureValue(),
greaterThan(500D));
}
}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
similarity index 90%
rename from
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
rename to
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
index 1924bb3317d..d092af64b42 100644
---
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/TotalRequestsCountAdviceTest.java
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
@@ -31,12 +31,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-public final class TotalRequestsCountAdviceTest extends MetricsAdviceBaseTest {
+public final class RequestsCountAdviceTest extends MetricsAdviceBaseTest {
- private final TotalRequestsCountAdvice advice = new
TotalRequestsCountAdvice();
+ private final RequestsCountAdvice advice = new RequestsCountAdvice();
@Test
- public void assertBeforeMethod() {
+ public void assertCountRequests() {
MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
advice.beforeMethod(targetObject, mock(Method.class), new Object[]{});
assertTrue(MetricsPool.get(MetricIds.PROXY_REQUESTS).isPresent());
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
index a17ca0f7d2f..7ebde285b22 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
+++
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-metrics.yaml
@@ -19,25 +19,25 @@ metrics:
- id: proxy_requests_total
type: COUNTER
name: proxy_requests_total
- help: the total requests of ShardingSphere-Proxy
+ help: total requests of ShardingSphere-Proxy
- id: current_proxy_connections
type: GAUGE
name: current_proxy_connections
- help: the current connections of ShardingSphere-Proxy
+ help: current connections of ShardingSphere-Proxy
- id: proxy_execute_latency_millis
type: HISTOGRAM
name: proxy_execute_latency_millis
- help: the executor latency millis of ShardingSphere-Proxy
+ help: execute latency millis of ShardingSphere-Proxy
props:
buckets:
type: exp
start: 1
factor: 2
count: 13
- - id: proxy_execute_error_total
+ - id: proxy_execute_errors_total
type: COUNTER
- name: proxy_execute_error_total
- help: the shardingsphere proxy executor error
+ name: proxy_execute_errors_total
+ help: total execute errors of ShardingSphere-Proxy
- id: route_sql_select_total
name: route_sql_select_total
type: COUNTER
diff --git
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml
index d6af4833e7d..22eac4c3dd7 100644
---
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml
+++
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml
@@ -17,10 +17,13 @@
advisors:
- target:
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
- advice:
org.apache.shardingsphere.agent.plugin.metrics.core.advice.CommandExecutorTaskAdvice
+ advice:
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.ExecuteLatencyHistogramAdvice
pointcuts:
- name: run
type: method
+ - target:
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
+ advice:
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.ExecuteErrorsCountAdvice
+ pointcuts:
- name: processException
type: method
- target:
org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
@@ -31,7 +34,7 @@ advisors:
- name: channelInactive
type: method
- target:
org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
- advice:
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.TotalRequestsCountAdvice
+ advice:
org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.RequestsCountAdvice
pointcuts:
- name: channelRead
type: method
diff --git
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
index fcec790fcd1..3c26d725edf 100644
---
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
+++
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
@@ -159,7 +159,7 @@ services:
| proxy_requests_total | COUNTER | ShardingSphere-Proxy 的接受请求总合
|
| current_proxy_connections | GAUGE | ShardingSphere-Proxy 的当前连接数
|
| proxy_execute_latency_millis | HISTOGRAM | ShardingSphere-Proxy 的执行耗时毫秒
|
-| proxy_execute_error_total | COUNTER | ShardingSphere-Proxy 的执行异常总数
|
+| proxy_execute_errors_total | COUNTER | ShardingSphere-Proxy 的执行异常总数
|
| route_sql_select_total | COUNTER | 路由执行 select SQL 语句总数
|
| route_sql_insert_total | COUNTER | 路由执行 insert SQL 语句总数
|
| route_sql_update_total | COUNTER | 路由执行 update SQL 语句总数
|
diff --git
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
index 2ac67eba421..82e2425f100 100644
---
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
+++
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
@@ -160,9 +160,9 @@ services:
| name | type | description
|
| :------------------------------- | :-------- |
:--------------------------------------------------------------------------------------------------------
|
| proxy_requests_total | COUNTER | total requests of
ShardingSphere-Proxy
|
-| current_proxy_connections | GAUGE | the current connections of
ShardingSphere-Proxy |
-| proxy_execute_latency_millis | HISTOGRAM | the executor latency millis
of ShardingSphere-Proxy |
-| proxy_execute_error_total | COUNTER | proxy executor error total
|
+| current_proxy_connections | GAUGE | current connections of
ShardingSphere-Proxy
|
+| proxy_execute_latency_millis | HISTOGRAM | execute latency millis of
ShardingSphere-Proxy
|
+| proxy_execute_errors_total | COUNTER | total executor errors of
ShardingSphere-Proxy
|
| route_sql_select_total | COUNTER | proxy executor route select
sql total |
| route_sql_insert_total | COUNTER | proxy executor route insert
sql total |
| route_sql_update_total | COUNTER | proxy executor route update
sql total |
diff --git
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
index 5415d6f1205..e7d6485c7eb 100644
---
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
+++
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
@@ -38,13 +38,13 @@ import static org.junit.Assert.assertNotNull;
@Slf4j
public final class MetricsPluginE2EIT extends BasePluginE2EIT {
- public static final String TOTAL_PROXY_REQUESTS = "proxy_requests_total";
+ public static final String PROXY_REQUESTS = "proxy_requests_total";
- public static final String CURRENT_PROXY_CONNECTIONS =
"current_proxy_connections";
+ public static final String PROXY_CURRENT_CONNECTIONS =
"current_proxy_connections";
public static final String PROXY_EXECUTE_LATENCY_MILLIS =
"proxy_execute_latency_millis_bucket";
- public static final String PROXY_EXECUTE_ERROR =
"proxy_execute_error_total";
+ public static final String PROXY_EXECUTE_ERRORS =
"proxy_execute_errors_total";
public static final String SQL_SELECT = "route_sql_select_total";
@@ -87,8 +87,8 @@ public final class MetricsPluginE2EIT extends BasePluginE2EIT
{
private Collection<String> buildMetricsNames() {
Collection<String> result = new LinkedHashSet<>();
- result.add(TOTAL_PROXY_REQUESTS);
- result.add(CURRENT_PROXY_CONNECTIONS);
+ result.add(PROXY_REQUESTS);
+ result.add(PROXY_CURRENT_CONNECTIONS);
result.add(PROXY_EXECUTE_LATENCY_MILLIS);
result.add(SQL_SELECT);
result.add(SQL_UPDATE);
@@ -98,7 +98,7 @@ public final class MetricsPluginE2EIT extends BasePluginE2EIT
{
result.add(ROUTE_TABLE);
result.add(TRANSACTION_COMMIT);
result.add(TRANSACTION_ROLLBACK);
- result.add(PROXY_EXECUTE_ERROR);
+ result.add(PROXY_EXECUTE_ERRORS);
return result;
}