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

2022-08-16 Thread GitBox


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


##
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:
   Fixed it in the current commit, thank you for bringing it to my attention.



-- 
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] lucakovacs commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-15 Thread GitBox


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


##
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:
   First, I left it as it was, but I renamed to Hadoop in the last commit



-- 
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] lucakovacs commented on a diff in pull request #4691: HBASE-20904 Prometheus /metrics http endpoint for monitoring

2022-08-11 Thread GitBox


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


##
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:
   It was part of the original pull request and because it doesn't add any 
dependencies I kept it like this. If you think simpleclient is a better 
solution, it can be replaced of course.



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