Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 60358200CFC for ; Thu, 24 Aug 2017 06:02:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5EA1D16A4BF; Thu, 24 Aug 2017 04:02:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A2F9F16A4BE for ; Thu, 24 Aug 2017 06:02:43 +0200 (CEST) Received: (qmail 40861 invoked by uid 500); 24 Aug 2017 04:02:42 -0000 Mailing-List: contact commits-help@sentry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sentry.apache.org Delivered-To: mailing list commits@sentry.apache.org Received: (qmail 40852 invoked by uid 99); 24 Aug 2017 04:02:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Aug 2017 04:02:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9D698E0014; Thu, 24 Aug 2017 04:02:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akolb@apache.org To: commits@sentry.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: sentry git commit: SENTRY-1822: Allow multiple Sentry reporters (ALex Kolbasov, reviewed by Vamsee Yarlagadda) Date: Thu, 24 Aug 2017 04:02:42 +0000 (UTC) archived-at: Thu, 24 Aug 2017 04:02:44 -0000 Repository: sentry Updated Branches: refs/heads/master c659a3e68 -> 8ee4f4b85 SENTRY-1822: Allow multiple Sentry reporters (ALex Kolbasov, reviewed by Vamsee Yarlagadda) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/8ee4f4b8 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/8ee4f4b8 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/8ee4f4b8 Branch: refs/heads/master Commit: 8ee4f4b851b3bd62ba11552cfef4e4316b8cf093 Parents: c659a3e Author: Alexander Kolbasov Authored: Wed Aug 23 21:02:30 2017 -0700 Committer: Alexander Kolbasov Committed: Wed Aug 23 21:02:30 2017 -0700 ---------------------------------------------------------------------- .../db/service/thrift/SentryMetrics.java | 117 +++++++++++-------- 1 file changed, 71 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/8ee4f4b8/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 32a0664..4063a66 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 @@ -49,14 +49,16 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.lang.management.ManagementFactory; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; 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 + * A singleton class which holds metrics related utility functions as well as the list of metrics. */ public final class SentryMetrics { public enum Reporting { @@ -131,6 +133,9 @@ public final class SentryMetrics { registerMetricSet("threads", new ThreadStatesGaugeSet(), METRIC_REGISTRY); } + /** + * Get singleton instance. + */ public static synchronized SentryMetrics getInstance() { if (sentryMetrics == null) { sentryMetrics = new SentryMetrics(); @@ -139,7 +144,7 @@ public final class SentryMetrics { } void addSentryStoreGauges(SentryStore sentryStore) { - if(!gaugesAdded) { + if (!gaugesAdded) { addGauge(SentryStore.class, "role_count", sentryStore.getRoleCountGauge()); addGauge(SentryStore.class, "privilege_count", sentryStore.getPrivilegeCountGauge()); @@ -157,8 +162,12 @@ public final class SentryMetrics { } } + /** + * Add gauges for the SentryService class. + * @param sentryservice + */ public void addSentryServiceGauges(SentryService sentryservice) { - if(!sentryServiceGaugesAdded) { + if (!sentryServiceGaugesAdded) { addGauge(SentryService.class, "is_active", sentryservice.getIsActiveGauge()); addGauge(SentryService.class, "activated", sentryservice.getBecomeActiveCount()); sentryServiceGaugesAdded = true; @@ -166,8 +175,8 @@ public final class SentryMetrics { } /** - * Initialize reporters. Only initializes once. - *

+ * Initialize reporters. Only initializes once.

+ * * Available reporters: *

    *
  • console
  • @@ -175,11 +184,12 @@ public final class SentryMetrics { *
  • jmx
  • *
* - * For console reporter configre it to report every + *

SENTRY_REPORTER_INTERVAL_SEC seconds. - *

- * Method is thread safe. + * + *

Method is thread safe. */ + @SuppressWarnings("squid:S2095") void initReporting(Configuration conf) { final String reporter = conf.get(ServerConfig.SENTRY_REPORTER); if ((reporter == null) || reporter.isEmpty() || reportingInitialized.getAndSet(true)) { @@ -191,43 +201,58 @@ public final class SentryMetrics { conf.getInt(ServerConfig.SENTRY_REPORTER_INTERVAL_SEC, ServerConfig.SENTRY_REPORTER_INTERVAL_DEFAULT); - switch(SentryMetrics.Reporting.valueOf(reporter.toUpperCase())) { - case CONSOLE: - LOGGER.info("Enabled console metrics reporter with {} 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; - case LOG: - LOGGER.info("Enabled Log4J metrics reporter with {} seconds interval", - reportInterval); - final Slf4jReporter logReporter = Slf4jReporter.forRegistry(METRIC_REGISTRY) - .outputTo(LOGGER) - .convertRatesTo(TimeUnit.SECONDS) - .convertDurationsTo(TimeUnit.MILLISECONDS) - .build(); - logReporter.start(reportInterval, TimeUnit.SECONDS); - break; - case JSON: - LOGGER.info("Enabled JSON metrics reporter with {} seconds interval", reportInterval); - JsonFileReporter jsonReporter = new JsonFileReporter(conf, reportInterval, TimeUnit.SECONDS); - jsonReporter.start(); - break; - default: - LOGGER.warn("Invalid metrics reporter {}", reporter); - break; + // Get list of configured reporters + Set reporters = new HashSet<>(); + for (String r: reporter.split(",")) { + reporters.add(r.trim().toUpperCase()); + } + + // In case there are no reporters, configure JSON reporter + if (reporters.isEmpty()) { + reporters.add(Reporting.JSON.toString()); + } + + // Configure all reporters + for (String r: reporters) { + switch (SentryMetrics.Reporting.valueOf(r)) { + case CONSOLE: + LOGGER.info("Enabled console metrics reporter with {} 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; + case LOG: + LOGGER.info("Enabled Log4J metrics reporter with {} seconds interval", + reportInterval); + final Slf4jReporter logReporter = Slf4jReporter.forRegistry(METRIC_REGISTRY) + .outputTo(LOGGER) + .convertRatesTo(TimeUnit.SECONDS) + .convertDurationsTo(TimeUnit.MILLISECONDS) + .build(); + logReporter.start(reportInterval, TimeUnit.SECONDS); + break; + case JSON: + LOGGER.info("Enabled JSON metrics reporter with {} seconds interval", reportInterval); + JsonFileReporter jsonReporter = new JsonFileReporter(conf, + reportInterval, TimeUnit.SECONDS); + jsonReporter.start(); + break; + default: + LOGGER.warn("Invalid metrics reporter {}", reporter); + break; + } } } @@ -261,7 +286,7 @@ public final class SentryMetrics { TimeUnit.MILLISECONDS, false)); private final Configuration conf; - /** Destination file name */ + /** Destination file name. */ private final String pathString; private final long interval; private final TimeUnit unit;