jiangzho commented on code in PR #52183:
URL: https://github.com/apache/spark/pull/52183#discussion_r2342598163


##########
core/src/main/scala/org/apache/spark/metrics/sink/PrometheusServlet.scala:
##########
@@ -59,71 +59,80 @@ private[spark] class PrometheusServlet(
   def getMetricsSnapshot(): String = {
     import scala.jdk.CollectionConverters._
 
-    val gaugesLabel = """{type="gauges"}"""
-    val countersLabel = """{type="counters"}"""
-    val metersLabel = countersLabel
-    val histogramslabels = """{type="histograms"}"""
-    val timersLabels = """{type="timers"}"""
+    val PERCENTILE_P50 = "0.5"
+    val PERCENTILE_P75 = "0.75"
+    val PERCENTILE_P95 = "0.95"
+    val PERCENTILE_P98 = "0.98"
+    val PERCENTILE_P99 = "0.99"
+    val PERCENTILE_P999 = "0.999"
 
     val sb = new StringBuilder()
     registry.getGauges.asScala.foreach { case (k, v) =>
-      if (!v.getValue.isInstanceOf[String]) {
-        sb.append(s"${normalizeKey(k)}Number$gaugesLabel ${v.getValue}\n")
-        sb.append(s"${normalizeKey(k)}Value$gaugesLabel ${v.getValue}\n")
+      v.getValue match {
+        case n: Number =>
+          sb.append(s"# HELP ${normalizeKey(k)} Gauge metric\n")
+          sb.append(s"# TYPE ${normalizeKey(k)} gauge\n")
+          sb.append(s"${normalizeKey(k)} ${n.doubleValue()}\n")
+        case _ => // non-numeric gauges
       }
     }
     registry.getCounters.asScala.foreach { case (k, v) =>
-      sb.append(s"${normalizeKey(k)}Count$countersLabel ${v.getCount}\n")
+      val name = normalizeKey(k)
+      sb.append(s"# HELP ${name} Counter metric\n")
+      sb.append(s"# TYPE ${name} counter\n")
+      sb.append(s"$name ${v.getCount}\n")
     }
     registry.getHistograms.asScala.foreach { case (k, h) =>
       val snapshot = h.getSnapshot
+      val values = snapshot.getValues.map(_.toDouble)
       val prefix = normalizeKey(k)
-      sb.append(s"${prefix}Count$histogramslabels ${h.getCount}\n")
-      sb.append(s"${prefix}Max$histogramslabels ${snapshot.getMax}\n")

Review Comment:
   thanks for the catch! 
   
   Though openmetrics consider these as optional, we shall not be ruling them 
out as they were present currently. I'll add them 



-- 
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: reviews-unsubscr...@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to