@Test public void testActivateOneReporterAmongTwoDeclared() { final Configuration config = new Configuration(); configureReporter1(config); configureReporter2(config); config.setString(MetricOptions.REPORTERS_LIST, "reporter2"); final List<ReporterSetup> reporterSetups = ReporterSetup.fromConfiguration(config); Assert.assertEquals(1, reporterSetups.size()); final ReporterSetup setup = reporterSetups.get(0); assertReporter2Configured(setup); }
public static List<ReporterSetup> fromConfiguration(final Configuration configuration) { String includedReportersString = configuration.getString(MetricOptions.REPORTERS_LIST, ""); Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString) .filter(r -> !r.isEmpty()) .collect(Collectors.toSet()); Set<String> namedReporters = new TreeSet<>(String::compareTo); for (String key : configuration.keySet()) { if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) { Matcher matcher = reporterClassPattern.matcher(key); if (matcher.matches()) { String reporterName = matcher.group(1); if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) { if (namedReporters.contains(reporterName)) { LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName); } else { namedReporters.add(reporterName); } } else { LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString); } } } } if (namedReporters.isEmpty()) { return Collections.emptyList(); } List<Tuple2<String, Configuration>> reporterConfigurations = new ArrayList<>(namedReporters.size()); for (String namedReporter: namedReporters) { DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration( configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.'); reporterConfigurations.add(Tuple2.of(namedReporter, delegatingConfiguration)); } final Map<String, 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 { Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories); metricReporterOptional.ifPresent(reporter -> { MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); 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; }
ReporterSetup { public static List<ReporterSetup> fromConfiguration(final Configuration configuration) { String includedReportersString = configuration.getString(MetricOptions.REPORTERS_LIST, ""); Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString) .filter(r -> !r.isEmpty()) .collect(Collectors.toSet()); Set<String> namedReporters = new TreeSet<>(String::compareTo); for (String key : configuration.keySet()) { if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) { Matcher matcher = reporterClassPattern.matcher(key); if (matcher.matches()) { String reporterName = matcher.group(1); if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) { if (namedReporters.contains(reporterName)) { LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName); } else { namedReporters.add(reporterName); } } else { LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString); } } } } if (namedReporters.isEmpty()) { return Collections.emptyList(); } List<Tuple2<String, Configuration>> reporterConfigurations = new ArrayList<>(namedReporters.size()); for (String namedReporter: namedReporters) { DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration( configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.'); reporterConfigurations.add(Tuple2.of(namedReporter, delegatingConfiguration)); } final Map<String, 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 { Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories); metricReporterOptional.ifPresent(reporter -> { MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); 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; } }
ReporterSetup { public static List<ReporterSetup> fromConfiguration(final Configuration configuration) { String includedReportersString = configuration.getString(MetricOptions.REPORTERS_LIST, ""); Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString) .filter(r -> !r.isEmpty()) .collect(Collectors.toSet()); Set<String> namedReporters = new TreeSet<>(String::compareTo); for (String key : configuration.keySet()) { if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) { Matcher matcher = reporterClassPattern.matcher(key); if (matcher.matches()) { String reporterName = matcher.group(1); if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) { if (namedReporters.contains(reporterName)) { LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName); } else { namedReporters.add(reporterName); } } else { LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString); } } } } if (namedReporters.isEmpty()) { return Collections.emptyList(); } List<Tuple2<String, Configuration>> reporterConfigurations = new ArrayList<>(namedReporters.size()); for (String namedReporter: namedReporters) { DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration( configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.'); reporterConfigurations.add(Tuple2.of(namedReporter, delegatingConfiguration)); } final Map<String, 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 { Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories); metricReporterOptional.ifPresent(reporter -> { MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); 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; } ReporterSetup(final String name, final MetricConfig configuration, MetricReporter reporter); }
ReporterSetup { public static List<ReporterSetup> fromConfiguration(final Configuration configuration) { String includedReportersString = configuration.getString(MetricOptions.REPORTERS_LIST, ""); Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString) .filter(r -> !r.isEmpty()) .collect(Collectors.toSet()); Set<String> namedReporters = new TreeSet<>(String::compareTo); for (String key : configuration.keySet()) { if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) { Matcher matcher = reporterClassPattern.matcher(key); if (matcher.matches()) { String reporterName = matcher.group(1); if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) { if (namedReporters.contains(reporterName)) { LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName); } else { namedReporters.add(reporterName); } } else { LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString); } } } } if (namedReporters.isEmpty()) { return Collections.emptyList(); } List<Tuple2<String, Configuration>> reporterConfigurations = new ArrayList<>(namedReporters.size()); for (String namedReporter: namedReporters) { DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration( configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.'); reporterConfigurations.add(Tuple2.of(namedReporter, delegatingConfiguration)); } final Map<String, 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 { Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories); metricReporterOptional.ifPresent(reporter -> { MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); 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; } ReporterSetup(final String name, final MetricConfig configuration, MetricReporter reporter); Optional<String> getDelimiter(); Optional<String> getIntervalSettings(); String getName(); MetricReporter getReporter(); @VisibleForTesting static ReporterSetup forReporter(String reporterName, MetricReporter reporter); @VisibleForTesting static ReporterSetup forReporter(String reporterName, MetricConfig metricConfig, MetricReporter reporter); static List<ReporterSetup> fromConfiguration(final Configuration configuration); }
ReporterSetup { public static List<ReporterSetup> fromConfiguration(final Configuration configuration) { String includedReportersString = configuration.getString(MetricOptions.REPORTERS_LIST, ""); Set<String> includedReporters = reporterListPattern.splitAsStream(includedReportersString) .filter(r -> !r.isEmpty()) .collect(Collectors.toSet()); Set<String> namedReporters = new TreeSet<>(String::compareTo); for (String key : configuration.keySet()) { if (key.startsWith(ConfigConstants.METRICS_REPORTER_PREFIX)) { Matcher matcher = reporterClassPattern.matcher(key); if (matcher.matches()) { String reporterName = matcher.group(1); if (includedReporters.isEmpty() || includedReporters.contains(reporterName)) { if (namedReporters.contains(reporterName)) { LOG.warn("Duplicate class configuration detected for reporter {}.", reporterName); } else { namedReporters.add(reporterName); } } else { LOG.info("Excluding reporter {}, not configured in reporter list ({}).", reporterName, includedReportersString); } } } } if (namedReporters.isEmpty()) { return Collections.emptyList(); } List<Tuple2<String, Configuration>> reporterConfigurations = new ArrayList<>(namedReporters.size()); for (String namedReporter: namedReporters) { DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration( configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.'); reporterConfigurations.add(Tuple2.of(namedReporter, delegatingConfiguration)); } final Map<String, 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 { Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories); metricReporterOptional.ifPresent(reporter -> { MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); 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; } ReporterSetup(final String name, final MetricConfig configuration, MetricReporter reporter); Optional<String> getDelimiter(); Optional<String> getIntervalSettings(); String getName(); MetricReporter getReporter(); @VisibleForTesting static ReporterSetup forReporter(String reporterName, MetricReporter reporter); @VisibleForTesting static ReporterSetup forReporter(String reporterName, MetricConfig metricConfig, MetricReporter reporter); static List<ReporterSetup> fromConfiguration(final Configuration configuration);  }