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-1581: Provide Log4J metrics reporter (Alexander Kolbasov, Reviewed by: Hao Hao, Vamsee Yarlagadda)
Date Tue, 10 Jan 2017 22:43:23 GMT
Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign 56b0f19a5 -> 1458d1a3b


SENTRY-1581: Provide Log4J metrics reporter (Alexander Kolbasov, Reviewed by: Hao Hao, Vamsee
Yarlagadda)

Change-Id: I6aab2a7c3e7ec565046c678069049daeacbb7fa3


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

Branch: refs/heads/sentry-ha-redesign
Commit: 1458d1a3b2e6733be20f54917c4d4dbc4d90bcc1
Parents: 56b0f19
Author: hahao <hao.hao@cloudera.com>
Authored: Tue Jan 10 14:43:07 2017 -0800
Committer: hahao <hao.hao@cloudera.com>
Committed: Tue Jan 10 14:43:07 2017 -0800

----------------------------------------------------------------------
 .../db/service/thrift/SentryMetrics.java        | 42 +++++++++++---------
 .../thrift/SentryPolicyStoreProcessor.java      | 14 +------
 2 files changed, 25 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/1458d1a3/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
index 39539b9..3f7542c 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryMetrics.java
@@ -17,16 +17,10 @@
  */
 package org.apache.sentry.provider.db.service.thrift;
 
-import com.codahale.metrics.ConsoleReporter;
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.JmxReporter;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.*;
+
 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;
@@ -145,6 +139,7 @@ public final class SentryMetrics {
    * Available reporters:
    * <ul>
    *     <li>console</li>
+   *     <li>log</li>
    *     <li>jmx</li>
    * </ul>
    *
@@ -153,18 +148,19 @@ public final class SentryMetrics {
    * <p>
    * Method is thread safe.
    */
-  void initReporting(Reporting reporting, Configuration conf) {
-    if (reportingInitialized.getAndSet(true)) {
+  void initReporting(Configuration conf) {
+    final String reporter = conf.get(ServerConfig.SENTRY_REPORTER);
+    if (reporter == null || reporter.isEmpty() || 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);
+    final int reportInterval =
+            conf.getInt(ServerConfig.SENTRY_REPORTER_INTERVAL_SEC,
+                    ServerConfig.SENTRY_REPORTER_INTERVAL_DEFAULT);
 
+    switch(SentryMetrics.Reporting.valueOf(reporter.toUpperCase())) {
+      case CONSOLE:
         LOGGER.info(String.format("Enabled console metrics reporter with %d seconds interval",
                 reportInterval));
         final ConsoleReporter consoleReporter =
@@ -182,8 +178,17 @@ public final class SentryMetrics {
             .build();
         jmxReporter.start();
         break;
+      case LOG:
+        LOGGER.info(String.format("Enabled Log4J metrics reporter with %d seconds interval",
+                reportInterval));
+        final Slf4jReporter logReporter = Slf4jReporter.forRegistry(METRIC_REGISTRY)
+                .outputTo(LOGGER)
+                .convertRatesTo(TimeUnit.SECONDS)
+                .convertDurationsTo(TimeUnit.MILLISECONDS)
+                .build();
+        logReporter.start(reportInterval, TimeUnit.SECONDS);
       default:
-        LOGGER.warn("Invalid metrics reporter " + reporting.toString());
+        LOGGER.warn("Invalid metrics reporter " + reporter);
         break;
     }
   }
@@ -205,6 +210,7 @@ public final class SentryMetrics {
 
   public enum Reporting {
     JMX,
-    CONSOLE
+    CONSOLE,
+    LOG,
   }
 }

http://git-wip-us.apache.org/repos/asf/sentry/blob/1458d1a3/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
index caa3c58..5121740 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
@@ -118,19 +118,7 @@ public class SentryPolicyStoreProcessor implements SentryPolicyService.Iface
{
   private void initMetrics() {
     sentryMetrics = SentryMetrics.getInstance();
     sentryMetrics.addSentryStoreGauges(sentryStore);
-
-    String sentryReporting = conf.get(ServerConfig.SENTRY_REPORTER);
-    if (sentryReporting != null) {
-      SentryMetrics.Reporting reporting;
-      try {
-        reporting = SentryMetrics.Reporting.valueOf(sentryReporting.toUpperCase());
-        sentryMetrics.initReporting(reporting, conf);
-
-      } catch (IllegalArgumentException e) {
-        LOGGER.warn("Metrics reporting not configured correctly, please set " + ServerConfig.SENTRY_REPORTER
+
-            " to: " + ServerConfig.SENTRY_REPORTER_CONSOLE + "/" + ServerConfig.SENTRY_REPORTER_JMX);
-      }
-    }
+    sentryMetrics.initReporting(conf);
   }
 
   public void stop() {


Mime
View raw message