payert commented on code in PR #4807:
URL: https://github.com/apache/hbase/pull/4807#discussion_r985710610


##########
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java:
##########
@@ -57,13 +60,19 @@ static String toPrometheusName(String metricRecordName, 
String metricName) {
    */
   @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 {

Review Comment:
   Maybe 'describe' is better argument name than 'desc'.



##########
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java:
##########
@@ -41,7 +41,10 @@ public class PrometheusHadoopServlet extends HttpServlet {
 
   @Override
   protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws IOException {
-    writeMetrics(resp.getWriter());
+    String tmpStr = req.getParameter("description");
+    boolean description = tmpStr != null && tmpStr.equals("true");
+
+    writeMetrics(resp.getWriter(), description);

Review Comment:
   This could be compacted like this:
   `writeMetrics(resp.getWriter(), 
"true".equals(req.getParameter("description"))); `



##########
hbase-http/src/main/java/org/apache/hadoop/hbase/http/prometheus/PrometheusHadoopServlet.java:
##########
@@ -57,13 +60,19 @@ static String toPrometheusName(String metricRecordName, 
String metricName) {
    */
   @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");

Review Comment:
   When you append a single char to the writer you can use the append(char c) 
instead if of append(CharSequence csq). I mean
   `.append('\n'`)
   instead of 
   `.append("\n")`
   Doesn't make much difference but slightly cheaper..



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

Reply via email to