[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-24 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r953651328


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java:
##
@@ -154,6 +154,18 @@ public class HttpServer implements FilterContainer {
   public static final String NO_CACHE_FILTER = "NoCacheFilter";
   public static final String APP_DIR = "webapps";
 
+  public static final String METRIC_SERVLETS_CONF_KEY = 
"hbase.http.metrics.servlets";
+  public static final String[] METRICS_SERVLETS_DEFAULT = { "jmx", "metrics", 
"prometheus" };
+  private static final ImmutableMap METRIC_SERVLETS = new ImmutableMap.Builder()
+  .put("jmx",
+new ServletConfig("jmx", "/jmx", 
"org.apache.hadoop.hbase.http.jmx.JMXJsonServlet"))
+  .put("metrics",
+new ServletConfig("metrics", "/metrics", 
"org.apache.hadoop.metrics.MetricsServlet"))
+  .put("prometheus", new ServletConfig("prometheus", "/prometheus",

Review Comment:
   Ah, this is a problem. I just read it as 'Prometheus metrics http endpoint 
for monitoring'... Missed the '/'



-- 
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: issues-unsubscr...@hbase.apache.org

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



[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-24 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r953649099


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java:
##
@@ -0,0 +1,84 @@
+/*
+ * 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.hadoop.hbase.http.prometheus;
+
+import com.google.errorprone.annotations.RestrictedApi;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+public class PrometheusHadoopServlet extends HttpServlet {

Review Comment:
   I do not see any advantages here to use jersey? The servlet is really easy 
to implement...



-- 
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: issues-unsubscr...@hbase.apache.org

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



[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-24 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r953648382


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java:
##
@@ -0,0 +1,84 @@
+/*
+ * 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.hadoop.hbase.http.prometheus;
+
+import com.google.errorprone.annotations.RestrictedApi;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+public class PrometheusHadoopServlet extends HttpServlet {

Review Comment:
   Because it exports the metrics we registered to hadoop metrics system?



-- 
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: issues-unsubscr...@hbase.apache.org

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



[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-24 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r953647493


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java:
##
@@ -784,6 +787,22 @@ protected void addDefaultServlets(ContextHandlerCollection 
contexts, Configurati
   LOG.info("ASYNC_PROFILER_HOME environment variable and 
async.profiler.home system property "
 + "not specified. Disabling /prof endpoint.");
 }
+
+/* register metrics servlets */
+String[] enabledServlets = conf.getStrings(METRIC_SERVLETS_CONF_KEY, 
METRICS_SERVLETS_DEFAULT);
+for (String enabledServlet : enabledServlets) {
+  try {
+ServletConfig servletConfig = METRIC_SERVLETS.get(enabledServlet);
+if (servletConfig != null) {
+  Class clz = Class.forName(servletConfig.getClazz());
+  addPrivilegedServlet(servletConfig.getName(), 
servletConfig.getPathSpec(),
+clz.asSubclass(HttpServlet.class));
+}
+  } catch (Exception e) {
+/* shouldn't be fatal, so warn the user about it */

Review Comment:
   For me, I think the current implementation is enough. We will warn if a 
registered endpoint fails to load. And the default configuration is to load all 
metrics endpoints, if users configured it to none, they must have a reason, so 
I do not think here we need to warn it. And I also do not think we should abort 
the process if none metrics can be loaded, as it does not effect the normal 
read/write.



##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java:
##
@@ -784,6 +787,22 @@ protected void addDefaultServlets(ContextHandlerCollection 
contexts, Configurati
   LOG.info("ASYNC_PROFILER_HOME environment variable and 
async.profiler.home system property "
 + "not specified. Disabling /prof endpoint.");
 }
+
+/* register metrics servlets */
+String[] enabledServlets = conf.getStrings(METRIC_SERVLETS_CONF_KEY, 
METRICS_SERVLETS_DEFAULT);
+for (String enabledServlet : enabledServlets) {
+  try {
+ServletConfig servletConfig = METRIC_SERVLETS.get(enabledServlet);
+if (servletConfig != null) {
+  Class clz = Class.forName(servletConfig.getClazz());
+  addPrivilegedServlet(servletConfig.getName(), 
servletConfig.getPathSpec(),
+clz.asSubclass(HttpServlet.class));
+}
+  } catch (Exception e) {
+/* shouldn't be fatal, so warn the user about it */

Review Comment:
   For me, I think the current implementation is enough. We will warn if a 
registered endpoint fails to load. And the default configuration is to load all 
metrics endpoints, if users configured it to none, they must have a reason, so 
I do not think here we need to warn it. And I also do not think we should abort 
the process if none metrics can be loaded, as it does not affect the normal 
read/write.



-- 
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: issues-unsubscr...@hbase.apache.org

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



[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-17 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r947551006


##
hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricsExportHelper.java:
##
@@ -0,0 +1,73 @@
+/*
+ * 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.hadoop.hbase.metrics;
+
+import java.util.Collection;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.MetricsTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ MetricsTests.class, SmallTests.class })
+public class TestMetricsExportHelper {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+HBaseClassTestRule.forClass(TestMetricsExportHelper.class);
+
+  @Test
+  public void testExportHelper() {
+DefaultMetricsSystem.initialize("exportHelperTestSystem");
+DefaultMetricsSystem.instance().start();
+
+String metricsName = "exportMetricsTestGrp";
+String gaugeName = "exportMetricsTestGauge";
+String counterName = "exportMetricsTestCounter";
+
+BaseSourceImpl baseSource = new BaseSourceImpl(metricsName, "", 
metricsName, metricsName);
+
+baseSource.setGauge(gaugeName, 0);
+baseSource.incCounters(counterName, 1);
+
+Collection metrics = MetricsExportHelper.export();
+DefaultMetricsSystem.instance().stop();
+
+Assert.assertTrue(metrics.stream().anyMatch(mr -> 
mr.name().equals(metricsName)));
+Assert.assertTrue(gaugeName + " is missing in the export",
+  contains(metrics, metricsName, gaugeName));
+Assert.assertTrue(counterName + " is missing in the export",
+  contains(metrics, metricsName, counterName));
+  }
+
+  private boolean contains(Collection metrics, String 
metricsName,
+String metricName) {
+return metrics.stream().filter(mr -> 
mr.name().equals(metricsName)).anyMatch(mr -> {
+  for (AbstractMetric metric : mr.metrics()) {
+if (metric.name().equals(metricName)) return true;

Review Comment:
   New line with '{}', otherwise there will be a checkstyle warning.



##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java:
##
@@ -784,6 +788,20 @@ protected void addDefaultServlets(ContextHandlerCollection 
contexts, Configurati
   LOG.info("ASYNC_PROFILER_HOME environment variable and 
async.profiler.home system property "
 + "not specified. Disabling /prof endpoint.");
 }
+
+/* register metrics servlets */
+String enabledServlets[] = conf.getStrings(METRIC_SERVLETS_CONF_KEY, 
METRICS_SERVLETS_DEFAULT);

Review Comment:
   `String enabledServlets[]` -> `String[] enabledServlets`



##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java:
##
@@ -154,6 +153,20 @@ public class HttpServer implements FilterContainer {
   public static final String NO_CACHE_FILTER = "NoCacheFilter";
   public static final String APP_DIR = "webapps";
 
+  public static final String METRIC_SERVLETS_CONF_KEY = 
"hbase.http.metrics.servlets";
+  public static final String METRICS_SERVLETS_DEFAULT[] = { "jmx", "metrics", 
"prometheus" };

Review Comment:
   `String METRICS_SERVLETS_DEFAULT[]` -> `String[] METRICS_SERVLETS_DEFAULT`



##
hbase-hadoop-compat/src/main/java/org/apache/hadoop/metrics2/impl/MetricsExportHelper.java:
##
@@ -0,0 +1,40 @@
+/*
+ * 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
+

[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-15 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r946323840


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java:
##
@@ -0,0 +1,84 @@
+/*
+ * 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.hadoop.hbase.http.prometheus;
+
+import com.google.errorprone.annotations.RestrictedApi;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+public class PrometheusHadoopServlet extends HttpServlet {
+
+  private static final Pattern SPLIT_PATTERN =
+Pattern.compile("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=([A-Z][a-z]))|\\W|(_)+");
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws IOException {
+writeMetrics(resp.getWriter());
+  }
+
+  static String toPrometheusName(String metricRecordName, String metricName) {
+String baseName = metricRecordName + StringUtils.capitalize(metricName);
+String[] parts = SPLIT_PATTERN.split(baseName);
+return String.join("_", parts).toLowerCase();
+  }
+
+  /*
+   * SimpleClient for Prometheus is not used, because the format is very easy 
to implement and this
+   * solution doesn't add any dependencies to the project. You can check the 
Prometheus format here:
+   * https://prometheus.io/docs/instrumenting/exposition_formats/
+   */
+  @RestrictedApi(explanation = "Should only be called in tests", link = "",

Review Comment:
   We also call it in this class so we need to change the allowedOnPath to also 
include the current file.



-- 
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: issues-unsubscr...@hbase.apache.org

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



[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-11 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r943466191


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoop2Servlet.java:
##
@@ -0,0 +1,86 @@
+/*
+ * 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.hadoop.hbase.http.prometheus;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import com.google.errorprone.annotations.RestrictedApi;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+public class PrometheusHadoop2Servlet extends HttpServlet {
+
+  private static final Pattern SPLIT_PATTERN =
+Pattern.compile("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=([A-Z][a-z]))|\\W|(_)+");
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+throws IOException {
+writeMetrics(resp.getWriter());
+  }
+
+  static String toPrometheusName(String metricRecordName, String metricName) {
+String baseName = metricRecordName + StringUtils.capitalize(metricName);
+String[] parts = SPLIT_PATTERN.split(baseName);
+return String
+  .join("_", parts)
+  .toLowerCase();
+  }
+
+  @RestrictedApi(explanation = "Should only be called in tests", link = "",
+allowedOnPath = ".*/src/test/.*")
+  void writeMetrics(Writer writer) throws IOException {
+Collection metricRecords = MetricsExportHelper.export();
+for (MetricsRecord metricsRecord : metricRecords) {
+  for (AbstractMetric metrics : metricsRecord.metrics()) {
+if (metrics.type() == MetricType.COUNTER || metrics.type() == 
MetricType.GAUGE) {

Review Comment:
   No problem, just want to know the reason.
   Then better add some references about the format spec, and also mention that 
the format is not hard to implement so do not want to add extra dependencies.



-- 
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: issues-unsubscr...@hbase.apache.org

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



[GitHub] [hbase] Apache9 commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-10 Thread GitBox


Apache9 commented on code in PR #4691:
URL: https://github.com/apache/hbase/pull/4691#discussion_r942426722


##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoop2Servlet.java:
##
@@ -0,0 +1,86 @@
+/*
+ * 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.hadoop.hbase.http.prometheus;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import com.google.errorprone.annotations.RestrictedApi;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+public class PrometheusHadoop2Servlet extends HttpServlet {
+
+  private static final Pattern SPLIT_PATTERN =
+Pattern.compile("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=([A-Z][a-z]))|\\W|(_)+");
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+throws IOException {
+writeMetrics(resp.getWriter());
+  }
+
+  static String toPrometheusName(String metricRecordName, String metricName) {
+String baseName = metricRecordName + StringUtils.capitalize(metricName);
+String[] parts = SPLIT_PATTERN.split(baseName);
+return String
+  .join("_", parts)
+  .toLowerCase();
+  }
+
+  @RestrictedApi(explanation = "Should only be called in tests", link = "",
+allowedOnPath = ".*/src/test/.*")
+  void writeMetrics(Writer writer) throws IOException {
+Collection metricRecords = MetricsExportHelper.export();
+for (MetricsRecord metricsRecord : metricRecords) {
+  for (AbstractMetric metrics : metricsRecord.metrics()) {
+if (metrics.type() == MetricType.COUNTER || metrics.type() == 
MetricType.GAUGE) {

Review Comment:
   We do not want to rely on prometheus simpleclient to do this?



##
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoop2Servlet.java:
##
@@ -0,0 +1,86 @@
+/*
+ * 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.hadoop.hbase.http.prometheus;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import com.google.errorprone.annotations.RestrictedApi;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.impl.MetricsExportHelper;
+import org.apache.yetus.audience.InterfaceAudience;
+
+@InterfaceAudience.Private
+public class PrometheusHadoop2Servlet extends HttpServlet {

Review Comment:
   Why name it hadoop2, not hadoop?



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