yandrey321 commented on code in PR #11719:
URL: https://github.com/apache/ozone/pull/11719#discussion_r4379061290
##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientMetrics.java:
##########
@@ -79,13 +94,67 @@ public void init() {
}
}
+ /**
+ * Set by each {@link XceiverClientCreator} from its configuration; read
when the metrics are created.
+ */
+ public static void setMetricsMode(MetricsMode mode) {
+ metricsMode = mode;
+ }
+
public static XceiverClientMetrics create() {
- DefaultMetricsSystem.initialize(SOURCE_NAME);
+ if (startsMetricsSystem(metricsMode, classLoader())) {
+ DefaultMetricsSystem.initialize(SOURCE_NAME);
+ }
+ // Registering is cheap without a started metrics system: the source goes
live if the system starts later.
MetricsSystem ms = DefaultMetricsSystem.instance();
return ms.register(SOURCE_NAME, "Storage Container Client Metrics",
new XceiverClientMetrics());
}
+ static boolean startsMetricsSystem(MetricsMode mode, ClassLoader loader) {
+ switch (mode) {
+ case ALWAYS:
+ return true;
+ case NEVER:
+ return false;
+ default:
+ return isSinkConfigured(SOURCE_NAME, loader);
+ }
+ }
+
+ /**
+ * Whether the metrics system would configure a sink for the prefix. Same
lookup as Hadoop's MetricsConfig:
+ * the first of hadoop-metrics2-[prefix].properties and
hadoop-metrics2.properties found on the classpath, with
+ * [prefix].sink.[instance].[option] keys; "*.sink" keys only supply
defaults. Uses java.util.Properties to avoid
+ * loading Commons Configuration.
+ */
+ static boolean isSinkConfigured(String prefix, ClassLoader loader) {
+ final String lowerPrefix = StringUtils.toLowerCase(prefix);
+ for (String name : new String[] {"hadoop-metrics2-" + lowerPrefix +
".properties", "hadoop-metrics2.properties"}) {
+ final URL url = loader.getResource(name);
+ if (url == null) {
+ continue;
Review Comment:
Fixed.
AUTO now looks for the two files where Hadoop's MetricsConfig does: through
Commons Configuration's default location strategy, a relative file name is
found in the working directory, then the user's home directory, then on the
classpath (context class loader, then system class loader). The client-specific
file wins wherever it is found, as in MetricsConfig.loadFirst. The lookup is in
XceiverClientMetrics.metricsConfigLocator, and the files are still read with
java.util.Properties, so Commons Configuration isn't loaded.
TestXceiverClientMetricsMode now covers the working directory, the home
directory and their precedence over each other and the classpath.
--
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]