chungen0126 commented on code in PR #10763:
URL: https://github.com/apache/ozone/pull/10763#discussion_r4332684203


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/util/MetricUtil.java:
##########
@@ -110,6 +114,28 @@ public static List<MutableQuantiles> 
createQuantiles(MetricsRegistry registry,
     }).collect(Collectors.toList());
   }
 
+  /**
+   * Qualifies a metrics-source name with a per-instance component, per
+   * {@link 
org.apache.hadoop.hdds.HddsConfigKeys#HDDS_METRICS_SOURCE_DISAMBIGUATION_ENABLED}.
+   * A null or empty {@code component} leaves standalone services on their 
original names.
+   * Non-alphanumeric characters are dropped from {@code component}, so the 
datanode UUID
+   * {@code abc-123} yields {@code <base>.abc123}. Recon resolves datanode 
metrics by these bean
+   * names, so the spelling is a contract rather than cosmetic.
+   */
+  public static String qualifySourceName(String base, String component) {
+    return component == null || component.isEmpty() ? base
+        : base + "." + component.replaceAll("[^A-Za-z0-9]+", "");
+  }
+
+  /**
+   * Intended as the argument for {@link #qualifySourceName(String, 
String)}-based factory
+   * methods, so a call site passes a component without testing the key itself.
+   */
+  public static String metricsSourceComponent(ConfigurationSource conf, String 
component) {
+    return conf.getBoolean(HDDS_METRICS_SOURCE_DISAMBIGUATION_ENABLED,
+        HDDS_METRICS_SOURCE_DISAMBIGUATION_ENABLED_DEFAULT) ? component : null;
+  }

Review Comment:
   Thanks @henrybear327 for working on this. 
   
   Relying on null across this two-step API forces ~19 constructors and call 
sites to coordinate both helpers manually (e.g., SCMMetrics/OMMetrics).
   
   Can we centralize this into something like MetricUtil.sourceName(conf, base, 
component)? Passing down the resolved name would eliminate null propagation.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to