use of org.apache.flink.metrics.reporter.MetricReporterFactory in project flink by apache.
the class ReporterSetup method setupReporters.
private static List<ReporterSetup> setupReporters(Map<String, MetricReporterFactory> reporterFactories, List<Tuple2<String, Configuration>> reporterConfigurations) {
List<ReporterSetup> reporterSetups = new ArrayList<>(reporterConfigurations.size());
for (Tuple2<String, Configuration> reporterConfiguration : reporterConfigurations) {
String reporterName = reporterConfiguration.f0;
Configuration reporterConfig = reporterConfiguration.f1;
try {
Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories);
// massage user variables keys into scope format for parity to variable exclusion
Map<String, String> additionalVariables = reporterConfig.get(ADDITIONAL_VARIABLES).entrySet().stream().collect(Collectors.toMap(e -> ScopeFormat.asVariable(e.getKey()), Entry::getValue));
metricReporterOptional.ifPresent(reporter -> {
MetricConfig metricConfig = new MetricConfig();
reporterConfig.addAllToProperties(metricConfig);
reporterSetups.add(createReporterSetup(reporterName, metricConfig, reporter, additionalVariables));
});
} catch (Throwable t) {
LOG.error("Could not instantiate metrics reporter {}. Metrics might not be exposed/reported.", reporterName, t);
}
}
return reporterSetups;
}
use of org.apache.flink.metrics.reporter.MetricReporterFactory in project flink by apache.
the class ReporterSetup method loadAvailableReporterFactories.
private static Map<String, MetricReporterFactory> loadAvailableReporterFactories(@Nullable PluginManager pluginManager) {
final Map<String, MetricReporterFactory> reporterFactories = new HashMap<>(2);
final Iterator<MetricReporterFactory> factoryIterator = getAllReporterFactories(pluginManager);
// non-existing factory class
while (factoryIterator.hasNext()) {
try {
MetricReporterFactory factory = factoryIterator.next();
String factoryClassName = factory.getClass().getName();
MetricReporterFactory existingFactory = reporterFactories.get(factoryClassName);
if (existingFactory == null) {
reporterFactories.put(factoryClassName, factory);
LOG.debug("Found reporter factory {} at {} ", factoryClassName, new File(factory.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getCanonicalPath());
} else {
LOG.warn("Multiple implementations of the same reporter were found in 'lib' and/or 'plugins' directories for {}. It is recommended to remove redundant reporter JARs to resolve used versions' ambiguity.", factoryClassName);
}
} catch (Exception | ServiceConfigurationError e) {
LOG.warn("Error while loading reporter factory.", e);
}
}
return Collections.unmodifiableMap(reporterFactories);
}
Aggregations