private static void verifyMetrics(ThriftMetrics metrics, String name, int expectValue) throws Exception { metricsHelper.assertCounter(name, expectValue, metrics.getSource()); }
/** * TODO: These counts are supposed to be zero but sometimes they are not, they are equal to the * passed in maybe. Investigate why. My guess is they are set by the test that runs just * previous to this one. Sometimes they are cleared. Sometimes not. */ private int getCurrentCount(final String name, final int maybe, final ThriftMetrics metrics) { int currentCount = 0; try { metricsHelper.assertCounter(name, maybe, metrics.getSource()); LOG.info("Shouldn't this be null? name=" + name + ", equals=" + maybe); currentCount = maybe; } catch (AssertionError e) { // Ignore } return currentCount; }
private static ThriftMetrics getMetrics(Configuration conf) throws Exception { ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO); m.getSource().init(); //Clear all the metrics return m; }
private void testExceptionType(THBaseService.Iface handler, ThriftMetrics metrics, ByteBuffer tTableName, byte[] rowkey, ErrorThrowingGetObserver.ErrorType errorType) { long preGetCounter = metricsHelper.getCounter("get_num_ops", metrics.getSource()); String exceptionKey = errorType.getMetricName(); long preExceptionCounter = metricsHelper.checkCounterExists(exceptionKey, metrics.getSource()) ? metricsHelper.getCounter(exceptionKey, metrics.getSource()) : 0; TGet tGet = new TGet(wrap(rowkey)); Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>(); attributes.put(wrap(Bytes.toBytes(ErrorThrowingGetObserver.SHOULD_ERROR_ATTRIBUTE)), wrap(Bytes.toBytes(errorType.name()))); tGet.setAttributes(attributes); try { TResult tResult = handler.get(tTableName, tGet); fail("Get with error attribute should have thrown an exception"); } catch (TException e) { LOG.info("Received exception: ", e); metricsHelper.assertCounter("get_num_ops", preGetCounter + 1, metrics.getSource()); metricsHelper.assertCounter(exceptionKey, preExceptionCounter + 1, metrics.getSource()); } }
private void testExceptionType(Hbase.Iface handler, ThriftMetrics metrics, ByteBuffer tTableName, String rowkey, ErrorThrowingGetObserver.ErrorType errorType) throws Exception { long preGetCounter = metricsHelper.getCounter("getRow_num_ops", metrics.getSource()); String exceptionKey = errorType.getMetricName(); long preExceptionCounter = metricsHelper.checkCounterExists(exceptionKey, metrics.getSource()) ? metricsHelper.getCounter(exceptionKey, metrics.getSource()) : 0; Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>(); attributes.put(asByteBuffer(ErrorThrowingGetObserver.SHOULD_ERROR_ATTRIBUTE), asByteBuffer(errorType.name())); try { List<TRowResult> tRowResult = handler.getRow(tTableName, asByteBuffer(rowkey), attributes); fail("Get with error attribute should have thrown an exception"); } catch (IOError e) { LOG.info("Received exception: ", e); metricsHelper.assertCounter("getRow_num_ops", preGetCounter + 1, metrics.getSource()); metricsHelper.assertCounter(exceptionKey, preExceptionCounter + 1, metrics.getSource()); } }
private static ThriftMetrics createMetrics() throws Exception { Configuration conf = UTIL.getConfiguration(); ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.ONE); m.getSource().init(); return m; }
this.pauseMonitor = new JvmPauseMonitor(conf, this.metrics.getSource()); this.hbaseServiceHandler = createHandler(conf, userProvider); this.hbaseServiceHandler.initMetrics(metrics);
/** * Tests if the metrics for thrift handler work correctly */ public void doTestThriftMetrics() throws Exception { LOG.info("START doTestThriftMetrics"); Configuration conf = UTIL.getConfiguration(); ThriftMetrics metrics = getMetrics(conf); Hbase.Iface handler = getHandlerForMetricsTest(metrics, conf); int currentCountCreateTable = getCurrentCount("createTable_num_ops", 2, metrics); int currentCountDeleteTable = getCurrentCount("deleteTable_num_ops", 2, metrics); int currentCountDisableTable = getCurrentCount("disableTable_num_ops", 2, metrics); createTestTables(handler); dropTestTables(handler); metricsHelper.assertCounter("createTable_num_ops", currentCountCreateTable + 2, metrics.getSource()); metricsHelper.assertCounter("deleteTable_num_ops", currentCountDeleteTable + 2, metrics.getSource()); metricsHelper.assertCounter("disableTable_num_ops", currentCountDisableTable + 2, metrics.getSource()); handler.getTableNames(); // This will have an artificial delay. // 3 to 6 seconds (to account for potential slowness), measured in nanoseconds try { metricsHelper.assertGaugeGt("getTableNames_avg_time", 3L * 1000 * 1000 * 1000, metrics.getSource()); metricsHelper.assertGaugeLt("getTableNames_avg_time",6L * 1000 * 1000 * 1000, metrics.getSource()); } catch (AssertionError e) { LOG.info("Fix me! Why does this happen? A concurrent cluster running?", e); } }
@Test public void testMetrics() throws Exception { Configuration conf = UTIL.getConfiguration(); ThriftMetrics metrics = getMetrics(conf); ThriftHBaseServiceHandler hbaseHandler = createHandler(); THBaseService.Iface handler = HbaseHandlerMetricsProxy.newInstance(hbaseHandler, metrics, conf); byte[] rowName = Bytes.toBytes("testMetrics"); ByteBuffer table = wrap(tableAname); TGet get = new TGet(wrap(rowName)); assertFalse(handler.exists(table, get)); List<TColumnValue> columnValues = new ArrayList<>(2); columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname))); columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname))); TPut put = new TPut(wrap(rowName), columnValues); put.setColumnValues(columnValues); handler.put(table, put); assertTrue(handler.exists(table, get)); metricsHelper.assertCounter("put_num_ops", 1, metrics.getSource()); metricsHelper.assertCounter("exists_num_ops", 2, metrics.getSource()); }
long preGetCounter = metricsHelper.checkCounterExists("get_num_ops", metrics.getSource()) ? metricsHelper.getCounter("get_num_ops", metrics.getSource()) : 0; TGet tGet = new TGet(wrap(rowkey)); assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues); metricsHelper.assertCounter("get_num_ops", preGetCounter + 1, metrics.getSource());
long preGetCounter = metricsHelper.checkCounterExists("getRow_num_ops", metrics.getSource()) ? metricsHelper.getCounter("getRow_num_ops", metrics.getSource()) : 0; List<TRowResult> tRowResult = handler.getRow(tTableName, asByteBuffer(rowkey), null); assertEquals(expectedColumnValue, returnedColumnValues.iterator().next()); metricsHelper.assertCounter("getRow_num_ops", preGetCounter + 1, metrics.getSource());
assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues); metricsHelper.assertGaugeGt("get_max", 3000L, metrics.getSource()); } finally { if (table != null) {
private static void verifyMetrics(ThriftMetrics metrics, String name, int expectValue) throws Exception { metricsHelper.assertCounter(name, expectValue, metrics.getSource()); }
private static void verifyMetrics(ThriftMetrics metrics, String name, int expectValue) throws Exception { metricsHelper.assertCounter(name, expectValue, metrics.getSource()); }
private static ThriftMetrics getMetrics(Configuration conf) throws Exception { ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO); m.getSource().init(); //Clear all the metrics return m; }
private static ThriftMetrics getMetrics(Configuration conf) throws Exception { ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.TWO); m.getSource().init(); //Clear all the metrics return m; }
private void testExceptionType(THBaseService.Iface handler, ThriftMetrics metrics, ByteBuffer tTableName, byte[] rowkey, ErrorThrowingGetObserver.ErrorType errorType) { long preGetCounter = metricsHelper.getCounter("get_num_ops", metrics.getSource()); String exceptionKey = errorType.getMetricName(); long preExceptionCounter = metricsHelper.checkCounterExists(exceptionKey, metrics.getSource()) ? metricsHelper.getCounter(exceptionKey, metrics.getSource()) : 0; TGet tGet = new TGet(wrap(rowkey)); Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>(); attributes.put(wrap(Bytes.toBytes(ErrorThrowingGetObserver.SHOULD_ERROR_ATTRIBUTE)), wrap(Bytes.toBytes(errorType.name()))); tGet.setAttributes(attributes); try { TResult tResult = handler.get(tTableName, tGet); fail("Get with error attribute should have thrown an exception"); } catch (TException e) { LOG.info("Received exception: ", e); metricsHelper.assertCounter("get_num_ops", preGetCounter + 1, metrics.getSource()); metricsHelper.assertCounter(exceptionKey, preExceptionCounter + 1, metrics.getSource()); } }
private void testExceptionType(Hbase.Iface handler, ThriftMetrics metrics, ByteBuffer tTableName, String rowkey, ErrorThrowingGetObserver.ErrorType errorType) throws Exception { long preGetCounter = metricsHelper.getCounter("getRow_num_ops", metrics.getSource()); String exceptionKey = errorType.getMetricName(); long preExceptionCounter = metricsHelper.checkCounterExists(exceptionKey, metrics.getSource()) ? metricsHelper.getCounter(exceptionKey, metrics.getSource()) : 0; Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>(); attributes.put(asByteBuffer(ErrorThrowingGetObserver.SHOULD_ERROR_ATTRIBUTE), asByteBuffer(errorType.name())); try { List<TRowResult> tRowResult = handler.getRow(tTableName, asByteBuffer(rowkey), attributes); fail("Get with error attribute should have thrown an exception"); } catch (IOError e) { LOG.info("Received exception: ", e); metricsHelper.assertCounter("getRow_num_ops", preGetCounter + 1, metrics.getSource()); metricsHelper.assertCounter(exceptionKey, preExceptionCounter + 1, metrics.getSource()); } }
private static ThriftMetrics createMetrics() throws Exception { Configuration conf = UTIL.getConfiguration(); ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.ONE); m.getSource().init(); return m; }
private static ThriftMetrics createMetrics() throws Exception { Configuration conf = UTIL.getConfiguration(); ThriftMetrics m = new ThriftMetrics(conf, ThriftMetrics.ThriftServerType.ONE); m.getSource().init(); return m; }