@@ -41,7 +41,7 @@ public class PrometheusHadoopServlet extends HttpServlet {
4141
4242 @ Override
4343 protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws IOException {
44- writeMetrics (resp .getWriter ());
44+ writeMetrics (resp .getWriter (), "true" . equals ( req . getParameter ( "description" )) );
4545 }
4646
4747 static String toPrometheusName (String metricRecordName , String metricName ) {
@@ -57,15 +57,21 @@ static String toPrometheusName(String metricRecordName, String metricName) {
5757 */
5858 @ RestrictedApi (explanation = "Should only be called in tests or self" , link = "" ,
5959 allowedOnPath = ".*/src/test/.*|.*/PrometheusHadoopServlet\\ .java" )
60- void writeMetrics (Writer writer ) throws IOException {
60+ void writeMetrics (Writer writer , boolean desc ) throws IOException {
6161 Collection <MetricsRecord > metricRecords = MetricsExportHelper .export ();
6262 for (MetricsRecord metricsRecord : metricRecords ) {
6363 for (AbstractMetric metrics : metricsRecord .metrics ()) {
6464 if (metrics .type () == MetricType .COUNTER || metrics .type () == MetricType .GAUGE ) {
6565
6666 String key = toPrometheusName (metricsRecord .name (), metrics .name ());
67+
68+ if (desc ) {
69+ String description = metrics .description ();
70+ if (!description .isEmpty ()) writer .append ("# HELP " ).append (description ).append ('\n' );
71+ }
72+
6773 writer .append ("# TYPE " ).append (key ).append (" " )
68- .append (metrics .type ().toString ().toLowerCase ()).append (" \n " ).append (key ).append ("{" );
74+ .append (metrics .type ().toString ().toLowerCase ()).append ('\n' ).append (key ).append ("{" );
6975
7076 /* add tags */
7177 String sep = "" ;
0 commit comments