use of org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName in project flink by apache.
the class MetricRegistryImplTest method testConfigurableDelimiterForReportersInGroup.
@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
String name = "C";
MetricConfig config1 = new MetricConfig();
config1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
MetricConfig config2 = new MetricConfig();
config2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
MetricConfig config3 = new MetricConfig();
config3.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
Configuration config = new Configuration();
config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
List<ReporterSetup> reporterConfigurations = Arrays.asList(ReporterSetup.forReporter("test1", config1, new CollectingMetricsReporter()), ReporterSetup.forReporter("test2", config2, new CollectingMetricsReporter()), ReporterSetup.forReporter("test3", config3, new CollectingMetricsReporter()), ReporterSetup.forReporter("test4", new CollectingMetricsReporter()));
MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(config), reporterConfigurations);
TaskManagerMetricGroup group = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
group.counter(name);
group.close();
registry.shutdown().get();
for (ReporterSetup cfg : reporterConfigurations) {
String delimiter = cfg.getConfiguration().getProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER);
if (delimiter == null || delimiter.equals("AA")) {
// test3 reporter: 'AA' - not correct
// for test4 reporter use global delimiter
delimiter = String.valueOf(GLOBAL_DEFAULT_DELIMITER);
}
String expected = (config.get(MetricOptions.SCOPE_NAMING_TM) + ".C").replaceAll("\\.", delimiter);
CollectingMetricsReporter reporter = (CollectingMetricsReporter) cfg.getReporter();
for (MetricGroupAndName groupAndName : Arrays.asList(reporter.findAdded(name), reporter.findRemoved(name))) {
assertEquals(expected, groupAndName.group.getMetricIdentifier(name));
assertEquals(expected, groupAndName.group.getMetricIdentifier(name, reporter));
}
}
}
use of org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName in project flink by apache.
the class AbstractMetricGroupTest method testScopeCachingForMultipleReporters.
@Test
public void testScopeCachingForMultipleReporters() throws Exception {
String counterName = "1";
Configuration config = new Configuration();
config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");
MetricConfig metricConfig1 = new MetricConfig();
metricConfig1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
MetricConfig metricConfig2 = new MetricConfig();
metricConfig2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");
CollectingMetricsReporter reporter1 = new CollectingMetricsReporter(FILTER_B);
CollectingMetricsReporter reporter2 = new CollectingMetricsReporter(FILTER_C);
MetricRegistryImpl testRegistry = new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(config), Arrays.asList(ReporterSetup.forReporter("test1", metricConfig1, reporter1), ReporterSetup.forReporter("test2", metricConfig2, reporter2)));
try {
MetricGroup tmGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(testRegistry, "host", new ResourceID("id"));
tmGroup.counter(counterName);
assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size());
{
// verify reporter1
MetricGroupAndName nameAndGroup = reporter1.getAddedMetrics().stream().filter(nag -> nag.name.equals(counterName)).findAny().get();
String metricName = nameAndGroup.name;
MetricGroup group = nameAndGroup.group;
// the first call determines which filter is applied to all future
// calls; in
// this case
// no filter is used at all
assertEquals("A-B-C-D-1", group.getMetricIdentifier(metricName));
// from now on the scope string is cached and should not be reliant
// on the
// given filter
assertEquals("A-B-C-D-1", group.getMetricIdentifier(metricName, FILTER_C));
assertEquals("A-B-C-D-1", group.getMetricIdentifier(metricName, reporter1));
// the metric name however is still affected by the filter as it is
// not
// cached
assertEquals("A-B-C-D-4", group.getMetricIdentifier(metricName, input -> input.replace("B", "X").replace(counterName, "4")));
}
{
// verify reporter2
MetricGroupAndName nameAndGroup = reporter2.getAddedMetrics().stream().filter(nag -> nag.name.equals(counterName)).findAny().get();
String metricName = nameAndGroup.name;
MetricGroup group = nameAndGroup.group;
// the first call determines which filter is applied to all future calls
assertEquals("A!B!X!D!1", group.getMetricIdentifier(metricName, reporter2));
// from now on the scope string is cached and should not be reliant on the given
// filter
assertEquals("A!B!X!D!1", group.getMetricIdentifier(metricName));
assertEquals("A!B!X!D!1", group.getMetricIdentifier(metricName, FILTER_C));
// the metric name however is still affected by the filter as it is not cached
assertEquals("A!B!X!D!3", group.getMetricIdentifier(metricName, input -> input.replace("A", "X").replace(counterName, "3")));
}
} finally {
testRegistry.shutdown().get();
}
}
Aggregations