public static MetricRegistry createRegistryForMasterCoprocessor(String clazz) { return MetricRegistries.global().create(createRegistryInfoForMasterCoprocessor(clazz)); }
public static MetricRegistry createRegistryForRSCoprocessor(String clazz) { return MetricRegistries.global().create(createRegistryInfoForRSCoprocessor(clazz)); }
public static MetricRegistry createRegistryForRegionCoprocessor(String clazz) { return MetricRegistries.global().create(createRegistryInfoForRegionCoprocessor(clazz)); }
public static MetricRegistry createRegistryForWALCoprocessor(String clazz) { return MetricRegistries.global().create(createRegistryInfoForWALCoprocessor(clazz)); }
@VisibleForTesting public static MetricRegistryInfo createRegistryInfoForRegionCoprocessor(String clazz) { return new MetricRegistryInfo( suffix(REGION_COPROC_METRICS_NAME, clazz), REGION_COPROC_METRICS_DESCRIPTION, suffix(REGION_COPROC_METRICS_JMX_CONTEXT, clazz), REGION_COPROC_METRICS_CONTEXT, false); }
@Override public void shutdown() { super.shutdown(); MetricsCoprocessor.removeRegistry(this.metricRegistry); } }
public MasterEnvironment(final MasterCoprocessor impl, final int priority, final int seq, final Configuration conf, final MasterServices services) { super(impl, priority, seq, conf); this.services = services; this.metricRegistry = MetricsCoprocessor.createRegistryForMasterCoprocessor(impl.getClass().getName()); }
/** * Constructor * @param impl the coprocessor instance * @param priority chaining priority * @param seq load sequence * @param conf configuration * @param wal WAL */ private WALEnvironment(final WALCoprocessor impl, final int priority, final int seq, final Configuration conf, final WAL wal) { super(impl, priority, seq, conf); this.wal = wal; this.metricRegistry = MetricsCoprocessor.createRegistryForWALCoprocessor( impl.getClass().getName()); }
/** * Constructor * @param impl the coprocessor instance * @param priority chaining priority */ public RegionEnvironment(final RegionCoprocessor impl, final int priority, final int seq, final Configuration conf, final Region region, final RegionServerServices services, final ConcurrentMap<String, Object> sharedData) { super(impl, priority, seq, conf); this.region = region; this.sharedData = sharedData; this.services = services; this.metricRegistry = MetricsCoprocessor.createRegistryForRegionCoprocessor(impl.getClass().getName()); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="BC_UNCONFIRMED_CAST", justification="Intentional; FB has trouble detecting isAssignableFrom") public RegionServerEnvironment(final RegionServerCoprocessor impl, final int priority, final int seq, final Configuration conf, final RegionServerServices services) { super(impl, priority, seq, conf); // If coprocessor exposes any services, register them. for (Service service : impl.getServices()) { services.registerService(service); } this.services = services; this.metricRegistry = MetricsCoprocessor.createRegistryForRSCoprocessor(impl.getClass().getName()); }
@Test public void testWALObserver() throws IOException { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForWALCoprocessor( CustomWALObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("walEditsCount"); assertTrue(metric.isPresent()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { admin.createTable( new HTableDescriptor(TableName.valueOf(name.getMethodName())) .addFamily(new HColumnDescriptor("foo"))); Counter rollWalRequests = (Counter)metric.get(); long prevCount = rollWalRequests.getCount(); assertTrue(prevCount > 0); try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) { table.put(new Put(foo).addColumn(foo, foo, foo)); } assertEquals(1, rollWalRequests.getCount() - prevCount); } }
@Override public void shutdown() { super.shutdown(); MetricsCoprocessor.removeRegistry(this.metricRegistry); } }
/** * Helper for below tests */ private void assertPreGetRequestsCounter(Class<?> coprocClass) { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor( coprocClass.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("preGetRequests"); assertTrue(metric.isPresent()); Counter preGetRequests = (Counter)metric.get(); assertEquals(2, preGetRequests.getCount()); }
@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 testWALObserver() throws IOException { // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForWALCoprocessor( CustomWALObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("walEditsCount"); assertTrue(metric.isPresent()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { admin.createTable( new HTableDescriptor(TableName.valueOf(name.getMethodName())) .addFamily(new HColumnDescriptor("foo"))); Counter rollWalRequests = (Counter)metric.get(); long prevCount = rollWalRequests.getCount(); assertTrue(prevCount > 0); try (Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) { table.put(new Put(foo).addColumn(foo, foo, foo)); } assertEquals(1, rollWalRequests.getCount() - prevCount); } }
@Test public void testRegionServerObserver() throws IOException { try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { LOG.info("Rolling WALs"); admin.rollWALWriter(UTIL.getMiniHBaseCluster().getServerHoldingMeta()); } // Find out the MetricRegistry used by the CP using the global registries MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRSCoprocessor( CustomRegionServerObserver.class.getName()); Optional<MetricRegistry> registry = MetricRegistries.global().get(info); assertTrue(registry.isPresent()); Optional<Metric> metric = registry.get().get("rollWALRequests"); assertTrue(metric.isPresent()); Counter rollWalRequests = (Counter)metric.get(); assertEquals(1, rollWalRequests.getCount()); }
@Override public void shutdown() { super.shutdown(); MetricsCoprocessor.removeRegistry(metricRegistry); } }
MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor( CustomRegionEndpoint.class.getName());