This is an automated email from the ASF dual-hosted git repository.
zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new 211833d106 [CELEBORN-2511] Fix labeled histograms sharing one
reservoir and being missed in metrics count
211833d106 is described below
commit 211833d106070259f1c6c1c12f58b5c7cee811f8
Author: yew1eb <[email protected]>
AuthorDate: Thu Nov 19 23:36:46 2026 +0800
[CELEBORN-2511] Fix labeled histograms sharing one reservoir and being
missed in metrics count
1. `AbstractSource.addHistogram` computes the label-aware key
`metricNameWithLabel` but
registers the Dropwizard histogram under the bare `name`, so every
labeled variant of the
same histogram shares a single reservoir. Labeled variants now register
under
`metricNameWithLabel`, giving each one its own reservoir. Histograms
without customized
labels keep registering under the bare `name` so sinks built on
`metricRegistry`
(CsvSink/JmxSink) keep exposing existing histograms under their
historical names.
2. `AbstractSource.getAllMetricsNum` now includes `namedHistogram.size()`,
so the metrics
capacity warning counts what `getMetrics` actually emits.
- With the old code, adding a label (e.g. a disk label on
`PartitionFileSize`) makes all
labeled variants read the same aggregated reservoir, so they report
identical
`Count`/`Max`/percentiles. It is latent today because the only two
histograms
(`FetchChunkTransferSize`, `PartitionFileSize`) carry no labels yet.
Those two keep their
bare registry names, so Dropwizard sink consumers are unaffected; only
new labeled
variants register under the label-aware key.
- `getMetrics` emits histograms (`fillInnerMetricsSnapshot(histograms(),
...)`) but
`getAllMetricsNum` ignores them, under-reporting the count used for the
"number of metrics exceed the output metrics strings capacity" warning.
- [x] Yes
- [x] Yes
Labeled histograms report their own values instead of a shared aggregate,
and the reported
total metric count grows by the number of histograms. Existing unlabeled
histograms keep
their registry names, so CsvSink/JmxSink output is unchanged for them.
Added `test histogram with customized label` to `CelebornSourceSuite`: it
registers
`PartitionFileSize` with `disk=disk1`/`disk=disk2`, updates them with
different values and
asserts each label reports its own `_Max` plus `getAllMetricsNum == 2`, and
that each
variant registers under its label-aware key in the registry. `test
histogram` now also
asserts a histogram registered without labels is still exposed under the
bare name.
./build/mvn -pl common test -DargLine=
-Dsuites=org.apache.celeborn.common.metrics.source.CelebornSourceSuite
passes (10 tests); the labeled test fails if histograms revert to the bare
registry key,
and the bare-name assertion fails if unlabeled histograms move to the
label-aware key.
Closes #3908 from yew1eb/fix/metrics-histogram-label-keys.
Authored-by: yew1eb <[email protected]>
Co-Authored-By: Claude <[email protected]>
Signed-off-by: zhengtao <[email protected]>
---
.../common/metrics/source/AbstractSource.scala | 10 +++++--
.../metrics/source/CelebornSourceSuite.scala | 31 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git
a/common/src/main/scala/org/apache/celeborn/common/metrics/source/AbstractSource.scala
b/common/src/main/scala/org/apache/celeborn/common/metrics/source/AbstractSource.scala
index 58a3a0ad0c..0abd3956b4 100644
---
a/common/src/main/scala/org/apache/celeborn/common/metrics/source/AbstractSource.scala
+++
b/common/src/main/scala/org/apache/celeborn/common/metrics/source/AbstractSource.scala
@@ -231,11 +231,16 @@ abstract class AbstractSource(conf: CelebornConf, role:
String)
def addHistogram(name: String, labels: Map[String, String]): Unit = {
val metricNameWithLabel = metricNameWithCustomizedLabels(name, labels)
+ // Register in the Dropwizard registry under the bare name when no
customized labels are
+ // given, so sinks built on metricRegistry (CsvSink/JmxSink) keep exposing
existing
+ // histograms under their historical names. Labeled variants register
under the
+ // label-aware key, giving each variant its own reservoir instead of a
shared one.
+ val registryName = if (labels.isEmpty) name else metricNameWithLabel
namedHistogram.putIfAbsent(
metricNameWithLabel,
NamedHistogram(
name,
- metricRegistry.histogram(name, histogramSupplier),
+ metricRegistry.histogram(registryName, histogramSupplier),
labelsWithCustomizedLabels(labels)))
}
@@ -746,7 +751,8 @@ abstract class AbstractSource(conf: CelebornConf, role:
String)
namedMeters.size() +
namedGauges.size() +
namedGaugesWithDetails.size() +
- namedCounters.size()
+ namedCounters.size() +
+ namedHistogram.size()
sum
}
diff --git
a/common/src/test/scala/org/apache/celeborn/common/metrics/source/CelebornSourceSuite.scala
b/common/src/test/scala/org/apache/celeborn/common/metrics/source/CelebornSourceSuite.scala
index d148c26d6a..f14be7863f 100644
---
a/common/src/test/scala/org/apache/celeborn/common/metrics/source/CelebornSourceSuite.scala
+++
b/common/src/test/scala/org/apache/celeborn/common/metrics/source/CelebornSourceSuite.scala
@@ -19,6 +19,8 @@ package org.apache.celeborn.common.metrics.source
import java.util.concurrent.{CyclicBarrier, TimeUnit}
+import scala.collection.JavaConverters._
+
import org.apache.celeborn.CelebornFunSuite
import org.apache.celeborn.common.CelebornConf
@@ -60,6 +62,9 @@ class CelebornSourceSuite extends CelebornFunSuite {
}
val histogram = "abc"
mockSource.addHistogram(histogram)
+ // a histogram without customized labels stays exposed under the bare name
in the
+ // Dropwizard registry, so CsvSink/JmxSink keep finding it under its
historical name
+ assert(mockSource.metricRegistry.getMetrics.containsKey(histogram))
for (i <- 1 to 100) {
mockSource.updateHistogram(histogram, 10)
}
@@ -99,6 +104,32 @@ class CelebornSourceSuite extends CelebornFunSuite {
}
}
+ test("test histogram with customized label") {
+ val conf = new CelebornConf()
+ val mockSource = new AbstractSource(conf, Role.WORKER) {
+ override def sourceName: String = "mockSource"
+ }
+ val histogram = "PartitionFileSize"
+ val disk1 = Map("disk" -> "disk1")
+ val disk2 = Map("disk" -> "disk2")
+ mockSource.addHistogram(histogram, disk1)
+ mockSource.addHistogram(histogram, disk2)
+ mockSource.updateHistogram(histogram, disk1, 10)
+ mockSource.updateHistogram(histogram, disk2, 100)
+
+ val res = mockSource.getMetrics
+ val maxPerDisk = """metrics_PartitionFileSize_Max\{disk="(disk\d)".*\}
(\d+)""".r
+ .findAllMatchIn(res).map(m => m.group(1) -> m.group(2).toLong).toMap
+ // each labeled histogram owns its own reservoir instead of sharing a
single one
+ assert(maxPerDisk("disk1") == 10)
+ assert(maxPerDisk("disk2") == 100)
+ assert(mockSource.getAllMetricsNum == 2)
+ // labeled variants register under the label-aware key in the Dropwizard
registry
+ val registryKeys = mockSource.metricRegistry.getMetrics.keySet.asScala
+ assert(registryKeys.exists(k => k.startsWith(histogram) &&
k.contains("""disk="disk1"""")))
+ assert(registryKeys.exists(k => k.startsWith(histogram) &&
k.contains("""disk="disk2"""")))
+ }
+
test("test getMetrics with customized label") {
val conf = new CelebornConf()
createAbstractSourceAndCheck(conf, "", Role.MASTER)