diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2Metrics.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2Metrics.java index c55c05e..0b88936 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2Metrics.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2Metrics.java @@ -75,12 +75,12 @@ public static void setup() throws Exception { confOverlay = new HashMap(); confOverlay.put(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false"); confOverlay.put(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname, MetricCheckingHook.class.getName()); + confOverlay.put(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED.varname, "true"); + confOverlay.put(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false"); miniHS2.start(confOverlay); HiveConf conf = new HiveConf(); - conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED, true); - conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); - MetricsFactory.init(conf); + metrics = (CodahaleMetrics) MetricsFactory.getInstance(); } diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java index 2f55591..9c76683 100644 --- a/service/src/java/org/apache/hive/service/server/HiveServer2.java +++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -99,6 +99,15 @@ public HiveServer2() { @Override public synchronized void init(HiveConf hiveConf) { + //Initialize metrics first, as some metrics are for initialization stuff. + try { + if (hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_METRICS_ENABLED)) { + MetricsFactory.init(hiveConf); + } + } catch (Throwable t) { + LOG.warn("Could not initiate the HiveServer2 Metrics system. Metrics may not be reported.", t); + } + cliService = new CLIService(this); addService(cliService); final HiveServer2 hiveServer2 = this; @@ -506,9 +515,6 @@ private static void startHiveServer2() throws Throwable { server.init(hiveConf); server.start(); - if (hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_METRICS_ENABLED)) { - MetricsFactory.init(hiveConf); - } try { JvmPauseMonitor pauseMonitor = new JvmPauseMonitor(hiveConf); pauseMonitor.start();