HIVE-19477: Hiveserver2 in http mode not emitting metric default.General.open_connections (Jesus Camacho Rodriguez, reviewed by Vaibhav Gumashta)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/b3313380 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/b3313380 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/b3313380 Branch: refs/heads/branch-3.0.0 Commit: b3313380c994b90334d06b7ce364bcf24fb0e8d3 Parents: 1a31e49 Author: Jesus Camacho Rodriguez <jcama...@apache.org> Authored: Fri May 11 09:00:51 2018 -0700 Committer: Jesus Camacho Rodriguez <jcama...@apache.org> Committed: Fri May 11 09:21:30 2018 -0700 ---------------------------------------------------------------------- .../cli/thrift/ThriftHttpCLIService.java | 34 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/b3313380/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java ---------------------------------------------------------------------- diff --git a/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java b/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java index a02f13c..0b3f2c3 100644 --- a/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java +++ b/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java @@ -23,14 +23,17 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; import javax.ws.rs.HttpMethod; +import org.apache.hadoop.hive.common.metrics.common.Metrics; +import org.apache.hadoop.hive.common.metrics.common.MetricsConstant; +import org.apache.hadoop.hive.common.metrics.common.MetricsFactory; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hadoop.hive.shims.ShimLoader; -import org.apache.hadoop.hive.shims.Utils; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hadoop.util.Shell; import org.apache.hive.service.auth.HiveAuthFactory; import org.apache.hive.service.cli.CLIService; import org.apache.hive.service.rpc.thrift.TCLIService; @@ -153,6 +156,33 @@ public class ThriftHttpCLIService extends ThriftCLIService { LOG.warn("XSRF filter disabled"); } + context.addEventListener(new ServletContextListener() { + @Override + public void contextInitialized(ServletContextEvent servletContextEvent) { + Metrics metrics = MetricsFactory.getInstance(); + if (metrics != null) { + try { + metrics.incrementCounter(MetricsConstant.OPEN_CONNECTIONS); + metrics.incrementCounter(MetricsConstant.CUMULATIVE_CONNECTION_COUNT); + } catch (Exception e) { + LOG.warn("Error reporting HS2 open connection operation to Metrics system", e); + } + } + } + + @Override + public void contextDestroyed(ServletContextEvent servletContextEvent) { + 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); + } + } + } + }); + final String httpPath = getHttpPath(hiveConf .getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_HTTP_PATH));