public static void decrementMetric(String name, long count) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { metrics.decrementCounter(name, count); } }
@Before public void setup() throws Exception { HiveConf conf = new HiveConf(); conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED, true); MetricsFactory.init(conf); HiveSession session = mock(HiveSession.class); when(session.getHiveConf()).thenReturn(conf); when(session.getSessionState()).thenReturn(mock(SessionState.class)); when(session.getUserName()).thenReturn("userName"); operation = new SQLOperation(session, "select * from dummy", Maps.<String, String>newHashMap(), false, 0L); metrics = (CodahaleMetrics) MetricsFactory.getInstance(); }
@Before public void before() throws Exception { MetricsFactory.close(); HiveConf conf = new HiveConf(); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, LegacyMetrics.class.getCanonicalName()); MetricsFactory.init(conf); metrics = (LegacyMetrics) MetricsFactory.getInstance(); }
if (MetricsFactory.getInstance() != null) { try { MetricsFactory.close(); } catch (Exception e) { LOG.error("error in Metrics deinit: " + e.getClass().getName() + " "
@Before public void init() throws Exception { conf = new HiveConf(); conf.setBoolVar(HIVE_SERVER2_METRICS_ENABLED, true); conf.setVar(HiveConf.ConfVars.DOWNLOADED_RESOURCES_DIR, System.getProperty("java.io.tmpdir")); conf.setTimeVar(HIVE_SERVER2_COMPILE_LOCK_TIMEOUT, 15, TimeUnit.SECONDS); MetricsFactory.close(); MetricsFactory.init(conf); }
MetricsFactory.init(conf); } catch (InvocationTargetException expectedException) {
@AfterClass public static void cleanup() { try { MetricsFactory.close(); } catch (Exception e) { e.printStackTrace(); } jsonReportFile.delete(); }
@Test public void testNoErrorOnDisabledMetrics() throws Exception { MetricsFactory.close(); MetricsQueryLifeTimeHook emptyhook = new MetricsQueryLifeTimeHook(); assertThat(MetricsFactory.getInstance(), nullValue()); emptyhook.beforeCompile(ctx); emptyhook.afterCompile(ctx, false); emptyhook.beforeExecution(ctx); emptyhook.afterExecution(ctx, false); } }
MetricsFactory.init(hiveConf);
@After public void after() throws Exception { MetricsFactory.close(); }
private void endMetrics(String method) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { MetricsScope scope = openScopes.remove(method); if (scope != null) { metrics.endScope(scope); } } }
@Before public void before() throws Exception { HiveConf conf = new HiveConf(); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, CodahaleMetrics.class.getCanonicalName()); // disable json file writing conf.setVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_INTERVAL, "60000m"); MetricsFactory.init(conf); metricRegistry = ((CodahaleMetrics) MetricsFactory.getInstance()).getMetricRegistry(); }
if (MetricsFactory.getInstance() != null) { try { MetricsFactory.close(); } catch (Exception e) { LOG.error("error in Metrics deinit: " + e.getClass().getName() + " "
MetricsFactory.init(hiveConf);
@After public void after() throws Exception { MetricsFactory.close(); }
private void closeConnection() { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { try { metrics.decrementCounter(MetricsConstant.OPEN_CONNECTIONS); } catch (Exception e) { LOG.warn("Error reporting HS2 close connection operation to Metrics system", e); } } }
@BeforeClass public static void setUp() throws Exception { if (!tmpDir.toFile().exists()) { System.out.println("Creating directory " + tmpDir); Files.createDirectories(tmpDir, PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-xr-x"))); } HiveConf conf = new HiveConf(); jsonReportFile = File.createTempFile("TestCodahaleMetrics", ".json"); System.out.println("Json metrics saved in " + jsonReportFile.getAbsolutePath()); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, CodahaleMetrics.class.getCanonicalName()); conf.setVar(HiveConf.ConfVars.HIVE_CODAHALE_METRICS_REPORTER_CLASSES, "org.apache.hadoop.hive.common.metrics.metrics2.JsonFileMetricsReporter, " + "org.apache.hadoop.hive.common.metrics.metrics2.JmxMetricsReporter"); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_LOCATION, jsonReportFile.getAbsolutePath()); conf.setTimeVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_INTERVAL, REPORT_INTERVAL_MS, TimeUnit.MILLISECONDS); MetricsFactory.init(conf); metricRegistry = ((CodahaleMetrics) MetricsFactory.getInstance()).getMetricRegistry(); }
@After public void after() throws Exception { MetricsFactory.close(); }
private void beginMetrics(String method) { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { MetricsScope scope = metrics.createScope(MetricsConstant.API_PREFIX + method); openScopes.put(method, scope); } }
/** * Tests that the deprecated HIVE_METRICS_REPORTER config is used if the HIVE_CODAHALE_METRICS_REPORTER_CLASSES is missing. */ @Test public void testFallbackToDeprecatedConfig() throws Exception { HiveConf conf = new HiveConf(); jsonReportFile = new File(workDir, "json_reporting"); jsonReportFile.delete(); conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, "local"); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, CodahaleMetrics.class.getCanonicalName()); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_REPORTER, "JMX, JSON"); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_LOCATION, jsonReportFile.toString()); conf.setVar(HiveConf.ConfVars.HIVE_METRICS_JSON_FILE_INTERVAL, "100ms"); MetricsFactory.init(conf); int runs = 5; for (int i = 0; i < runs; i++) { MetricsFactory.getInstance().incrementCounter("count2"); } // we expect json file to be updated byte[] jsonData = MetricsTestUtils.getFileData(jsonReportFile.getAbsolutePath(), 2000, 3); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(jsonData); JsonNode countersNode = rootNode.path("counters"); JsonNode methodCounterNode = countersNode.path("count2"); JsonNode countNode = methodCounterNode.path("count"); Assert.assertEquals(countNode.asInt(), 5); }