sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject sentry git commit: SENTRY-1533: Sentry console metrics reporting interval should be configurable (Alexander Kolbasov, Reviewed by: Hao Hao and Vadim Spector)
Date Mon, 28 Nov 2016 18:35:07 GMT
Repository: sentry
Updated Branches:
  refs/heads/master 73a5eabea -> d9763f6b9


SENTRY-1533: Sentry console metrics reporting interval should be configurable (Alexander Kolbasov,
Reviewed by: Hao Hao and Vadim Spector)

Change-Id: Ide3871402e5900c0df0b72542dfcbd5d561230ba


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/d9763f6b
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/d9763f6b
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/d9763f6b

Branch: refs/heads/master
Commit: d9763f6b98b4440f72883991467c0ad96b20952d
Parents: 73a5eab
Author: hahao <hao.hao@cloudera.com>
Authored: Mon Nov 28 10:33:56 2016 -0800
Committer: hahao <hao.hao@cloudera.com>
Committed: Mon Nov 28 10:33:56 2016 -0800

----------------------------------------------------------------------
 .../sentry/service/thrift/ServiceConstants.java |   6 +
 .../db/service/thrift/SentryMetrics.java        | 159 ++++++++++++-------
 .../thrift/SentryPolicyStoreProcessor.java      |   2 +-
 3 files changed, 106 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/d9763f6b/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
