This is an automated email from the ASF dual-hosted git repository. zhangduo pushed a commit to branch branch-2 in repository https://gitbox.apache.org/repos/asf/hbase.git
commit c82cf47354ee4970e346d4fdde45ff0273fd2097 Author: Fantasy-Jay <[email protected]> AuthorDate: Thu Jul 6 10:32:08 2023 +0800 HBASE-27845 Distinguish the mutate types of rpc error in MetricsConnection. (#5224) Co-authored-by: fantasy <[email protected]> Co-authored-by: jay.zhu <[email protected]> Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit 047f077f0b6117985eab9d02bb10bb8c328fabfb) --- .../hadoop/hbase/client/MetricsConnection.java | 25 ++++++++++++-- .../hadoop/hbase/client/TestMetricsConnection.java | 39 ++++++++++++++++------ 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java index 1d337372927..89536d430bf 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java @@ -700,7 +700,28 @@ public final class MetricsConnection implements StatisticTrackable { concurrentCallsPerServerHist.update(callsPerServer); } // Update the counter that tracks RPCs by type. - final String methodName = method.getService().getName() + "_" + method.getName(); + StringBuilder methodName = new StringBuilder(); + methodName.append(method.getService().getName()).append("_").append(method.getName()); + // Distinguish mutate types. + if ("Mutate".equals(method.getName())) { + final MutationType type = ((MutateRequest) param).getMutation().getMutateType(); + switch (type) { + case APPEND: + methodName.append("(Append)"); + break; + case DELETE: + methodName.append("(Delete)"); + break; + case INCREMENT: + methodName.append("(Increment)"); + break; + case PUT: + methodName.append("(Put)"); + break; + default: + methodName.append("(Unknown)"); + } + } getMetric(CNT_BASE + methodName, rpcCounters, counterFactory).inc(); if (e != null) { getMetric(FAILURE_CNT_BASE + methodName, rpcCounters, counterFactory).inc(); @@ -777,7 +798,7 @@ public final class MetricsConnection implements StatisticTrackable { } } // Fallback to dynamic registry lookup for DDL methods. - updateRpcGeneric(methodName, stats); + updateRpcGeneric(methodName.toString(), stats); } public void incrCacheDroppingExceptions(Object exception) { diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestMetricsConnection.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestMetricsConnection.java index 66d81599427..469ecd4e10e 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestMetricsConnection.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestMetricsConnection.java @@ -102,7 +102,7 @@ public class TestMetricsConnection { } @Test - public void testMetricsWithMutiConnections() throws IOException { + public void testMetricsWithMultiConnections() throws IOException { Configuration conf = new Configuration(); conf.setBoolean(MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY, true); conf.set(MetricsConnection.METRICS_SCOPE_KEY, "unit-test"); @@ -205,7 +205,8 @@ public class TestMetricsConnection { MutateRequest.newBuilder() .setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo))).setRegion(region) .build(), - MetricsConnection.newCallStats(), null); + MetricsConnection.newCallStats(), + new CallTimeoutException("test with CallTimeoutException")); } final String rpcCountPrefix = "rpcCount_" + ClientService.getDescriptor().getName() + "_"; @@ -215,20 +216,38 @@ public class TestMetricsConnection { long metricVal; Counter counter; - for (String method : new String[] { "Get", "Scan", "Multi", "Mutate" }) { + for (String method : new String[] { "Get", "Scan", "Multi" }) { metricKey = rpcCountPrefix + method; metricVal = METRICS.getRpcCounters().get(metricKey).getCount(); - assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal >= loop); + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop); metricKey = rpcFailureCountPrefix + method; counter = METRICS.getRpcCounters().get(metricKey); metricVal = (counter != null) ? counter.getCount() : 0; - if (method.equals("Get") || method.equals("Mutate")) { + if (method.equals("Get")) { // no failure - assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == 0); + assertEquals("metric: " + metricKey + " val: " + metricVal, 0, metricVal); } else { // has failure - assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop); + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop); + } + } + + String method = "Mutate"; + for (String mutationType : new String[] { "Append", "Delete", "Increment", "Put" }) { + metricKey = rpcCountPrefix + method + "(" + mutationType + ")"; + metricVal = METRICS.getRpcCounters().get(metricKey).getCount(); + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop); + + metricKey = rpcFailureCountPrefix + method + "(" + mutationType + ")"; + counter = METRICS.getRpcCounters().get(metricKey); + metricVal = (counter != null) ? counter.getCount() : 0; + if (mutationType.equals("Put")) { + // has failure + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop); + } else { + // no failure + assertEquals("metric: " + metricKey + " val: " + metricVal, 0, metricVal); } } @@ -236,19 +255,19 @@ public class TestMetricsConnection { metricKey = "rpcRemoteExceptions_IOException"; counter = METRICS.getRpcCounters().get(metricKey); metricVal = (counter != null) ? counter.getCount() : 0; - assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop); + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop); // local exception metricKey = "rpcLocalExceptions_CallTimeoutException"; counter = METRICS.getRpcCounters().get(metricKey); metricVal = (counter != null) ? counter.getCount() : 0; - assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop); + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop * 2); // total exception metricKey = "rpcTotalExceptions"; counter = METRICS.getRpcCounters().get(metricKey); metricVal = (counter != null) ? counter.getCount() : 0; - assertTrue("metric: " + metricKey + " val: " + metricVal, metricVal == loop * 2); + assertEquals("metric: " + metricKey + " val: " + metricVal, metricVal, loop * 3); for (MetricsConnection.CallTracker t : new MetricsConnection.CallTracker[] { METRICS.getGetTracker(), METRICS.getScanTracker(), METRICS.getMultiTracker(),
