You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/04/29 13:44:40 UTC

[GitHub] [shardingsphere] kimmking commented on a change in pull request #5382: build base framework for metrics

kimmking commented on a change in pull request #5382:
URL: https://github.com/apache/shardingsphere/pull/5382#discussion_r417254085



##########
File path: sharding-metrics/sharding-metrics-facade/pom.xml
##########
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>sharding-metrics</artifactId>
+        <groupId>org.apache.shardingsphere</groupId>
+        <version>5.0.0-RC1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sharding-metrics-facade</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>sharding-metrics-spi</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+    </dependencies>
+

Review comment:
       one more line

##########
File path: sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.metrics.facade;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.metrics.api.CounterMetricsTracker;
+import org.apache.shardingsphere.metrics.api.GaugeMetricsTracker;
+import org.apache.shardingsphere.metrics.api.HistogramMetricsTracker;
+import org.apache.shardingsphere.metrics.api.HistogramMetricsTrackerDelegate;
+import org.apache.shardingsphere.metrics.api.MetricsTracker;
+import org.apache.shardingsphere.metrics.api.NoneHistogramMetricsTrackerDelegate;
+import org.apache.shardingsphere.metrics.api.NoneSummaryMetricsTrackerDelegate;
+import org.apache.shardingsphere.metrics.api.SummaryMetricsTracker;
+import org.apache.shardingsphere.metrics.api.SummaryMetricsTrackerDelegate;
+import org.apache.shardingsphere.metrics.enums.MetricsTypeEnum;
+import org.apache.shardingsphere.metrics.spi.MetricsTrackerManager;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Metrics tracker facade.
+ */
+@Slf4j
+public final class MetricsTrackerFacade {
+    
+    private static final Map<String, MetricsTrackerManager> METRICS_MAP = new HashMap<>();
+    
+    private static final MetricsTrackerFacade INSTANCE = new MetricsTrackerFacade();
+    
+    private volatile AtomicBoolean isInit = new AtomicBoolean(false);
+    
+    private Optional<MetricsTrackerManager> metricsTrackerManager = Optional.empty();
+    
+    private MetricsTrackerFacade() {
+        loadMetricsManager();
+    }
+    
+    /**
+     * Get metrics tracker facade.
+     *
+     * @return metrics tracker facade
+     */
+    public static MetricsTrackerFacade getInstance() {
+        return INSTANCE;
+    }
+    
+    /**
+     * Find metrics tracker manager.
+     *
+     * @param metricsName  metrics name
+     * @return metrics tracker manager
+     */
+    public Optional<MetricsTrackerManager> findMetricsTrackerManager(final String metricsName) {
+        return Optional.ofNullable(METRICS_MAP.get(metricsName));
+    }
+    
+    /**
+     * Init for metrics tracker manager.
+     *
+     * @param metricsName metrics name
+     * @param port port
+     */
+    public void init(final String metricsName, final int port) {
+        if (!isInit.compareAndSet(false, true)) {
+            return;
+        }
+        metricsTrackerManager = findMetricsTrackerManager(metricsName);
+        metricsTrackerManager.ifPresent(manager -> manager.init(port));
+    }
+    
+    /**
+     * Inc of counter metrics tracker.

Review comment:
       Increment instead

##########
File path: sharding-metrics/sharding-metrics-spi/pom.xml
##########
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>sharding-metrics</artifactId>
+        <groupId>org.apache.shardingsphere</groupId>
+        <version>5.0.0-RC1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sharding-metrics-spi</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-spi</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+

Review comment:
       one more

##########
File path: sharding-metrics/sharding-metrics-prometheus/pom.xml
##########
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>sharding-metrics</artifactId>
+        <groupId>org.apache.shardingsphere</groupId>
+        <version>5.0.0-RC1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sharding-metrics-prometheus</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>sharding-metrics-spi</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.16.20</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.prometheus</groupId>
+            <artifactId>simpleclient</artifactId>
+            <version>0.6.0</version>

Review comment:
       move to root pom




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org