zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eolive...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3474: Enable BookKeeper checkstyle configuration on zookeeper-prometheus-metrics
Date Mon, 05 Aug 2019 13:30:02 GMT
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 49354f5  ZOOKEEPER-3474: Enable BookKeeper checkstyle configuration on zookeeper-prometheus-metrics
49354f5 is described below

commit 49354f581f3b88316177492ef28823b50a5b33f7
Author: tison <wander4096@gmail.com>
AuthorDate: Mon Aug 5 15:29:50 2019 +0200

    ZOOKEEPER-3474: Enable BookKeeper checkstyle configuration on zookeeper-prometheus-metrics
    
    Subtasks of ZOOKEEPER-3431. Enable BookKeeper checkstyle configuration on zookeeper-promethus-metrics.
    
    Author: tison <wander4096@gmail.com>
    
    Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org>
    
    Closes #1028 from TisonKun/ZOOKEEPER-3474
---
 pom.xml                                            |  2 +-
 zookeeper-jute/pom.xml                             |  2 +-
 zookeeper-metrics-providers/pom.xml                | 37 ++++++++++++++++++++++
 .../prometheus/PrometheusMetricsProvider.java      | 23 ++++++--------
 .../metrics/prometheus/ExportJvmInfoTest.java      |  5 +--
 .../prometheus/PrometheusMetricsProviderTest.java  | 19 +++++------
 .../src/test/resources/log4j.properties            |  4 +--
 7 files changed, 64 insertions(+), 28 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6176f6b..718a7d5 100755
--- a/pom.xml
+++ b/pom.xml
@@ -574,7 +574,7 @@
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-checkstyle-plugin</artifactId>
-          <version>3.0.0</version>
+          <version>3.1.0</version>
           <dependencies>
             <dependency>
               <groupId>com.puppycrawl.tools</groupId>
diff --git a/zookeeper-jute/pom.xml b/zookeeper-jute/pom.xml
index 91b215f..e5d192b 100755
--- a/zookeeper-jute/pom.xml
+++ b/zookeeper-jute/pom.xml
@@ -157,7 +157,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>3.0.0</version>
+        <version>3.1.0</version>
         <dependencies>
           <dependency>
             <groupId>com.puppycrawl.tools</groupId>
diff --git a/zookeeper-metrics-providers/pom.xml b/zookeeper-metrics-providers/pom.xml
index 5c83792..b6ae141 100755
--- a/zookeeper-metrics-providers/pom.xml
+++ b/zookeeper-metrics-providers/pom.xml
@@ -37,4 +37,41 @@
     <module>zookeeper-prometheus-metrics</module>
   </modules>
 
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-checkstyle-plugin</artifactId>
+          <version>3.1.0</version>
+          <dependencies>
+            <dependency>
+              <groupId>com.puppycrawl.tools</groupId>
+              <artifactId>checkstyle</artifactId>
+              <version>${checkstyle.version}</version>
+            </dependency>
+          </dependencies>
+          <configuration>
+            <configLocation>checkstyle-strict.xml</configLocation>
+            <suppressionsLocation>checkstyleSuppressions.xml</suppressionsLocation>
+            <encoding>UTF-8</encoding>
+            <consoleOutput>true</consoleOutput>
+            <failOnViolation>true</failOnViolation>
+            <includeResources>false</includeResources>
+            <includeTestSourceDirectory>true</includeTestSourceDirectory>
+          </configuration>
+          <executions>
+            <execution>
+              <id>checkstyle</id>
+              <phase>validate</phase>
+              <goals>
+                <goal>check</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
 </project>
diff --git a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
index ffa9e5b..569c049 100644
--- a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
+++ b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -15,6 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.zookeeper.metrics.prometheus;
 
 import io.prometheus.client.Collector;
@@ -29,7 +30,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.function.BiConsumer;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.apache.zookeeper.metrics.Counter;
@@ -60,7 +60,7 @@ public class PrometheusMetricsProvider implements MetricsProvider {
      * <p>
      * When you are running ZooKeeper (server or client) together with other
      * libraries every metrics will be expected as a single view.
-     *
+     * </p>
      */
     private final CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry;
     private int port = 7000;
@@ -133,6 +133,7 @@ public class PrometheusMetricsProvider implements MetricsProvider {
      * This method is not expected to be used to serve metrics to Prometheus. We
      * are using the MetricsServlet provided by Prometheus for that, leaving the
      * real representation to the Prometheus Java client.
+     * </p>
      *
      * @param sink the receiver of data (4lw interface, Admin server or tests)
      */
@@ -199,25 +200,21 @@ public class PrometheusMetricsProvider implements MetricsProvider {
 
         @Override
         public Counter getCounter(String name) {
-            return counters.computeIfAbsent(name, (n) -> {
-                return new PrometheusCounter(n);
-            });
+            return counters.computeIfAbsent(name, PrometheusCounter::new);
         }
 
         /**
          * Gauges may go up and down, in ZooKeeper they are a way to export
          * internal values with a callback.
          *
-         * @param name the name of the gauge
+         * @param name  the name of the gauge
          * @param gauge the callback
          */
         @Override
         public void registerGauge(String name, Gauge gauge) {
             Objects.requireNonNull(name);
-            gauges.compute(name, (id, prev) -> {
-                return new PrometheusGaugeWrapper(id, gauge,
-                        prev != null ? prev.inner : null);
-            });
+            gauges.compute(name, (id, prev) ->
+                    new PrometheusGaugeWrapper(id, gauge, prev != null ? prev.inner : null));
         }
 
         @Override
@@ -311,8 +308,8 @@ public class PrometheusMetricsProvider implements MetricsProvider {
             this.gauge = gauge;
             this.inner = prev != null ? prev
                     : io.prometheus.client.Gauge
-                            .build(name, name)
-                            .register(collectorRegistry);
+                    .build(name, name)
+                    .register(collectorRegistry);
         }
 
         /**
diff --git a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/ExportJvmInfoTest.java
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/ExportJvmInfoTest.java
index 899a271..fb5353d 100644
--- a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/ExportJvmInfoTest.java
+++ b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/ExportJvmInfoTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -15,11 +15,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.zookeeper.metrics.prometheus;
 
+import static org.junit.Assert.assertEquals;
 import io.prometheus.client.CollectorRegistry;
 import java.util.Properties;
-import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
 /**
diff --git a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderTest.java
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderTest.java
index b52bd7b..2d691db 100644
--- a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderTest.java
+++ b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -15,8 +15,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.zookeeper.metrics.prometheus;
 
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import io.prometheus.client.CollectorRegistry;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -30,17 +39,9 @@ import org.apache.zookeeper.metrics.Gauge;
 import org.apache.zookeeper.metrics.MetricsContext;
 import org.apache.zookeeper.metrics.Summary;
 import org.hamcrest.CoreMatchers;
-import static org.hamcrest.CoreMatchers.containsString;
 import org.junit.After;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.junit.Test;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests about Prometheus Metrics Provider. Please note that we are not testing
diff --git a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/resources/log4j.properties
b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/resources/log4j.properties
index 4a2ede9..d7f930d 100644
--- a/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/resources/log4j.properties
+++ b/zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/resources/log4j.properties
@@ -1,5 +1,5 @@
 # Copyright 2012 The Apache Software Foundation
-# 
+#
 # 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
@@ -34,7 +34,7 @@ log4j.rootLogger=${zookeeper.root.logger}
 
 #
 # console
-# Add "console" to rootlogger above if you want to use this 
+# Add "console" to rootlogger above if you want to use this
 #
 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
 log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}


Mime
View raw message