You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by me...@apache.org on 2022/10/07 09:35:59 UTC
[hbase] branch branch-2 updated: HBASE-27395 Adding description to Prometheus metrics (#4807)
This is an automated email from the ASF dual-hosted git repository.
meszibalu pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2 by this push:
new f5df7693c53 HBASE-27395 Adding description to Prometheus metrics (#4807)
f5df7693c53 is described below
commit f5df7693c53b9e347bf8d10edc6fe2e3a322c4dd
Author: Luca Kovács <ko...@gmail.com>
AuthorDate: Fri Oct 7 11:31:02 2022 +0200
HBASE-27395 Adding description to Prometheus metrics (#4807)
Signed-off-by: Tamas Payer <pa...@apache.org>
Signed-off-by: Balazs Meszaros <me...@apache.org>
---
.../hbase/http/prometheus/PrometheusHadoopServlet.java | 12 +++++++++---
.../hadoop/hbase/http/prometheus/TestPrometheusServlet.java | 3 ++-
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java
index c6e13b37c66..db5952e2fa7 100644
--- a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java
+++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java
@@ -41,7 +41,7 @@ public class PrometheusHadoopServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- writeMetrics(resp.getWriter());
+ writeMetrics(resp.getWriter(), "true".equals(req.getParameter("description")));
}
static String toPrometheusName(String metricRecordName, String metricName) {
@@ -57,15 +57,21 @@ public class PrometheusHadoopServlet extends HttpServlet {
*/
@RestrictedApi(explanation = "Should only be called in tests or self", link = "",
allowedOnPath = ".*/src/test/.*|.*/PrometheusHadoopServlet\\.java")
- void writeMetrics(Writer writer) throws IOException {
+ void writeMetrics(Writer writer, boolean desc) throws IOException {
Collection<MetricsRecord> metricRecords = MetricsExportHelper.export();
for (MetricsRecord metricsRecord : metricRecords) {
for (AbstractMetric metrics : metricsRecord.metrics()) {
if (metrics.type() == MetricType.COUNTER || metrics.type() == MetricType.GAUGE) {
String key = toPrometheusName(metricsRecord.name(), metrics.name());
+
+ if (desc) {
+ String description = metrics.description();
+ if (!description.isEmpty()) writer.append("# HELP ").append(description).append('\n');
+ }
+
writer.append("# TYPE ").append(key).append(" ")
- .append(metrics.type().toString().toLowerCase()).append("\n").append(key).append("{");
+ .append(metrics.type().toString().toLowerCase()).append('\n').append(key).append("{");
/* add tags */
String sep = "";
diff --git a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/prometheus/TestPrometheusServlet.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/prometheus/TestPrometheusServlet.java
index fcfde82ad41..0ca021bc12b 100644
--- a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/prometheus/TestPrometheusServlet.java
+++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/prometheus/TestPrometheusServlet.java
@@ -60,7 +60,8 @@ public class TestPrometheusServlet {
// WHEN
PrometheusHadoopServlet prom2Servlet = new PrometheusHadoopServlet();
- prom2Servlet.writeMetrics(writer);
+ // Test with no description
+ prom2Servlet.writeMetrics(writer, false);
// THEN
String writtenMetrics = stream.toString(UTF_8.name());