public static MetricRegistry createRegistryForMasterCoprocessor(String clazz) { return MetricRegistries.global().create(createRegistryInfoForMasterCoprocessor(clazz)); }
@Test public void testMasterObserver() throws IOException { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForMasterCoprocessor( CustomMasterObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("CreateTable"); assertTrue(metric.isPresent()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { Timer createTableTimer = (Timer)metric.get(); long prevCount = createTableTimer.getHistogram().getCount(); LOG.info("Creating table"); admin.createTable( new HTableDescriptor(TableName.valueOf(name.getMethodName())) .addFamily(new HColumnDescriptor("foo"))); assertEquals(1, createTableTimer.getHistogram().getCount() - prevCount); } }
@Test public void testMasterObserver() throws IOException { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForMasterCoprocessor( CustomMasterObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("CreateTable"); assertTrue(metric.isPresent()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { Timer createTableTimer = (Timer)metric.get(); long prevCount = createTableTimer.getHistogram().getCount(); LOG.info("Creating table"); admin.createTable( new HTableDescriptor(TableName.valueOf(name.getMethodName())) .addFamily(new HColumnDescriptor("foo"))); assertEquals(1, createTableTimer.getHistogram().getCount() - prevCount); } }