Repository: sentry Updated Branches: refs/heads/sentry-ha-redesign 38098b461 -> 81990992b
SENTRY-1319: Add metrics for isActive and isHA ( Rahul Sharma, reviewed by Colin Patrick McCabe, Sravya Tirukkovalur, Hao Hao and Anne Yu) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/81990992 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/81990992 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/81990992 Branch: refs/heads/sentry-ha-redesign Commit: 81990992b42690ed064564fc67aa7c6c840a9b46 Parents: 38098b4 Author: Anne Yu <[email protected]> Authored: Wed Jun 15 14:07:14 2016 -0700 Committer: Anne Yu <[email protected]> Committed: Wed Jun 15 14:07:14 2016 -0700 ---------------------------------------------------------------------- .../db/service/thrift/SentryMetrics.java | 9 +++ .../sentry/service/thrift/SentryService.java | 33 +++++++++++ .../thrift/TestSentryServiceMetrics.java | 58 ++++++++++++++++++++ .../tests/e2e/hdfs/TestHDFSIntegration.java | 1 + 4 files changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/81990992/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 c6d4d02..19d6ebb 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 @@ -31,6 +31,7 @@ import com.codahale.metrics.jvm.GarbageCollectorMetricSet; import com.codahale.metrics.jvm.MemoryUsageGaugeSet; import com.codahale.metrics.jvm.ThreadStatesGaugeSet; import org.apache.sentry.provider.db.service.persistent.SentryStore; +import org.apache.sentry.service.thrift.SentryService; import java.lang.management.ManagementFactory; import java.util.Map; @@ -43,6 +44,7 @@ public final class SentryMetrics { private static SentryMetrics sentryMetrics = null; private boolean reportingInitialized = false; private boolean gaugesAdded = false; + private boolean sentryServiceGaugesAdded = false; public final Timer createRoleTimer = SentryMetricsServletContextListener.METRIC_REGISTRY.timer( MetricRegistry.name(SentryPolicyStoreProcessor.class, "create-role")); @@ -116,6 +118,13 @@ public final class SentryMetrics { } } + public void addSentryServiceGauges(SentryService sentryservice) { + if(!sentryServiceGaugesAdded) { + addGauge(SentryService.class, "is_active", sentryservice.getIsActiveGauge()); + addGauge(SentryService.class, "is_ha", sentryservice.getIsHAGauge()); + sentryServiceGaugesAdded = true; + } + } /* Should be only called once to initialize the reporters */ http://git-wip-us.apache.org/repos/asf/sentry/blob/81990992/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java index 5783649..6883bf4 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java @@ -37,6 +37,7 @@ import java.util.concurrent.ThreadFactory; import javax.security.auth.Subject; +import com.codahale.metrics.Gauge; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.GnuParser; @@ -49,6 +50,7 @@ import org.apache.hadoop.security.SaslRpcServer.AuthMethod; import org.apache.hadoop.security.SecurityUtil; import org.apache.sentry.Command; import org.apache.sentry.provider.db.service.thrift.SentryHealthCheckServletContextListener; +import org.apache.sentry.provider.db.service.thrift.SentryMetrics; import org.apache.sentry.provider.db.service.thrift.SentryMetricsServletContextListener; import org.apache.sentry.provider.db.service.thrift.SentryWebServer; import org.apache.sentry.service.thrift.ServiceConstants.ConfUtilties; @@ -92,6 +94,9 @@ public class SentryService implements Callable { private int webServerPort; private SentryWebServer sentryWebServer; private long maxMessageSize; + private final boolean isHA; + private boolean isActive; + SentryMetrics sentryMetrics; public SentryService(Configuration conf) { this.conf = conf; @@ -136,6 +141,10 @@ public class SentryService implements Callable { principalParts = null; keytab = null; } + isHA = conf.getBoolean(ServerConfig.SENTRY_HA_ENABLED, + ServerConfig.SENTRY_HA_ENABLED_DEFAULT); + //setting isActive to true for now, until we have Sentry HA implemented + isActive = true; serviceExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { private int count = 0; @@ -212,6 +221,7 @@ public class SentryService implements Callable { throw new IllegalStateException( "Failed to register any processors from " + processorFactories); } + addSentryServiceGauge(); TServerTransport serverTransport = new TServerSocket(address); TTransportFactory transportFactory = null; if (kerberos) { @@ -234,6 +244,11 @@ public class SentryService implements Callable { thriftServer.serve(); } + private void addSentryServiceGauge() { + sentryMetrics = SentryMetrics.getInstance(); + sentryMetrics.addSentryServiceGauges(this); + } + private void startSentryWebServer() throws Exception{ Boolean sentryReportingEnable = conf.getBoolean(ServerConfig.SENTRY_WEB_ENABLE, ServerConfig.SENTRY_WEB_ENABLE_DEFAULT); @@ -423,4 +438,22 @@ public class SentryService implements Callable { } return thriftServer.getEventHandler(); } + + public Gauge<Boolean> getIsActiveGauge() { + return new Gauge<Boolean>() { + @Override + public Boolean getValue() { + return isActive; + } + }; + } + + public Gauge<Boolean> getIsHAGauge() { + return new Gauge<Boolean>() { + @Override + public Boolean getValue() { + return isHA; + } + }; + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/81990992/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java new file mode 100644 index 0000000..441a108 --- /dev/null +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java @@ -0,0 +1,58 @@ +/** + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless createRequired by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sentry.provider.db.service.thrift; + +import org.apache.sentry.service.thrift.SentryServiceIntegrationBase; +import org.junit.*; + +public class TestSentryServiceMetrics extends SentryServiceIntegrationBase { + + @BeforeClass + public static void setup() throws Exception { + kerberos = false; + beforeSetup(); + setupConf(); + startSentryService(); + afterSetup(); + } + + //Overriding this method as the tests do not require a client handle + @Override + @Before + public void before() throws Exception { + + } + /* SENTRY-1319 */ + @Test + public void testSentryServiceGauges() throws Throwable { + //More Cases to be added once Sentry HA is implemented + + //Check for gauges with the server handle. + Assert.assertEquals(new Boolean(false),server.getIsHAGauge().getValue()); + Assert.assertEquals(new Boolean(true),server.getIsActiveGauge().getValue()); + } + + //Overriding this method as the client handle does not exist. + @Override + @After + public void after() { + + } + +} http://git-wip-us.apache.org/repos/asf/sentry/blob/81990992/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegration.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegration.java index 1606b6d..f2d74bf 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegration.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegration.java @@ -1723,6 +1723,7 @@ public class TestHDFSIntegration { conn.close(); } + private void loadData(Statement stmt) throws IOException, SQLException { FSDataOutputStream f1 = miniDFS.getFileSystem().create(new Path("/tmp/f1.txt")); f1.writeChars("m1d1_t1\n");
