This is an automated email from the ASF dual-hosted git repository.

nicholasjiang pushed a commit to branch branch-0.6
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/branch-0.6 by this push:
     new 784a52780 [CELEBORN-2071] Fix the issue where some gauge metrics were 
not registered to the metricRegistry
784a52780 is described below

commit 784a52780852ccbc1c32a3cbd6484079baa6b9ee
Author: TheodoreLx <[email protected]>
AuthorDate: Thu Jul 24 16:15:21 2025 +0800

    [CELEBORN-2071] Fix the issue where some gauge metrics were not registered 
to the metricRegistry
    
    ### What changes were proposed in this pull request?
    
    add code to register gauge to metricRegistry in addGauge method
    
    ### Why are the changes needed?
    
    Because one implementation of addGauge does not register the gauge to the 
metricRegistry, some Sink implementation classes cannot export these gauge 
metrics. For example, you cannot see JVMCPUTime in the metric file printed by 
CsvSink, because CsvSink only prints metrics from the registry variable in 
MetricsSystem.
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    cluster test
    
    Closes #3369 from TheodoreLx/fix-gauge-missing.
    
    Lead-authored-by: TheodoreLx <[email protected]>
    Co-authored-by: TheodoreLx <[email protected] >
    Signed-off-by: SteNicholas <[email protected]>
    (cherry picked from commit 4656bcb98af7eb41c60278f5e2feacb26b2498e7)
    Signed-off-by: SteNicholas <[email protected]>
---
 .../apache/celeborn/common/metrics/source/AbstractSource.scala | 10 +++++++---
 1 file changed, 7 insertions(+), 3 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 c5407315a..43e8ee28d 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
@@ -109,9 +109,13 @@ abstract class AbstractSource(conf: CelebornConf, role: 
String)
       gauge: Gauge[T]): Unit = {
     // filter out non-number type gauges
     if (gauge.getValue.isInstanceOf[Number]) {
-      namedGauges.putIfAbsent(
-        metricNameWithCustomizedLabels(name, labels),
-        NamedGauge(name, gauge, labels ++ staticLabels))
+      val metricNameWithLabel = metricNameWithCustomizedLabels(name, labels)
+      namedGauges.putIfAbsent(metricNameWithLabel, NamedGauge(name, gauge, 
labels ++ staticLabels))
+      metricRegistry.synchronized({
+        if (!metricRegistry.getMetrics.containsKey(metricNameWithLabel)) {
+          metricRegistry.register(metricNameWithLabel, gauge)
+        }
+      })
     } else {
       logWarning(
         s"Add gauge $name failed, the value type ${gauge.getValue.getClass} is 
not a number")

Reply via email to