zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fang...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3327: Add unrecoverable error metric
Date Thu, 21 Mar 2019 18:15:13 GMT
This is an automated email from the ASF dual-hosted git repository.

fangmin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 07c3aaf  ZOOKEEPER-3327: Add unrecoverable error metric
07c3aaf is described below

commit 07c3aaf3d723fb3144c0aedc0c2b655325df70e9
Author: Jie Huang <jiehuang@fb.com>
AuthorDate: Thu Mar 21 11:15:06 2019 -0700

    ZOOKEEPER-3327: Add unrecoverable error metric
    
    Author: Jie Huang <jiehuang@fb.com>
    
    Reviewers: andor@apache.org, eolivelli@apache.org, fangmin@apache.org
    
    Closes #862 from jhuan31/ZOOKEEPER-3327
---
 .../org/apache/zookeeper/server/ServerMetrics.java |  2 +
 .../zookeeper/server/ZooKeeperCriticalThread.java  |  1 +
 .../server/ZooKeeperCriticalThreadMetricsTest.java | 88 ++++++++++++++++++++++
 3 files changed, 91 insertions(+)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerMetrics.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerMetrics.java
index bc66d66..a664872 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerMetrics.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerMetrics.java
@@ -74,6 +74,8 @@ public enum ServerMetrics {
     CONNECTION_TOKEN_DEFICIT(new AvgMinMaxCounter("connection_token_deficit")),
     CONNECTION_REJECTED(new SimpleCounter("connection_rejected")),
 
+    UNRECOVERABLE_ERROR_COUNT(new SimpleCounter("unrecoverable_error_count")),
+
     BYTES_RECEIVED_COUNT(new SimpleCounter("bytes_received_count")),
 
     /**
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
index d52d01d..02bcb3e 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperCriticalThread.java
@@ -47,5 +47,6 @@ public class ZooKeeperCriticalThread extends ZooKeeperThread {
     protected void handleException(String threadName, Throwable e) {
         LOG.error("Severe unrecoverable error, from thread : {}", threadName, e);
         listener.notifyStopping(threadName, ExitCode.UNEXPECTED_ERROR.getValue());
+        ServerMetrics.UNRECOVERABLE_ERROR_COUNT.add(1);
     }
 }
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperCriticalThreadMetricsTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperCriticalThreadMetricsTest.java
new file mode 100644
index 0000000..7c36137
--- /dev/null
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ZooKeeperCriticalThreadMetricsTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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.zookeeper.server;
+
+import org.apache.zookeeper.ZKTestCase;
+import org.apache.zookeeper.ZooDefs;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+public class ZooKeeperCriticalThreadMetricsTest extends ZKTestCase {
+    CountDownLatch processed;
+
+    private class MyRequestProcessor implements RequestProcessor {
+        @Override
+        public void processRequest(Request request) throws RequestProcessorException {
+            // use this dummy request processor to trigger a unrecoverable ex
+            throw new RequestProcessorException("test", new Exception());
+        }
+
+        @Override
+        public void shutdown() {
+        }
+    }
+
+    private class MyPrepRequestProcessor extends PrepRequestProcessor {
+        public MyPrepRequestProcessor() {
+            super(new ZooKeeperServer(), new MyRequestProcessor());
+        }
+
+        @Override
+        public void run() {
+            super.run();
+            processed.countDown();
+        }
+
+    }
+
+    @Test
+    public void testUnrecoverableErrorCountFromRequestProcessor() throws Exception{
+        ServerMetrics.resetAll();
+
+        processed = new CountDownLatch(1);
+        PrepRequestProcessor processor =new MyPrepRequestProcessor();
+        processor.start();
+
+        processor.processRequest(new Request(null, 1L, 1, ZooDefs.OpCode.setData,
+                ByteBuffer.wrap(new byte[10]), null));
+        processed.await();
+
+        processor.shutdown();
+
+        Map<String, Object> values = ServerMetrics.getAllValues();
+        Assert.assertEquals(1L, values.get("unrecoverable_error_count"));
+    }
+
+    @Test
+    public void testUnrecoverableErrorCount() {
+        ServerMetrics.resetAll();
+
+        ZooKeeperServer zks = new ZooKeeperServer();
+        ZooKeeperCriticalThread thread = new ZooKeeperCriticalThread("test", zks.getZooKeeperServerListener());
+
+        thread.handleException("test", new Exception());
+
+        Map<String, Object> values = ServerMetrics.getAllValues();
+        Assert.assertEquals(1L, values.get("unrecoverable_error_count"));
+    }
+}


Mime
View raw message