tillrohrmann commented on a change in pull request #8373:
[FLINK-11922][metrics] Support MetricReporter factories
URL: https://github.com/apache/flink/pull/8373#discussion_r282397203
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/metrics/ReporterSetup.java
##########
@@ -131,46 +137,119 @@ private static ReporterSetup createReporterSetup(String
reporterName, MetricConf
}
}
- List<Tuple2<String, Configuration>> reporterConfigurations;
-
if (namedReporters.isEmpty()) {
- reporterConfigurations = Collections.emptyList();
- } else {
- reporterConfigurations = new
ArrayList<>(namedReporters.size());
+ return Collections.emptyList();
+ }
- for (String namedReporter: namedReporters) {
- DelegatingConfiguration delegatingConfiguration
= new DelegatingConfiguration(
- configuration,
- ConfigConstants.METRICS_REPORTER_PREFIX
+ namedReporter + '.');
+ List<Tuple2<String, Configuration>> reporterConfigurations =
new ArrayList<>(namedReporters.size());
-
reporterConfigurations.add(Tuple2.of(namedReporter, (Configuration)
delegatingConfiguration));
- }
+ for (String namedReporter: namedReporters) {
+ DelegatingConfiguration delegatingConfiguration = new
DelegatingConfiguration(
+ configuration,
+ ConfigConstants.METRICS_REPORTER_PREFIX +
namedReporter + '.');
+
+ reporterConfigurations.add(Tuple2.of(namedReporter,
(Configuration) delegatingConfiguration));
}
+ final Collection<MetricReporterFactory> reporterFactories =
loadReporterFactories();
List<ReporterSetup> reporterArguments = new
ArrayList<>(reporterConfigurations.size());
for (Tuple2<String, Configuration> reporterConfiguration:
reporterConfigurations) {
String reporterName = reporterConfiguration.f0;
Configuration reporterConfig = reporterConfiguration.f1;
try {
- final String reporterClassName =
reporterConfig.getString(ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, null);
- if (reporterClassName == null) {
- LOG.error("No reporter class set for
reporter " + reporterName + ". Metrics might not be exposed/reported.");
- continue;
- }
-
- Class<?> reporterClass =
Class.forName(reporterClassName);
- MetricReporter reporter = (MetricReporter)
reporterClass.newInstance();
+ Optional<MetricReporter> metricReporterOptional
= loadReporter(reporterName, reporterConfig, reporterFactories);
+ if (metricReporterOptional.isPresent()) {
+ MetricReporter reporter =
metricReporterOptional.get();
- MetricConfig metricConfig = new MetricConfig();
- reporterConfig.addAllToProperties(metricConfig);
+ MetricConfig metricConfig = new
MetricConfig();
+
reporterConfig.addAllToProperties(metricConfig);
-
reporterArguments.add(createReporterSetup(reporterName, metricConfig,
reporter));
+
reporterArguments.add(createReporterSetup(reporterName, metricConfig,
reporter));
+ }
}
catch (Throwable t) {
LOG.error("Could not instantiate metrics
reporter {}. Metrics might not be exposed/reported.", reporterName, t);
}
}
return reporterArguments;
}
+
+ private static Collection<MetricReporterFactory>
loadReporterFactories() {
+ final ServiceLoader<MetricReporterFactory> serviceLoader =
ServiceLoader.load(MetricReporterFactory.class);
+
+ final Collection<MetricReporterFactory> reporterFactories = new
ArrayList<>();
Review comment:
Specify capacity.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services