SteNicholas commented on code in PR #3740:
URL: https://github.com/apache/celeborn/pull/3740#discussion_r3802873927
##########
common/src/main/scala/org/apache/celeborn/common/metrics/source/AbstractSource.scala:
##########
@@ -212,6 +235,51 @@ abstract class AbstractSource(conf: CelebornConf, role:
String)
labelsWithCustomizedLabels(labels)))
}
+ protected def addOrUpdateGaugeForApp(
+ name: String,
+ labels: Map[String, String],
+ appId: String,
+ value: Long): Unit = {
+ val key = metricNameWithCustomizedLabels(name, labels)
+ namedGaugesWithDetails.compute(
+ key,
+ new BiFunction[String, TrackedGauge, TrackedGauge] {
+ override def apply(_key: String, existing: TrackedGauge): TrackedGauge
= {
+ val tracked = Option(existing).getOrElse {
+ val holder = new AtomicLong()
+ addGauge(name, labels)(() => holder.get())
+ val namedGauge =
namedGauges.get(key).asInstanceOf[NamedGauge[Long]]
+ TrackedGauge(namedGauge, holder,
ConcurrentHashMap.newKeySet[String]())
+ }
+ tracked.contributingAppIds.add(appId)
+ tracked.handle.set(value)
Review Comment:
Gauges become last-writer-wins across applications sharing a label set. The
documented low-cardinality labels (`env`, `team`, etc.) intentionally collapse
multiple applications into one series, but `set(value)` makes
`ClientActiveShuffleCount` and the other gauges report whichever application
heartbeated last rather than an aggregate. It also leaves a removed application
value behind when that application was the last writer and other contributors
remain. Please retain per-application gauge values and define an aggregation
such as sum/max, or require an application-unique label and document that
contract.
##########
master/src/main/scala/org/apache/celeborn/service/deploy/master/ApplicationMetricsSource.scala:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.celeborn.service.deploy.master
+
+import java.util.{Map => JMap}
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicBoolean
+
+import scala.collection.JavaConverters._
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.metrics.{ClientMetric, MetricType}
+import org.apache.celeborn.common.metrics.source.{AbstractSource, Role}
+import org.apache.celeborn.common.util.{JavaUtils, Utils}
+
+class ApplicationMetricsSource(conf: CelebornConf)
+ extends AbstractSource(conf, Role.MASTER) with Logging {
+ override val sourceName = "application"
+
+ private val masterClientMetricsEnabled = conf.masterClientMetricsEnabled
+ private val removedAppRetentionMs =
conf.masterClientMetricsRemovedAppRetentionMs
+
+ // Tracking applications that have been terminated
+ private val removedAppIds =
+ JavaUtils.newConcurrentHashMap[String, java.lang.Long]()
+
+ private val seriesCardinalityWarnThreshold =
+ conf.masterClientMetricsSeriesCardinalityWarnThreshold
+ private val seriesCardinalityWarned = new AtomicBoolean(false)
+
+ if (masterClientMetricsEnabled) {
+ startRemovedAppCleaner()
+ }
+
+ private def startRemovedAppCleaner(): Unit = {
+ val cleanTask: Runnable = new Runnable {
+ override def run(): Unit = Utils.tryLogNonFatalError {
+ val cutoff = System.currentTimeMillis() - removedAppRetentionMs
+ removedAppIds.entrySet().asScala.foreach { entry =>
+ if (entry.getValue < cutoff) {
+ removedAppIds.remove(entry.getKey, entry.getValue)
+ }
+ }
+ }
+ }
+ metricsCleaner.scheduleWithFixedDelay(
+ cleanTask,
+ removedAppRetentionMs,
+ removedAppRetentionMs,
+ TimeUnit.MILLISECONDS)
+ }
+
+ def updateApplicationMetrics(
+ appId: String,
+ metricLabels: Map[String, String],
+ metrics: JMap[String, ClientMetric]): Unit = {
Review Comment:
Validate heartbeat-provided labels before registering metrics. These labels
come from the wire and are eventually rendered as `key="value"` without
escaping; the client-side config check only verifies key/value parsing and can
also be bypassed by another client implementation. Invalid keys or values
containing quotes, backslashes, or newlines can corrupt the master Prometheus
response for every scrape. Please enforce Prometheus label-name rules on the
master and correctly escape, or reject, unsafe values.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]