maoling commented on a change in pull request #1574:
URL: https://github.com/apache/zookeeper/pull/1574#discussion_r628871719



##########
File path: zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
##########
@@ -2068,6 +2068,9 @@ options are used to configure the 
[AdminServer](#sc_adminserver).
     Set to "org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider" 
to
     enable Prometheus.io exporter.
 
+* *metricsProvider.httpHost* :
+  Prometheus.io exporter will start a Jetty server and listen this address, 
default is "0.0.0.0"
+  

Review comment:
       here has whitespace, please don't have it next time:)

##########
File path: 
zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderConfigTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.zookeeper.metrics.prometheus;
+
+import io.prometheus.client.CollectorRegistry;
+
+import java.util.Properties;
+
+import org.apache.zookeeper.metrics.MetricsProviderLifeCycleException;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class PrometheusMetricsProviderConfigTest {
+
+    @Test
+    public void testInvalidPort() {
+        MetricsProviderLifeCycleException exception = Assert
+                .assertThrows(MetricsProviderLifeCycleException.class, () -> {
+                    CollectorRegistry.defaultRegistry.clear();
+                    PrometheusMetricsProvider provider = new 
PrometheusMetricsProvider();
+                    Properties configuration = new Properties();
+                    configuration.setProperty("httpPort", "65536");
+                    configuration.setProperty("exportJvmInfo", "false");
+                    provider.configure(configuration);
+                    provider.start();
+                });
+        Assert.assertEquals("java.lang.IllegalArgumentException: port out of 
range:65536", exception.getMessage());
+    }
+
+    @Test
+    public void testInvalidAddr() {
+        MetricsProviderLifeCycleException exception = Assert
+                .assertThrows(MetricsProviderLifeCycleException.class, () -> {
+                    CollectorRegistry.defaultRegistry.clear();
+                    PrometheusMetricsProvider provider = new 
PrometheusMetricsProvider();
+                    Properties configuration = new Properties();
+                    configuration.setProperty("httpHost", "256.256.256.256");

Review comment:
       - Yep. ` configuration.setProperty("httpHost", "master");` is  better.

##########
File path: 
zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/test/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProviderConfigTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.zookeeper.metrics.prometheus;
+
+import io.prometheus.client.CollectorRegistry;
+
+import java.util.Properties;
+
+import org.apache.zookeeper.metrics.MetricsProviderLifeCycleException;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class PrometheusMetricsProviderConfigTest {
+
+    @Test
+    public void testInvalidPort() {
+        MetricsProviderLifeCycleException exception = Assert
+                .assertThrows(MetricsProviderLifeCycleException.class, () -> {
+                    CollectorRegistry.defaultRegistry.clear();
+                    PrometheusMetricsProvider provider = new 
PrometheusMetricsProvider();
+                    Properties configuration = new Properties();
+                    configuration.setProperty("httpPort", "65536");
+                    configuration.setProperty("exportJvmInfo", "false");
+                    provider.configure(configuration);
+                    provider.start();
+                });
+        Assert.assertEquals("java.lang.IllegalArgumentException: port out of 
range:65536", exception.getMessage());
+    }
+
+    @Test
+    public void testInvalidAddr() {
+        MetricsProviderLifeCycleException exception = Assert
+                .assertThrows(MetricsProviderLifeCycleException.class, () -> {
+                    CollectorRegistry.defaultRegistry.clear();
+                    PrometheusMetricsProvider provider = new 
PrometheusMetricsProvider();
+                    Properties configuration = new Properties();
+                    configuration.setProperty("httpHost", "256.256.256.256");
+                    provider.configure(configuration);
+                    provider.start();
+                });
+        Assert.assertEquals("java.net.SocketException: Unresolved address", 
exception.getMessage());

Review comment:
       - You have asserted there was a `MetricsProviderLifeCycleException` 
happens here, so don't make so specify assertion here to avoid the environment 
diversity?So removing this line?

##########
File path: zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
##########
@@ -2068,6 +2068,9 @@ options are used to configure the 
[AdminServer](#sc_adminserver).
     Set to "org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider" 
to
     enable Prometheus.io exporter.
 
+* *metricsProvider.httpHost* :
+  Prometheus.io exporter will start a Jetty server and listen this address, 
default is "0.0.0.0"

Review comment:
       Add this: **New in 3.8.0:** ? 

##########
File path: 
zookeeper-metrics-providers/zookeeper-prometheus-metrics/src/main/java/org/apache/zookeeper/metrics/prometheus/PrometheusMetricsProvider.java
##########
@@ -72,18 +74,20 @@
     @Override
     public void configure(Properties configuration) throws 
MetricsProviderLifeCycleException {
         LOG.info("Initializing metrics, configuration: {}", configuration);
+        this.host = configuration.getProperty("httpHost", "0.0.0.0");
         this.port = Integer.parseInt(configuration.getProperty("httpPort", 
"7000"));
         this.exportJvmInfo = 
Boolean.parseBoolean(configuration.getProperty("exportJvmInfo", "true"));
     }
 
     @Override
     public void start() throws MetricsProviderLifeCycleException {
         try {
-            LOG.info("Starting /metrics HTTP endpoint at port {} 
exportJvmInfo: {}", port, exportJvmInfo);
+            LOG.info("Starting /metrics HTTP endpoint at port {} listening {} 
exportJvmInfo: {}",
+                    port, host, exportJvmInfo);

Review comment:
       The following is better?
   ```
   LOG.info("Starting /metrics HTTP endpoint at host: {}, port: {}, 
exportJvmInfo: {}",
                       host, port, exportJvmInfo);
   ```




-- 
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:
us...@infra.apache.org


Reply via email to