TeslaCN commented on a change in pull request #11585:
URL: https://github.com/apache/shardingsphere/pull/11585#discussion_r679804748



##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L.
+     */
+    default void counterInc() {
+        counterInc(1L);
+    }
+    
+    /**
+     * Counter increase by value with labels.
+     *
+     * @param value  value
+     * @param labels counter labels
+     */
+    default void counterInc(long value, String... labels) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L with labels.
+     *
+     * @param labels counter labels
+     */
+    default void counterInc(String... labels) {
+        counterInc(1, labels);
+    }
+    
+    /**
+     * Gauge increase by 1L.
+     */
+    default void gaugeInc() {
+        gaugeInc(1L);
+    }
+    
+    /**
+     * Gauge increase by value.
+     *
+     * @param value value
+     */
+    default void gaugeInc(double value) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsPool.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Metrics pool.
+ */
+public final class MetricsPool {
+    
+    private static final ConcurrentHashMap<String, MetricsWrapper> 
METRICS_POOL = new ConcurrentHashMap<>();
+    
+    private static MetricsWrapperFactory wrapperFactory;
+    
+    /**
+     * Set the metrics wrapper factory.
+     *
+     * @param factory MetricsWrapperFactory
+     */
+    public static void setMetricsFactory(final MetricsWrapperFactory factory) {
+        wrapperFactory = factory;
+    }
+    
+    /**
+     * Create metrics wrapper by id.
+     *
+     * @param id id
+     */
+    public static void create(final String id) {
+        Optional<MetricsWrapper> wrapper = wrapperFactory.create(id);
+        wrapper.ifPresent(w -> METRICS_POOL.put(id, w));
+    }
+    
+    /**
+     * Get the metrics wrapper by id.
+     *
+     * @param id id
+     * @return optional of metrics wrapper
+     */
+    public static Optional<MetricsWrapper> get(final String id) {
+        if (METRICS_POOL.containsKey(id)) {

Review comment:
       Consider simplifying by `Optional.ofNullable`.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L.
+     */
+    default void counterInc() {
+        counterInc(1L);
+    }
+    
+    /**
+     * Counter increase by value with labels.
+     *
+     * @param value  value
+     * @param labels counter labels
+     */
+    default void counterInc(long value, String... labels) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L with labels.
+     *
+     * @param labels counter labels
+     */
+    default void counterInc(String... labels) {
+        counterInc(1, labels);
+    }
+    
+    /**
+     * Gauge increase by 1L.
+     */
+    default void gaugeInc() {
+        gaugeInc(1L);
+    }
+    
+    /**
+     * Gauge increase by value.
+     *
+     * @param value value
+     */
+    default void gaugeInc(double value) {
+        
+    }
+    
+    /**
+     * Gauge decrease by 1L.
+     */
+    default void gaugeDec() {
+        gaugeDec(1L);
+    }
+    
+    /**
+     * Gauge decrease by value.
+     *
+     * @param value value
+     */
+    default void gaugeDec(double value) {
+        
+    }
+    
+    /**
+     * Histogram observed by value.
+     *
+     * @param value value
+     */
+    default void histogramObserve(double value) {
+        
+    }
+    
+    /**
+     * Summary observed by value.
+     *
+     * @param value value
+     */
+    default void summaryObserve(double value) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/advice/TransactionAdvice.java
##########
@@ -17,34 +17,35 @@
 
 package org.apache.shardingsphere.agent.metrics.api.advice;
 
-import java.lang.reflect.Method;
+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.api.advice.AdviceTargetObject;
-import org.apache.shardingsphere.agent.metrics.api.reporter.MetricsReporter;
-import org.apache.shardingsphere.agent.metrics.api.constant.MethodNameConstant;
+import org.apache.shardingsphere.agent.metrics.api.MetricsPool;
+import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
+
+import java.lang.reflect.Method;
 
 /**
  * Transaction advice.
  */
 public final class TransactionAdvice implements InstanceMethodAroundAdvice {
     
-    private static final String COMMIT = "proxy_transaction_commit_total";
+    public static final String COMMIT = "commit";
     
-    private static final String ROLLBACK = "proxy_transaction_rollback_total";
+    public static final String ROLL_BACK = "rollback";

Review comment:
       Maybe `ROLLBACK` is better?

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L.
+     */
+    default void counterInc() {
+        counterInc(1L);
+    }
+    
+    /**
+     * Counter increase by value with labels.
+     *
+     * @param value  value
+     * @param labels counter labels
+     */
+    default void counterInc(long value, String... labels) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L with labels.
+     *
+     * @param labels counter labels
+     */
+    default void counterInc(String... labels) {
+        counterInc(1, labels);
+    }
+    
+    /**
+     * Gauge increase by 1L.
+     */
+    default void gaugeInc() {
+        gaugeInc(1L);
+    }
+    
+    /**
+     * Gauge increase by value.
+     *
+     * @param value value
+     */
+    default void gaugeInc(double value) {
+        
+    }
+    
+    /**
+     * Gauge decrease by 1L.
+     */
+    default void gaugeDec() {
+        gaugeDec(1L);
+    }
+    
+    /**
+     * Gauge decrease by value.
+     *
+     * @param value value
+     */
+    default void gaugeDec(double value) {
+        
+    }
+    
+    /**
+     * Histogram observed by value.
+     *
+     * @param value value
+     */
+    default void histogramObserve(double value) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L.
+     */
+    default void counterInc() {
+        counterInc(1L);
+    }
+    
+    /**
+     * Counter increase by value with labels.
+     *
+     * @param value  value
+     * @param labels counter labels
+     */
+    default void counterInc(long value, String... labels) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L with labels.
+     *
+     * @param labels counter labels
+     */
+    default void counterInc(String... labels) {
+        counterInc(1, labels);
+    }
+    
+    /**
+     * Gauge increase by 1L.
+     */
+    default void gaugeInc() {
+        gaugeInc(1L);
+    }
+    
+    /**
+     * Gauge increase by value.
+     *
+     * @param value value
+     */
+    default void gaugeInc(double value) {
+        
+    }
+    
+    /**
+     * Gauge decrease by 1L.
+     */
+    default void gaugeDec() {
+        gaugeDec(1L);
+    }
+    
+    /**
+     * Gauge decrease by value.
+     *
+     * @param value value
+     */
+    default void gaugeDec(double value) {
+        
+    }
+    
+    /**
+     * Histogram observed by value.
+     *
+     * @param value value
+     */
+    default void histogramObserve(double value) {
+        
+    }
+    
+    /**
+     * Summary observed by value.
+     *
+     * @param value value
+     */
+    default void summaryObserve(double value) {
+        
+    }
+    
+    /**
+     * Delegated with object.
+     *
+     * @param object object
+     */
+    default void delegate(Object object) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L.
+     */
+    default void counterInc() {
+        counterInc(1L);
+    }
+    
+    /**
+     * Counter increase by value with labels.
+     *
+     * @param value  value
+     * @param labels counter labels
+     */
+    default void counterInc(long value, String... labels) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsWrapper.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+/**
+ * Metrics wrapper.
+ */
+public interface MetricsWrapper {
+    
+    /**
+     * Counter increase by value.
+     *
+     * @param value value
+     */
+    default void counterInc(long value) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L.
+     */
+    default void counterInc() {
+        counterInc(1L);
+    }
+    
+    /**
+     * Counter increase by value with labels.
+     *
+     * @param value  value
+     * @param labels counter labels
+     */
+    default void counterInc(long value, String... labels) {
+        
+    }
+    
+    /**
+     * Counter increase by 1L with labels.
+     *
+     * @param labels counter labels
+     */
+    default void counterInc(String... labels) {
+        counterInc(1, labels);
+    }
+    
+    /**
+     * Gauge increase by 1L.
+     */
+    default void gaugeInc() {
+        gaugeInc(1L);
+    }
+    
+    /**
+     * Gauge increase by value.
+     *
+     * @param value value
+     */
+    default void gaugeInc(double value) {
+        
+    }
+    
+    /**
+     * Gauge decrease by 1L.
+     */
+    default void gaugeDec() {
+        gaugeDec(1L);
+    }
+    
+    /**
+     * Gauge decrease by value.
+     *
+     * @param value value
+     */
+    default void gaugeDec(double value) {
+        

Review comment:
       Remove redundant blank line.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml
##########
@@ -49,3 +49,10 @@ interceptors:
     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

Review comment:
       Add a line break.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to