----------------------------------------------------------------------
diff --git a/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
b/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
index ec47909..919fdaf 100644
--- a/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
+++ b/sentry-service/sentry-service-common/src/main/java/org/apache/sentry/service/thrift/ServiceConstants.java
@@ -165,7 +165,13 @@ public class ServiceConstants {
     public static final Boolean SENTRY_WEB_ENABLE_DEFAULT = false;
     public static final String SENTRY_WEB_PORT = "sentry.service.web.port";
     public static final int SENTRY_WEB_PORT_DEFAULT = 29000;
+    // Reporter is either "console" or "jmx"
     public static final String SENTRY_REPORTER = "sentry.service.reporter";
+    // for console reporter, reporting interval in seconds
+    public static final String SENTRY_REPORTER_INTERVAL_SEC =
+            "sentry.service.reporter.interval.sec";
+    // Report every 5 minutes by default
+    public static final int SENTRY_REPORTER_INTERVAL_DEFAULT = 300;
 
     // Web SSL
     public static final String SENTRY_WEB_USE_SSL = "sentry.web.use.ssl";

http://git-wip-us.apache.org/repos/asf/sentry/blob/d9763f6b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
----------------------------------------------------------------------
diff --git a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
index c6d4d02..c477f24 100644
--- a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
+++ b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -24,80 +24,92 @@ import com.codahale.metrics.Histogram;
 import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.Metric;
 import com.codahale.metrics.MetricRegistry;
+import static com.codahale.metrics.MetricRegistry.name;
 import com.codahale.metrics.MetricSet;
 import com.codahale.metrics.Timer;
 import com.codahale.metrics.jvm.BufferPoolMetricSet;
 import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
 import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
 import com.codahale.metrics.jvm.ThreadStatesGaugeSet;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.sentry.provider.db.service.persistent.SentryStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.sentry.provider.db.service.thrift.SentryMetricsServletContextListener.METRIC_REGISTRY;
+import static org.apache.sentry.service.thrift.ServiceConstants.ServerConfig;
 
 import java.lang.management.ManagementFactory;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * A singleton class which holds metrics related utility functions as well as the list of
metrics
  */
 public final class SentryMetrics {
+  private static final Logger LOGGER = LoggerFactory
+          .getLogger(SentryMetrics.class);
+
   private static SentryMetrics sentryMetrics = null;
-  private boolean reportingInitialized = false;
+  private final AtomicBoolean reportingInitialized = new AtomicBoolean();
   private boolean gaugesAdded = false;
 
-  public final Timer createRoleTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "create-role"));
-  public final Timer dropRoleTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "drop-role"));
-  public final Timer grantRoleTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "grant-role"));
-  public final Timer revokeRoleTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "revoke-role"));
-  public final Timer grantTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "grant-privilege"));
-  public final Timer revokeTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "revoke-privilege"));
-
-  public final Timer dropPrivilegeTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "drop-privilege"));
-  public final Timer renamePrivilegeTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "rename-privilege"));
-
-  public final Timer listRolesByGroupTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "list-roles-by-group"));
-  public final Timer listPrivilegesByRoleTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "list-privileges-by-role"));
-  public final Timer listPrivilegesForProviderTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "list-privileges-for-provider"));
-  public final Timer listPrivilegesByAuthorizableTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer(
-      MetricRegistry.name(SentryPolicyStoreProcessor.class, "list-privileges-by-authorizable"));
+  final Timer createRoleTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "create-role"));
+  final Timer dropRoleTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "drop-role"));
+  final Timer grantRoleTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "grant-role"));
+  final Timer revokeRoleTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "revoke-role"));
+  final Timer grantTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "grant-privilege"));
+  final Timer revokeTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "revoke-privilege"));
+
+  final Timer dropPrivilegeTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "drop-privilege"));
+  final Timer renamePrivilegeTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "rename-privilege"));
+
+  final Timer listRolesByGroupTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "list-roles-by-group"));
+  final Timer listPrivilegesByRoleTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "list-privileges-by-role"));
+  final Timer listPrivilegesForProviderTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "list-privileges-for-provider"));
+  final Timer listPrivilegesByAuthorizableTimer = METRIC_REGISTRY.timer(
+      name(SentryPolicyStoreProcessor.class, "list-privileges-by-authorizable"));
 
   /**
    * Return a Timer with name.
    */
   public Timer getTimer(String name) {
-    return SentryMetricsServletContextListener.METRIC_REGISTRY.timer(name);
+    return METRIC_REGISTRY.timer(name);
   }
 
   /**
    * Return a Histogram with name.
    */
   public Histogram getHistogram(String name) {
-    return SentryMetricsServletContextListener.METRIC_REGISTRY.histogram(name);
+    return METRIC_REGISTRY.histogram(name);
   }
 
   /**
    * Return a Counter with name.
    */
   public Counter getCounter(String name) {
-    return SentryMetricsServletContextListener.METRIC_REGISTRY.counter(name);
+    return METRIC_REGISTRY.counter(name);
   }
 
   private SentryMetrics() {
-    registerMetricSet("gc", new GarbageCollectorMetricSet(), SentryMetricsServletContextListener.METRIC_REGISTRY);
-    registerMetricSet("buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()),
-        SentryMetricsServletContextListener.METRIC_REGISTRY);
-    registerMetricSet("memory", new MemoryUsageGaugeSet(), SentryMetricsServletContextListener.METRIC_REGISTRY);
-    registerMetricSet("threads", new ThreadStatesGaugeSet(), SentryMetricsServletContextListener.METRIC_REGISTRY);
+    registerMetricSet("gc", new GarbageCollectorMetricSet(), METRIC_REGISTRY);
+    registerMetricSet("buffers",
+            new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()),
+        METRIC_REGISTRY);
+    registerMetricSet("memory", new MemoryUsageGaugeSet(), METRIC_REGISTRY);
+    registerMetricSet("threads", new ThreadStatesGaugeSet(), METRIC_REGISTRY);
   }
 
   public static synchronized SentryMetrics getInstance() {
@@ -107,42 +119,69 @@ public final class SentryMetrics {
     return sentryMetrics;
   }
 
-  public void addSentryStoreGauges(SentryStore sentryStore) {
+  void addSentryStoreGauges(SentryStore sentryStore) {
     if(!gaugesAdded) {
       addGauge(SentryStore.class, "role_count", sentryStore.getRoleCountGauge());
-      addGauge(SentryStore.class, "privilege_count", sentryStore.getPrivilegeCountGauge());
+      addGauge(SentryStore.class, "privilege_count",
+              sentryStore.getPrivilegeCountGauge());
       addGauge(SentryStore.class, "group_count", sentryStore.getGroupCountGauge());
       gaugesAdded = true;
     }
   }
 
 
-  /* Should be only called once to initialize the reporters
+  /**
+   * Initialize reporters. Only initializes once.
+   * <p>
+   * Available reporters:
+   * <ul>
+   *     <li>console</li>
+   *     <li>jmx</li>
+   * </ul>
+   *
+   * For console reporter configre it to report every
+   * <em>SENTRY_REPORTER_INTERVAL_SEC</em> seconds.
+   * <p>
+   * Method is thread safe.
    */
-  public synchronized void initReporting(Reporting reporting) {
-    if(!reportingInitialized) {
-      switch(reporting) {
-        case CONSOLE:
-          final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(SentryMetricsServletContextListener.METRIC_REGISTRY)
-              .convertRatesTo(TimeUnit.SECONDS)
-              .convertDurationsTo(TimeUnit.MILLISECONDS)
-              .build();
-          consoleReporter.start(1, TimeUnit.SECONDS);
-          break;
-        case JMX:
-          final JmxReporter jmxReporter = JmxReporter.forRegistry(SentryMetricsServletContextListener.METRIC_REGISTRY)
-              .convertRatesTo(TimeUnit.SECONDS)
-              .convertDurationsTo(TimeUnit.MILLISECONDS)
-              .build();
-          jmxReporter.start();
-          break;
-      }
+  void initReporting(Reporting reporting, Configuration conf) {
+    if (reportingInitialized.getAndSet(true)) {
+      // Nothing to do, just return
+      return;
+    }
+
+    switch(reporting) {
+      case CONSOLE:
+        final int reportInterval =
+                conf.getInt(ServerConfig.SENTRY_REPORTER_INTERVAL_SEC,
+                        ServerConfig.SENTRY_REPORTER_INTERVAL_DEFAULT);
+
+        LOGGER.info(String.format("Enabled console metrics reporter with %d seconds interval",
+                reportInterval));
+        final ConsoleReporter consoleReporter =
+                ConsoleReporter.forRegistry(METRIC_REGISTRY)
+            .convertRatesTo(TimeUnit.SECONDS)
+            .convertDurationsTo(TimeUnit.MILLISECONDS)
+            .build();
+        consoleReporter.start(reportInterval, TimeUnit.SECONDS);
+        break;
+      case JMX:
+        LOGGER.info("Enabled JMX metrics reporter");
+        final JmxReporter jmxReporter = JmxReporter.forRegistry(METRIC_REGISTRY)
+            .convertRatesTo(TimeUnit.SECONDS)
+            .convertDurationsTo(TimeUnit.MILLISECONDS)
+            .build();
+        jmxReporter.start();
+        break;
+      default:
+        LOGGER.warn("Invalid metrics reporter " + reporting.toString());
+        break;
     }
   }
 
   private <T, V> void addGauge(Class<T> tClass, String gaugeName, Gauge<V>
gauge) {
-    SentryMetricsServletContextListener.METRIC_REGISTRY.register(
-        MetricRegistry.name(tClass, gaugeName), gauge);
+    METRIC_REGISTRY.register(
+        name(tClass, gaugeName), gauge);
   }
 
   private void registerMetricSet(String prefix, MetricSet metricSet, MetricRegistry registry)
{
@@ -157,6 +196,6 @@ public final class SentryMetrics {
 
   public enum Reporting {
     JMX,
-    CONSOLE;
+    CONSOLE
   }
 }

http://git-wip-us.apache.org/repos/asf/sentry/blob/d9763f6b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
----------------------------------------------------------------------
diff --git a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
index ff06582..898632d 100644
--- a/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
+++ b/sentry-service/sentry-service-server/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
@@ -136,7 +136,7 @@ public class SentryPolicyStoreProcessor implements SentryPolicyService.Iface
{
       SentryMetrics.Reporting reporting;
       try {
         reporting = SentryMetrics.Reporting.valueOf(sentryReporting.toUpperCase());
-        sentryMetrics.initReporting(reporting);
+        sentryMetrics.initReporting(reporting, conf);
 
       } catch (IllegalArgumentException e) {
         LOGGER.warn("Metrics reporting not configured correctly, please set " + ServerConfig.SENTRY_REPORTER
+


Mime
View raw message