@Test public void testScopeCachingForMultipleReporters() throws Exception { 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, TestReporter1.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, TestReporter2.class.getName()); config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!"); MetricRegistryImpl testRegistry = new MetricRegistryImpl( MetricRegistryConfiguration.fromConfiguration(config), Arrays.asList( ReporterSetup.forReporter("test1", metricConfig1, new TestReporter1()), ReporterSetup.forReporter("test2", metricConfig2, new TestReporter2()))); try { MetricGroup tmGroup = new TaskManagerMetricGroup(testRegistry, "host", "id"); tmGroup.counter("1"); assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size()); for (MetricReporter reporter : testRegistry.getReporters()) { ScopeCheckingTestReporter typedReporter = (ScopeCheckingTestReporter) reporter; if (typedReporter.failureCause != null) { throw typedReporter.failureCause; } } } finally { testRegistry.shutdown().get(); } }
@Override public Counter counter(int name) { return counter(String.valueOf(name)); }
AbstractMetricGroup implements MetricGroup { @Override public Counter counter(int name) { return counter(String.valueOf(name)); } }
AbstractMetricGroup implements MetricGroup { @Override public Counter counter(int name) { return counter(String.valueOf(name)); } AbstractMetricGroup(MetricRegistry registry, String[] scope, A parent); }
AbstractMetricGroup implements MetricGroup { @Override public Counter counter(int name) { return counter(String.valueOf(name)); } AbstractMetricGroup(MetricRegistry registry, String[] scope, A parent); Map<String, String> getAllVariables(); String getLogicalScope(CharacterFilter filter); String getLogicalScope(CharacterFilter filter, char delimiter); String[] getScopeComponents(); QueryScopeInfo getQueryServiceMetricInfo(CharacterFilter filter); String getMetricIdentifier(String metricName); String getMetricIdentifier(String metricName, CharacterFilter filter); String getMetricIdentifier(String metricName, CharacterFilter filter, int reporterIndex); void close(); final boolean isClosed(); @Override Counter counter(int name); @Override Counter counter(String name); @Override C counter(int name, C counter); @Override C counter(String name, C counter); @Override G gauge(int name, G gauge); @Override G gauge(String name, G gauge); @Override H histogram(int name, H histogram); @Override H histogram(String name, H histogram); @Override M meter(int name, M meter); @Override M meter(String name, M meter); @Override MetricGroup addGroup(int name); @Override MetricGroup addGroup(String name); @Override MetricGroup addGroup(String key, String value); }
AbstractMetricGroup implements MetricGroup { @Override public Counter counter(int name) { return counter(String.valueOf(name)); } AbstractMetricGroup(MetricRegistry registry, String[] scope, A parent); Map<String, String> getAllVariables(); String getLogicalScope(CharacterFilter filter); String getLogicalScope(CharacterFilter filter, char delimiter); String[] getScopeComponents(); QueryScopeInfo getQueryServiceMetricInfo(CharacterFilter filter); String getMetricIdentifier(String metricName); String getMetricIdentifier(String metricName, CharacterFilter filter); String getMetricIdentifier(String metricName, CharacterFilter filter, int reporterIndex); void close(); final boolean isClosed(); @Override Counter counter(int name); @Override Counter counter(String name); @Override C counter(int name, C counter); @Override C counter(String name, C counter); @Override G gauge(int name, G gauge); @Override G gauge(String name, G gauge); @Override H histogram(int name, H histogram); @Override H histogram(String name, H histogram); @Override M meter(int name, M meter); @Override M meter(String name, M meter); @Override MetricGroup addGroup(int name); @Override MetricGroup addGroup(String name); @Override MetricGroup addGroup(String key, String value);  }