Skip to content

Commit

Permalink
HBASE-26554 Introduce a new parameter in jmx servlet to exclude the s…
Browse files Browse the repository at this point in the history
…pecific mbean (#3930)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
  • Loading branch information
frostruan authored Dec 14, 2021
1 parent a3ff8e4 commit 136b1ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ public interface Writer extends Closeable {

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;
}
Expand Down Expand Up @@ -118,8 +123,8 @@ public void write(String key, String value) throws IOException {

@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);
}
};
}
Expand All @@ -128,7 +133,7 @@ public int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
* @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);
Expand All @@ -137,6 +142,9 @@ private static int write(JsonWriter writer, MBeanServer mBeanServer, ObjectName
Pattern[] matchingPattern = null;
while (it.hasNext()) {
ObjectName oname = it.next();
if (excluded != null && excluded.apply(oname)) {
continue;
}
MBeanInfo minfo;
String code = "";
String descriptionStr = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public static void assertNotFind(String re, String value) {
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
Expand Down

0 comments on commit 136b1ea

Please sign in to comment.