You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/11/17 17:55:02 UTC

[GitHub] [hbase] karthikhw commented on a change in pull request #834: HBASE-23237 Negative sign in requestsPerSecond

karthikhw commented on a change in pull request #834: HBASE-23237 Negative sign in requestsPerSecond
URL: https://github.com/apache/hbase/pull/834#discussion_r347149839
 
 

 ##########
 File path: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRequestsPerSecondMetric.java
 ##########
 @@ -0,0 +1,86 @@
+/**
+ * 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 required 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.hadoop.hbase.regionserver;
+
+
+import java.io.IOException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.RegionServerTests;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Validate no negative value in requestsPerSecond metric.
+ */
+@Category({ RegionServerTests.class, MediumTests.class })
+public class TestRequestsPerSecondMetric {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+      HBaseClassTestRule.forClass(TestRequestsPerSecondMetric.class);
+
+  private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
+  private static final long METRICS_PERIOD = 2000L;
+  private static Configuration conf;
+
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    conf = UTIL.getConfiguration();
+    conf.setLong(HConstants.REGIONSERVER_METRICS_PERIOD, METRICS_PERIOD);
+    UTIL.startMiniCluster(1);
+  }
+
+  @AfterClass
+  public static void teardown() throws Exception {
+    UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testNoNegativeSignAtRequestsPerSecond() throws IOException, InterruptedException {
+    final TableName TABLENAME = TableName.valueOf("t");
+    final String FAMILY = "f";
+    Admin admin = UTIL.getAdmin();
+    UTIL.createMultiRegionTable(TABLENAME, FAMILY.getBytes(),25);
+    Table table = admin.getConnection().getTable(TABLENAME);
+    ServerName serverName = admin.getRegionServers().iterator().next();
+    HRegionServer regionServer = UTIL.getMiniHBaseCluster().getRegionServer(serverName);
+    MetricsRegionServerWrapperImpl metricsWrapper  =
+        new MetricsRegionServerWrapperImpl(regionServer);
+    MetricsRegionServerWrapperImpl.RegionServerMetricsWrapperRunnable metricsServer
+        = metricsWrapper.new RegionServerMetricsWrapperRunnable();
+    metricsServer.run();
+    UTIL.loadRandomRows(table, FAMILY.getBytes(), 1, 2000);
+    Thread.sleep(METRICS_PERIOD);
+    metricsServer.run();
+    admin.disableTable(TABLENAME);
+    Thread.sleep(METRICS_PERIOD);
+    metricsServer.run();
+    Assert.assertTrue(metricsWrapper.getRequestsPerSecond() > -1);
+  }
+}
 
 Review comment:
   Thank you very much @saintstack. I am disabling table(the equivalent of region transition in my case) so all of his regions will be closed and removed from HRegionServer#onlineregion map. But metricsystem still have these closed regions metric and it never removed from metricsystem. so if we compute new metric then it will be a negative value.  This can be re-produced running this test case without patch.
   
   Hope, I am answering correct answer @saintstack  Sorry If I am wrong :). I am still fine if you would like to change the test case. 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services