This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 1c463ebd50f Add HistogramBucketUtils (#37162)
1c463ebd50f is described below
commit 1c463ebd50f00ccacfb81fabb2f81c139ac89ca4
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Nov 22 22:49:48 2025 +0800
Add HistogramBucketUtils (#37162)
---
.../AbstractExecuteLatencyHistogramAdvice.java | 14 +------
.../proxy/ExecuteLatencyHistogramAdvice.java | 15 ++------
.../metrics/core/util/HistogramBucketUtils.java | 45 ++++++++++++++++++++++
.../core/util/HistogramBucketUtilsTest.java | 38 ++++++++++++++++++
4 files changed, 88 insertions(+), 24 deletions(-)
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
index 88cfc452305..547981b3504 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/AbstractExecuteLatencyHistogramAdvice.java
@@ -25,10 +25,9 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsColl
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.util.HistogramBucketUtils;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
/**
* Abstract execute latency histogram advice for ShardingSphere-JDBC.
@@ -36,16 +35,7 @@ import java.util.Map;
public abstract class AbstractExecuteLatencyHistogramAdvice extends
AbstractInstanceMethodAdvice {
private final MetricConfiguration config = new
MetricConfiguration("jdbc_statement_execute_latency_millis",
MetricCollectorType.HISTOGRAM,
- "Statement execute latency millis histogram",
Collections.singletonMap("buckets", getBuckets()));
-
- private Map<String, Object> getBuckets() {
- Map<String, Object> result = new HashMap<>(4, 1F);
- result.put("type", "exp");
- result.put("start", 1);
- result.put("factor", 2);
- result.put("count", 13);
- return result;
- }
+ "Statement execute latency millis histogram",
Collections.singletonMap("buckets", HistogramBucketUtils.getBucketsMap()));
@Override
public void beforeMethod(final TargetAdviceObject target, final
TargetAdviceMethod method, final Object[] args, final String pluginType) {
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
index fb666e92917..322eff6e4ce 100644
---
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
@@ -25,11 +25,10 @@ import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsColl
import
org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.HistogramMetricsCollector;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType;
import
org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfiguration;
+import
org.apache.shardingsphere.agent.plugin.metrics.core.util.HistogramBucketUtils;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
/**
* Execute latency histogram advance for ShardingSphere-Proxy.
@@ -37,19 +36,11 @@ import java.util.Map;
public final class ExecuteLatencyHistogramAdvice extends
AbstractInstanceMethodAdvice {
private final MetricConfiguration config = new
MetricConfiguration("proxy_execute_latency_millis",
- MetricCollectorType.HISTOGRAM, "Execute latency millis histogram
of ShardingSphere-Proxy", Collections.emptyList(),
Collections.singletonMap("buckets", getBuckets()));
+ MetricCollectorType.HISTOGRAM, "Execute latency millis histogram
of ShardingSphere-Proxy", Collections.emptyList(),
+ Collections.singletonMap("buckets",
HistogramBucketUtils.getBucketsMap()));
private final MethodTimeRecorder methodTimeRecorder = new
MethodTimeRecorder(ExecuteLatencyHistogramAdvice.class);
- private Map<String, Object> getBuckets() {
- Map<String, Object> result = new HashMap<>(4, 1F);
- result.put("type", "exp");
- result.put("start", 1);
- result.put("factor", 2);
- result.put("count", 13);
- return result;
- }
-
@Override
public void beforeMethod(final TargetAdviceObject target, final
TargetAdviceMethod method, final Object[] args, final String pluginType) {
if (args[2] instanceof QueryCommandExecutor) {
diff --git
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/util/HistogramBucketUtils.java
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/util/HistogramBucketUtils.java
new file mode 100644
index 00000000000..12ad7ac8ed3
--- /dev/null
+++
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/util/HistogramBucketUtils.java
@@ -0,0 +1,45 @@
+/*
+ * 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.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Histogram bucket utils.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class HistogramBucketUtils {
+
+ /**
+ * Get buckets map.
+ *
+ * @return buckets map
+ */
+ public static Map<String, Object> getBucketsMap() {
+ Map<String, Object> result = new HashMap<>(4, 1F);
+ result.put("type", "exp");
+ result.put("start", 1);
+ result.put("factor", 2);
+ result.put("count", 13);
+ return result;
+ }
+}
diff --git
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/util/HistogramBucketUtilsTest.java
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/util/HistogramBucketUtilsTest.java
new file mode 100644
index 00000000000..78d23089328
--- /dev/null
+++
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/util/HistogramBucketUtilsTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.util;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class HistogramBucketUtilsTest {
+
+ @Test
+ void assertGetBuckets() {
+ Map<String, Object> actual = HistogramBucketUtils.getBucketsMap();
+ assertThat(actual.size(), is(4));
+ assertThat(actual.get("type"), is("exp"));
+ assertThat(actual.get("start"), is(1));
+ assertThat(actual.get("factor"), is(2));
+ assertThat(actual.get("count"), is(13));
+ }
+}