You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2021/12/14 14:57:58 UTC
[hbase] branch branch-2 updated: HBASE-26554 Introduce a new parameter in jmx servlet to exclude the specific mbean (#3930)
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
The following commit(s) were added to refs/heads/branch-2 by this push:
new be00c45 HBASE-26554 Introduce a new parameter in jmx servlet to exclude the specific mbean (#3930)
be00c45 is described below
commit be00c452aa2ac13026e8da808b822cab81bbad1b
Author: Ruanhui <32...@users.noreply.github.com>
AuthorDate: Tue Dec 14 22:50:58 2021 +0800
HBASE-26554 Introduce a new parameter in jmx servlet to exclude the specific mbean (#3930)
Signed-off-by: Duo Zhang <zh...@apache.org>
---
.../apache/hadoop/hbase/http/jmx/JMXJsonServlet.java | 6 +++++-
.../java/org/apache/hadoop/hbase/util/JSONBean.java | 18 +++++++++++++-----
.../hadoop/hbase/http/jmx/TestJMXJsonServlet.java | 6 ++++++
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java
index 7e3a79d..a61e616 100644
--- a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java
+++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java
@@ -212,7 +212,11 @@ public class JMXJsonServlet extends HttpServlet {
if (qry == null) {
qry = "*:*";
}
- if (beanWriter.write(this.mBeanServer, new ObjectName(qry), null, description) != 0) {
+ String excl = request.getParameter("excl");
+ ObjectName excluded = excl == null ? null : new ObjectName(excl);
+
+ if (beanWriter.write(this.mBeanServer, new ObjectName(qry),
+ null, description, excluded) != 0) {
beanWriter.flush();
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java
index 0dbe0fd..4afc567 100644
--- a/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java
+++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java
@@ -66,8 +66,13 @@ public class JSONBean {
void write(String key, String value) throws IOException;
- int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description)
- throws IOException;
+ default int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
+ boolean description) throws IOException {
+ return write(mBeanServer, qry, attribute, description, null);
+ }
+
+ int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description,
+ ObjectName excluded) throws IOException;
void flush() throws IOException;
}
@@ -118,8 +123,8 @@ public class JSONBean {
@Override
public int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
- boolean description) throws IOException {
- return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description);
+ boolean description, ObjectName excluded) throws IOException {
+ return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description, excluded);
}
};
}
@@ -128,7 +133,7 @@ public class JSONBean {
* @return Return non-zero if failed to find bean. 0
*/
private static int write(JsonWriter writer, MBeanServer mBeanServer, ObjectName qry,
- String attribute, boolean description) throws IOException {
+ String attribute, boolean description, ObjectName excluded) throws IOException {
LOG.debug("Listing beans for {}", qry);
Set<ObjectName> names = null;
names = mBeanServer.queryNames(qry, null);
@@ -137,6 +142,9 @@ public class JSONBean {
Pattern[] matchingPattern = null;
while (it.hasNext()) {
ObjectName oname = it.next();
+ if (excluded != null && excluded.apply(oname)) {
+ continue;
+ }
MBeanInfo minfo;
String code = "";
String descriptionStr = null;
diff --git a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java
index e907a32..02248d6 100644
--- a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java
+++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java
@@ -122,6 +122,12 @@ public class TestJMXJsonServlet extends HttpServerFunctionalTest {
assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result);
assertReFind("\"committed\"\\s*:", result);
assertReFind("\\}\\);$", result);
+
+ // test exclude the specific mbean
+ result = readOutput(new URL(baseUrl,
+ "/jmx?excl=Hadoop:service=HBase,name=RegionServer,sub=Regions"));
+ LOG.info("/jmx RESULT: " + result);
+ assertNotFind("\"name\"\\s*:\\s*\"Hadoop:service=HBase,name=RegionServer,sub=Regions\"",result);
}
@Test