Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private MetricsUserAggregateFactory() {
}

public static final String METRIC_USER_ENABLED_CONF = "hbase.regionserver.user.metrics.enabled";
public static final boolean DEFAULT_METRIC_USER_ENABLED_CONF = true;
public static final boolean DEFAULT_METRIC_USER_ENABLED_CONF = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have many default constants for multiple configs defined in core code, seems like we are not utilizing hbase-default.xml.
@saintstack it's not related to this PR, but should we have a general guideline to keep config's default values only in hbase-default.xml and not in code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds find if the original config is in hbase-default; this one is not.

We don't have all configs in hbase-default. Too many. Operator would get lost. The boundary between listing in hbase-default or not is not specified unfortunately. A task to do.


public static MetricsUserAggregate getMetricsUserAggregate(Configuration conf) {
if (conf.getBoolean(METRIC_USER_ENABLED_CONF, DEFAULT_METRIC_USER_ENABLED_CONF)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.hadoop.hbase.filter.FilterAllFilter;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.regionserver.MetricsUserAggregateFactory;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.testclassification.MediumTests;
Expand Down Expand Up @@ -251,6 +252,11 @@ public void testMasterAndBackupMastersStatus() throws Exception {

@Test public void testUserMetrics() throws Exception {
Configuration conf = UTIL.getConfiguration();
// If metrics for users is not enabled, this test doesn't make sense.
if (!conf.getBoolean(MetricsUserAggregateFactory.METRIC_USER_ENABLED_CONF,
MetricsUserAggregateFactory.DEFAULT_METRIC_USER_ENABLED_CONF)) {
return;
}
User userFoo = User.createUserForTesting(conf, "FOO_USER_METRIC_TEST", new String[0]);
User userBar = User.createUserForTesting(conf, "BAR_USER_METRIC_TEST", new String[0]);
User userTest = User.createUserForTesting(conf, "TEST_USER_METRIC_TEST", new String[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class TestMetricsUserAggregate {

private MetricsRegionServerWrapperStub wrapper;
private MetricsRegionServer rsm;
private MetricsUserAggregateImpl userAgg;
private MetricsUserAggregate userAgg;
private TableName tableName = TableName.valueOf("testUserAggregateMetrics");

@BeforeClass
Expand All @@ -60,7 +60,7 @@ public void setUp() {
wrapper = new MetricsRegionServerWrapperStub();
Configuration conf = HBaseConfiguration.create();
rsm = new MetricsRegionServer(wrapper,conf , null);
userAgg = (MetricsUserAggregateImpl)rsm.getMetricsUserAggregate();
userAgg = (MetricsUserAggregate)rsm.getMetricsUserAggregate();
}

private void doOperations() {
Expand Down Expand Up @@ -90,6 +90,11 @@ private void doOperations() {
@Test
public void testPerUserOperations() {
Configuration conf = HBaseConfiguration.create();
// If metrics for users is not enabled, this test doesn't make sense.
if (!conf.getBoolean(MetricsUserAggregateFactory.METRIC_USER_ENABLED_CONF,
MetricsUserAggregateFactory.DEFAULT_METRIC_USER_ENABLED_CONF)) {
return;
}
User userFoo = User.createUserForTesting(conf, "FOO", new String[0]);
User userBar = User.createUserForTesting(conf, "BAR", new String[0]);

Expand Down Expand Up @@ -128,6 +133,11 @@ public Void run() {

@Test public void testLossyCountingOfUserMetrics() {
Configuration conf = HBaseConfiguration.create();
// If metrics for users is not enabled, this test doesn't make sense.
if (!conf.getBoolean(MetricsUserAggregateFactory.METRIC_USER_ENABLED_CONF,
MetricsUserAggregateFactory.DEFAULT_METRIC_USER_ENABLED_CONF)) {
return;
}
int noOfUsers = 10000;
for (int i = 1; i <= noOfUsers; i++) {
User.createUserForTesting(conf, "FOO" + i, new String[0]).getUGI()
Expand Down