private void registerSystemSource() { MetricsConfig sysConf = sourceConfigs.get(MS_NAME); sysSource = new MetricsSourceAdapter(prefix, MS_STATS_NAME, MS_STATS_DESC, MetricsAnnotations.makeSource(this), injectedTags, period, sysConf == null ? config.subset(SOURCE_KEY) : sysConf); sysSource.start(); }
@Override public synchronized <T> T register(String name, String desc, T source) { MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); MetricsInfo si = sb.info(); String name2 = name == null ? si.name() : name; final String finalDesc = desc == null ? si.description() : desc; final String finalName = // be friendly to non-metrics tests DefaultMetricsSystem.sourceName(name2, !monitoring); allSources.put(finalName, s); LOG.debug(finalName +", "+ finalDesc); if (monitoring) { registerSource(finalName, finalDesc, s); } // We want to re-register the source to pick up new config when the // metrics system restarts. register(finalName, new AbstractCallback() { @Override public void postStart() { registerSource(finalName, finalDesc, s); } }); return source; }
private void registerSystemSource() { MetricsConfig sysConf = sourceConfigs.get(MS_NAME); sysSource = new MetricsSourceAdapter(prefix, MS_STATS_NAME, MS_STATS_DESC, MetricsAnnotations.makeSource(this), injectedTags, period, sysConf == null ? config.subset(SOURCE_KEY) : sysConf); sysSource.start(); }
@Override public synchronized <T> T register(String name, String desc, T source) { MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); MetricsInfo si = sb.info(); String name2 = name == null ? si.name() : name; final String finalDesc = desc == null ? si.description() : desc; final String finalName = // be friendly to non-metrics tests DefaultMetricsSystem.sourceName(name2, !monitoring); allSources.put(finalName, s); LOG.debug(finalName +", "+ finalDesc); if (monitoring) { registerSource(finalName, finalDesc, s); } // We want to re-register the source to pick up new config when the // metrics system restarts. register(finalName, new AbstractCallback() { @Override public void postStart() { registerSource(finalName, finalDesc, s); } }); return source; }
private void registerSystemSource() { MetricsConfig sysConf = sourceConfigs.get(MS_NAME); sysSource = new MetricsSourceAdapter(prefix, MS_STATS_NAME, MS_STATS_DESC, MetricsAnnotations.makeSource(this), injectedTags, period * 1000L, sysConf == null ? config.subset(SOURCE_KEY) : sysConf); sysSource.start(); }
@Override public synchronized <T> T register(String name, String desc, T source) { MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); MetricsInfo si = sb.info(); String name2 = name == null ? si.name() : name; final String finalDesc = desc == null ? si.description() : desc; final String finalName = // be friendly to non-metrics tests DefaultMetricsSystem.sourceName(name2, !monitoring); allSources.put(finalName, s); LOG.debug(finalName +", "+ finalDesc); if (monitoring) { registerSource(finalName, finalDesc, s); } // We want to re-register the source to pick up new config when the // metrics system restarts. register(finalName, new AbstractCallback() { @Override public void postStart() { registerSource(finalName, finalDesc, s); } }); return source; }
private void registerSystemSource() { MetricsConfig sysConf = sourceConfigs.get(MS_NAME); sysSource = new MetricsSourceAdapter(prefix, MS_STATS_NAME, MS_STATS_DESC, MetricsAnnotations.makeSource(this), injectedTags, period * 1000L, sysConf == null ? config.subset(SOURCE_KEY) : sysConf); sysSource.start(); }
@Override public synchronized <T> T register(String name, String desc, T source) { MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); MetricsInfo si = sb.info(); String name2 = name == null ? si.name() : name; final String finalDesc = desc == null ? si.description() : desc; final String finalName = // be friendly to non-metrics tests DefaultMetricsSystem.sourceName(name2, !monitoring); allSources.put(finalName, s); LOG.debug(finalName +", "+ finalDesc); if (monitoring) { registerSource(finalName, finalDesc, s); } // We want to re-register the source to pick up new config when the // metrics system restarts. register(finalName, new AbstractCallback() { @Override public void postStart() { registerSource(finalName, finalDesc, s); } }); return source; }
private void registerSystemSource() { MetricsConfig sysConf = sourceConfigs.get(MS_NAME); sysSource = new MetricsSourceAdapter(prefix, MS_STATS_NAME, MS_STATS_DESC, MetricsAnnotations.makeSource(this), injectedTags, period * 1000L, sysConf == null ? config.subset(SOURCE_KEY) : sysConf); sysSource.start(); }
@Override public synchronized <T> T register(String name, String desc, T source) { MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); MetricsInfo si = sb.info(); String name2 = name == null ? si.name() : name; final String finalDesc = desc == null ? si.description() : desc; final String finalName = // be friendly to non-metrics tests DefaultMetricsSystem.sourceName(name2, !monitoring); allSources.put(finalName, s); LOG.debug(finalName +", "+ finalDesc); if (monitoring) { registerSource(finalName, finalDesc, s); } // We want to re-register the source to pick up new config when the // metrics system restarts. register(finalName, new AbstractCallback() { @Override public void postStart() { registerSource(finalName, finalDesc, s); } }); return source; }
@Test(expected=MetricsException.class) public void testBadMethodReturnType() { MetricsAnnotations.makeSource(new BadMetrics3()); }
@Test public void testPurgeOldMetrics() throws Exception { // create test source with a single metric counter of value 1 PurgableSource source = new PurgableSource(); MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); List<MetricsTag> injectedTags = new ArrayList<MetricsTag>(); MetricsSourceAdapter sa = new MetricsSourceAdapter( "tst", "tst", "testdesc", s, injectedTags, null, null, 1, false); MBeanInfo info = sa.getMBeanInfo(); boolean sawIt = false; for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) { sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName); }; assertTrue("The last generated metric is not exported to jmx", sawIt); Thread.sleep(1000); // skip JMX cache TTL info = sa.getMBeanInfo(); sawIt = false; for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) { sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName); }; assertTrue("The last generated metric is not exported to jmx", sawIt); }
@Test(expected=IllegalArgumentException.class) public void testBadMethodWithArgs() { MetricsAnnotations.makeSource(new BadMetrics2()); }
@Test public void testPurgeOldMetrics() throws Exception { // create test source with a single metric counter of value 1 PurgableSource source = new PurgableSource(); MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); List<MetricsTag> injectedTags = new ArrayList<MetricsTag>(); MetricsSourceAdapter sa = new MetricsSourceAdapter( "tst", "tst", "testdesc", s, injectedTags, null, null, 1, false); MBeanInfo info = sa.getMBeanInfo(); boolean sawIt = false; for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) { sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName); }; assertTrue("The last generated metric is not exported to jmx", sawIt); Thread.sleep(1000); // skip JMX cache TTL info = sa.getMBeanInfo(); sawIt = false; for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) { sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName); }; assertTrue("The last generated metric is not exported to jmx", sawIt); }
@Test(expected=MetricsException.class) public void testBadMethodReturnType() { MetricsAnnotations.makeSource(new BadMetrics3()); }
MetricsAnnotations.newSourceBuilder(source);
@Test(expected=MetricsException.class) public void testEmptyMetrics() { MetricsAnnotations.makeSource(new EmptyMetrics()); } }
MetricsAnnotations.newSourceBuilder(source);
@Test(expected=IllegalArgumentException.class) public void testBadMethodWithArgs() { MetricsAnnotations.makeSource(new BadMetrics2()); }
@Test public void testGetMetricsAndJmx() throws Exception { // create test source with a single metric counter of value 0 TestSource source = new TestSource("test"); MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source); final MetricsSource s = sb.build(); List<MetricsTag> injectedTags = new ArrayList<MetricsTag>(); MetricsSourceAdapter sa = new MetricsSourceAdapter( "test", "test", "test desc", s, injectedTags, null, null, 1, false); // all metrics are initially assumed to have changed MetricsCollectorImpl builder = new MetricsCollectorImpl(); Iterable<MetricsRecordImpl> metricsRecords = sa.getMetrics(builder, true); // Validate getMetrics and JMX initial values MetricsRecordImpl metricsRecord = metricsRecords.iterator().next(); assertEquals(0L, metricsRecord.metrics().iterator().next().value().longValue()); Thread.sleep(100); // skip JMX cache TTL assertEquals(0L, (Number)sa.getAttribute("C1")); // change metric value source.incrementCnt(); // validate getMetrics and JMX builder = new MetricsCollectorImpl(); metricsRecords = sa.getMetrics(builder, true); metricsRecord = metricsRecords.iterator().next(); assertTrue(metricsRecord.metrics().iterator().hasNext()); Thread.sleep(100); // skip JMX cache TTL assertEquals(1L, (Number)sa.getAttribute("C1")); }