yandrey321 commented on code in PR #11719:
URL: https://github.com/apache/ozone/pull/11719#discussion_r4379053355
##########
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;
+ }
+ final Properties properties = new Properties();
+ try (InputStream in = url.openStream()) {
+ properties.load(in);
Review Comment:
Fixed conservatively. If the file AUTO finds contains an include or
includeoptional directive (case-insensitive, as Commons Configuration matches
it), the client now starts the metrics system as before, since the included
files may configure the sink. I didn't resolve the includes: MetricsConfig
splits the value on commas, interpolates it and resolves it relative to the
including file, which would mean reimplementing part of Commons Configuration
for a rare setup. TestXceiverClientMetricsMode covers both directives, mixed
case, and an include in either file.
--
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]