Skip to content

Commit

Permalink
[behavior change](fe) Change ShowProcessStmt output column format
Browse files Browse the repository at this point in the history
* Show fe host info in output columns by default
* Add a new column `CloudCluster` for cloud cluster info
  • Loading branch information
SWJTU-ZhangLei committed Apr 22, 2024
1 parent 440b2d0 commit 025e8d0
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@
// Used to show connection belong to this user.
public class ShowProcesslistStmt extends ShowStmt {
private static final ShowResultSetMetaData META_DATA = ShowResultSetMetaData.builder()
.addColumn(new Column("CurrentConnected", ScalarType.createVarchar(16)))
.addColumn(new Column("Id", ScalarType.createType(PrimitiveType.BIGINT)))
.addColumn(new Column("User", ScalarType.createVarchar(16)))
.addColumn(new Column("Host", ScalarType.createVarchar(16)))
.addColumn(new Column("LoginTime", ScalarType.createVarchar(16)))
.addColumn(new Column("Catalog", ScalarType.createVarchar(16)))
.addColumn(new Column("Db", ScalarType.createVarchar(16)))
.addColumn(new Column("Command", ScalarType.createVarchar(16)))
.addColumn(new Column("Time", ScalarType.createType(PrimitiveType.INT)))
.addColumn(new Column("State", ScalarType.createVarchar(64)))
.addColumn(new Column("QueryId", ScalarType.createVarchar(64)))
.addColumn(new Column("Info", ScalarType.STRING)).build();

private static final ShowResultSetMetaData ALL_META_DATA = ShowResultSetMetaData.builder()
.addColumn(new Column("CurrentConnected", ScalarType.createVarchar(16)))
.addColumn(new Column("Id", ScalarType.createType(PrimitiveType.BIGINT)))
.addColumn(new Column("User", ScalarType.createVarchar(16)))
Expand All @@ -53,7 +39,8 @@ public class ShowProcesslistStmt extends ShowStmt {
.addColumn(new Column("State", ScalarType.createVarchar(64)))
.addColumn(new Column("QueryId", ScalarType.createVarchar(64)))
.addColumn(new Column("Info", ScalarType.STRING))
.addColumn(new Column("FE", ScalarType.createVarchar(16))).build();
.addColumn(new Column("FE", ScalarType.createVarchar(16)))
.addColumn(new Column("CloudCluster", ScalarType.createVarchar(16))).build();

private boolean isFull;
private boolean isShowAllFe;
Expand Down Expand Up @@ -87,6 +74,6 @@ public String toString() {

@Override
public ShowResultSetMetaData getMetaData() {
return isShowAllFe ? ALL_META_DATA : META_DATA;
return META_DATA;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
public class SessionController extends RestBaseController {

private static final List<String> SESSION_TABLE_HEADER = Lists.newArrayList();

private static final List<String> ALL_SESSION_TABLE_HEADER = Lists.newArrayList();

private static final Logger LOG = LogManager.getLogger(SessionController.class);

static {
Expand All @@ -70,21 +67,21 @@ public class SessionController extends RestBaseController {
SESSION_TABLE_HEADER.add("State");
SESSION_TABLE_HEADER.add("QueryId");
SESSION_TABLE_HEADER.add("Info");
ALL_SESSION_TABLE_HEADER.addAll(SESSION_TABLE_HEADER);
ALL_SESSION_TABLE_HEADER.add("FE");
SESSION_TABLE_HEADER.add("FE");
SESSION_TABLE_HEADER.add("CloudCluster");
}

@RequestMapping(path = "/session/all", method = RequestMethod.GET)
public Object allSession(HttpServletRequest request) {
Map<String, Object> result = Maps.newHashMap();
result.put("column_names", ALL_SESSION_TABLE_HEADER);
result.put("column_names", SESSION_TABLE_HEADER);
List<Map<String, String>> sessionInfo = Env.getCurrentEnv().getFrontends(null)
.stream()
.filter(Frontend::isAlive)
.map(frontend -> {
try {
return Env.getCurrentEnv().getSelfNode().getHost().equals(frontend.getHost())
? getSessionInfo(true)
? getSessionInfo()
: getOtherSessionInfo(request, frontend);
} catch (IOException e) {
LOG.warn("", e);
Expand All @@ -104,22 +101,22 @@ public Object allSession(HttpServletRequest request) {
public Object session() {
Map<String, Object> result = Maps.newHashMap();
result.put("column_names", SESSION_TABLE_HEADER);
result.put("rows", getSessionInfo(false));
result.put("rows", getSessionInfo());
ResponseEntity entity = ResponseEntityBuilder.ok(result);
((ResponseBody) entity.getBody()).setCount(result.size());
return entity;
}

private List<Map<String, String>> getSessionInfo(boolean showFe) {
private List<Map<String, String>> getSessionInfo() {
List<ConnectContext.ThreadInfo> threadInfos = ExecuteEnv.getInstance().getScheduler()
.listConnection("root", false);
long nowMs = System.currentTimeMillis();
return threadInfos.stream()
.map(info -> info.toRow(-1, nowMs, showFe))
.map(info -> info.toRow(-1, nowMs))
.map(row -> {
Map<String, String> record = new HashMap<>();
for (int i = 0; i < row.size(); i++) {
record.put(showFe ? ALL_SESSION_TABLE_HEADER.get(i) : SESSION_TABLE_HEADER.get(i), row.get(i));
record.put(SESSION_TABLE_HEADER.get(i), row.get(i));
}
return record;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ public Map<String, String> getResultAttachedInfo() {
public class ThreadInfo {
public boolean isFull;

public List<String> toRow(int connId, long nowMs, boolean showFe) {
public List<String> toRow(int connId, long nowMs) {
List<String> row = Lists.newArrayList();
if (connId == connectionId) {
row.add("Yes");
Expand Down Expand Up @@ -1042,10 +1042,8 @@ public List<String> toRow(int connId, long nowMs, boolean showFe) {
row.add("");
}

if (showFe) {
row.add(Env.getCurrentEnv().getSelfNode().getHost());
}

row.add(Env.getCurrentEnv().getSelfNode().getHost());
row.add(cloudCluster);
return row;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public List<ConnectContext.ThreadInfo> listConnection(String user, boolean isFul
}

// used for thrift
public List<List<String>> listConnectionWithoutAuth(boolean isShowFullSql, boolean isShowFeHost) {
public List<List<String>> listConnectionWithoutAuth(boolean isShowFullSql) {
List<List<String>> list = new ArrayList<>();
long nowMs = System.currentTimeMillis();
for (ConnectContext ctx : connectionMap.values()) {
list.add(ctx.toThreadInfo(isShowFullSql).toRow(-1, nowMs, isShowFeHost));
list.add(ctx.toThreadInfo(isShowFullSql).toRow(-1, nowMs));
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private void handleShowProcesslist() {
.listConnection(ctx.getQualifiedUser(), isShowFullSql);
long nowMs = System.currentTimeMillis();
for (ConnectContext.ThreadInfo info : threadInfos) {
rowSet.add(info.toRow(ctx.getConnectionId(), nowMs, isShowAllFe));
rowSet.add(info.toRow(ctx.getConnectionId(), nowMs));
}

if (isShowAllFe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3761,7 +3761,7 @@ public TShowProcessListResult showProcessList(TShowProcessListRequest request) {
isShowFullSql = request.isShowFullSql();
}
List<List<String>> processList = ExecuteEnv.getInstance().getScheduler()
.listConnectionWithoutAuth(isShowFullSql, true);
.listConnectionWithoutAuth(isShowFullSql);
TShowProcessListResult result = new TShowProcessListResult();
result.setProcessList(processList);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void testNormal() {

// Thread info
Assert.assertNotNull(ctx.toThreadInfo(false));
List<String> row = ctx.toThreadInfo(false).toRow(101, 1000, false);
Assert.assertEquals(12, row.size());
List<String> row = ctx.toThreadInfo(false).toRow(101, 1000);
Assert.assertEquals(14, row.size());
Assert.assertEquals("Yes", row.get(0));
Assert.assertEquals("101", row.get(1));
Assert.assertEquals("testUser", row.get(2));
Expand Down
40 changes: 40 additions & 0 deletions regression-test/suites/show_p0/test_show_processlist.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.

import org.apache.doris.regression.util.Http

suite("test_show_processlist") {
sql """set show_all_fe_connection = false;"""
def result = sql """show processlist;"""
logger.info("result:${result}")
assertTrue(result[0].size() == 14)
sql """set show_all_fe_connection = true;"""
result = sql """show processlist;"""
logger.info("result:${result}")
assertTrue(result[0].size() == 14)
sql """set show_all_fe_connection = false;"""

def url1 = "http://${context.config.feHttpAddress}/rest/v1/session"
result = Http.GET(url1, true)
logger.info("result:${result}")
assertTrue(result["data"]["column_names"].size() == 14);

def url2 = "http://${context.config.feHttpAddress}/rest/v1/session/all"
result = Http.GET(url2, true)
logger.info("result:${result}")
assertTrue(result["data"]["column_names"].size() == 14);
}

0 comments on commit 025e8d0

Please sign in to comment.