Skip to content

Commit 3ec00e7

Browse files
committed
[Feature] (show) add IP field display for show frontends/backends/broker commands
1 parent 6eee338 commit 3ec00e7

10 files changed

Lines changed: 69 additions & 10 deletions

File tree

fe/fe-core/src/main/java/org/apache/doris/catalog/BrokerMgr.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.doris.common.util.NetUtils;
3030
import org.apache.doris.common.util.TimeUtils;
3131
import org.apache.doris.nereids.trees.plans.commands.info.ModifyBrokerOp;
32+
import org.apache.doris.nereids.util.HostUtils;
3233
import org.apache.doris.persist.gson.GsonUtils;
3334

3435
import com.google.common.collect.ArrayListMultimap;
@@ -52,7 +53,7 @@
5253
*/
5354
public class BrokerMgr {
5455
public static final ImmutableList<String> BROKER_PROC_NODE_TITLE_NAMES = new ImmutableList.Builder<String>()
55-
.add("Name").add("Host").add("Port").add("Alive")
56+
.add("Name").add("Host").add("IP").add("Port").add("Alive")
5657
.add("LastStartTime").add("LastUpdateTime").add("ErrMsg")
5758
.build();
5859

@@ -387,6 +388,7 @@ public ProcResult fetchResult() {
387388
List<String> row = Lists.newArrayList();
388389
row.add(brokerName);
389390
row.add(broker.host);
391+
row.add(HostUtils.resolveHostToIp(broker.host));
390392
row.add(String.valueOf(broker.port));
391393
row.add(String.valueOf(broker.isAlive));
392394
row.add(TimeUtils.longToTimeString(broker.lastStartTime));

fe/fe-core/src/main/java/org/apache/doris/common/proc/BackendsProcDir.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.doris.common.util.DebugUtil;
2525
import org.apache.doris.common.util.ListComparator;
2626
import org.apache.doris.common.util.TimeUtils;
27+
import org.apache.doris.nereids.util.HostUtils;
2728
import org.apache.doris.system.Backend;
2829
import org.apache.doris.system.SystemInfoService;
2930
import org.apache.doris.thrift.TUnit;
@@ -51,7 +52,7 @@ public class BackendsProcDir implements ProcDirInterface {
5152
.add("DataUsedCapacity").add("TrashUsedCapacity").add("AvailCapacity").add("TotalCapacity").add("UsedPct")
5253
.add("MaxDiskUsedPct").add("RemoteUsedCapacity").add("Tag").add("ErrMsg").add("Version").add("Status")
5354
.add("HeartbeatFailureCounter").add("NodeRole").add("CpuCores").add("Memory").add("LiveSince")
54-
.add("RunningTasks").build();
55+
.add("RunningTasks").add("IP").build();
5556

5657
public static final ImmutableList<String> DISK_TITLE_NAMES = new ImmutableList.Builder<String>()
5758
.add("BackendId").add("Host").add("RootPath").add("DirType").add("DiskState")
@@ -179,6 +180,8 @@ public static List<List<String>> getBackendInfos() {
179180

180181
// runningFragments
181182
backendInfo.add(String.valueOf(backend.getRunningTasks()));
183+
// ip resolved from hostname
184+
backendInfo.add(HostUtils.resolveHostToIp(backend.getHost()));
182185

183186
comparableBackendInfos.add(backendInfo);
184187
}
@@ -229,5 +232,4 @@ public ProcNodeInterface lookup(String beIdStr) throws AnalysisException {
229232

230233
return new BackendProcNode(backend);
231234
}
232-
233235
}

fe/fe-core/src/main/java/org/apache/doris/common/proc/FrontendsProcNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.doris.common.Pair;
2323
import org.apache.doris.common.io.DiskUtils;
2424
import org.apache.doris.common.util.TimeUtils;
25+
import org.apache.doris.nereids.util.HostUtils;
2526
import org.apache.doris.qe.ConnectContext;
2627
import org.apache.doris.service.FeDiskInfo;
2728
import org.apache.doris.system.Frontend;
@@ -49,7 +50,7 @@ public class FrontendsProcNode implements ProcNodeInterface {
4950
.add("Name").add("Host").add("EditLogPort").add("HttpPort").add("QueryPort").add("RpcPort")
5051
.add("ArrowFlightSqlPort").add("Role").add("IsMaster").add("ClusterId").add("Join").add("Alive")
5152
.add("ReplayedJournalId").add("LastStartTime").add("LastHeartbeat").add("IsHelper").add("ErrMsg")
52-
.add("Version").add("CurrentConnected").add("LiveSince")
53+
.add("Version").add("CurrentConnected").add("LiveSince").add("IP")
5354
.build();
5455

5556
public static final ImmutableList<String> DISK_TITLE_NAMES = new ImmutableList.Builder<String>()
@@ -168,6 +169,7 @@ public static void getFrontendsInfo(Env env, List<List<String>> infos) {
168169
// To indicate which FE we currently connected
169170
info.add(fe.getHost().equals(selfNode) ? "Yes" : "No");
170171
info.add(TimeUtils.longToTimeString(fe.getLiveSince()));
172+
info.add(HostUtils.resolveHostToIp(fe.getHost()));
171173

172174
infos.add(info);
173175
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.nereids.util;
19+
20+
import org.apache.logging.log4j.LogManager;
21+
import org.apache.logging.log4j.Logger;
22+
23+
import java.net.InetAddress;
24+
25+
/**
26+
* HostUtils
27+
*/
28+
public class HostUtils {
29+
30+
private static final Logger LOG = LogManager.getLogger(HostUtils.class);
31+
32+
/**
33+
* resolve ip from hostname
34+
*/
35+
public static String resolveHostToIp(String host) {
36+
try {
37+
InetAddress address = InetAddress.getByName(host);
38+
return address.getHostAddress();
39+
} catch (Exception e) {
40+
LOG.warn("Failed to resolve host {} to IP: {}", host, e.getMessage());
41+
return "Unknown";
42+
}
43+
}
44+
45+
}

fe/fe-core/src/main/java/org/apache/doris/system/Backend.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.doris.common.util.DebugPointUtil;
3030
import org.apache.doris.common.util.PrintableMap;
3131
import org.apache.doris.common.util.TimeUtils;
32+
import org.apache.doris.nereids.util.HostUtils;
3233
import org.apache.doris.persist.gson.GsonUtils;
3334
import org.apache.doris.qe.SimpleScheduler;
3435
import org.apache.doris.resource.Tag;
@@ -370,6 +371,7 @@ public String getDetailsForCreateReplica() {
370371
StringBuilder sb = new StringBuilder("[");
371372
sb.append("backendId=").append(id);
372373
sb.append(", host=").append(host);
374+
sb.append(", ip=").append(HostUtils.resolveHostToIp(host));
373375
if (!isAlive()) {
374376
sb.append(", isAlive=false, exclude it");
375377
} else if (isDecommissioned()) {

fe/fe-core/src/main/java/org/apache/doris/tablefunction/BackendsTableValuedFunction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public class BackendsTableValuedFunction extends MetadataTableValuedFunction {
6969
new Column("Version", ScalarType.createStringType()),
7070
new Column("Status", ScalarType.createStringType()),
7171
new Column("HeartbeatFailureCounter", ScalarType.createType(PrimitiveType.INT)),
72-
new Column("NodeRole", ScalarType.createStringType()));
72+
new Column("NodeRole", ScalarType.createStringType()),
73+
new Column("IP", ScalarType.createStringType())
74+
);
7375

7476
private static final ImmutableMap<String, Integer> COLUMN_TO_INDEX;
7577

fe/fe-core/src/main/java/org/apache/doris/tablefunction/FrontendsTableValuedFunction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public class FrontendsTableValuedFunction extends MetadataTableValuedFunction {
6262
new Column("IsHelper", ScalarType.createStringType()),
6363
new Column("ErrMsg", ScalarType.createStringType()),
6464
new Column("Version", ScalarType.createStringType()),
65-
new Column("CurrentConnected", ScalarType.createStringType()));
65+
new Column("CurrentConnected", ScalarType.createStringType()),
66+
new Column("IP", ScalarType.createStringType())
67+
);
6668

6769
private static final ImmutableMap<String, Integer> COLUMN_TO_INDEX;
6870

fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.apache.doris.mysql.privilege.PrivPredicate;
7878
import org.apache.doris.nereids.trees.expressions.Expression;
7979
import org.apache.doris.nereids.util.FrontendConjunctsUtils;
80+
import org.apache.doris.nereids.util.HostUtils;
8081
import org.apache.doris.nereids.util.PlanUtils;
8182
import org.apache.doris.qe.ConnectContext;
8283
import org.apache.doris.qe.QeProcessorImpl;
@@ -501,6 +502,7 @@ private static TFetchSchemaTableDataResult backendsMetadataResult(TMetadataTable
501502

502503
// node role, show the value only when backend is alive.
503504
trow.addToColumnValue(new TCell().setStringVal(backend.isAlive() ? backend.getNodeRoleTag().value : ""));
505+
trow.addToColumnValue(new TCell().setStringVal(HostUtils.resolveHostToIp(backend.getHost())));
504506

505507
dataBatch.add(trow);
506508
}

regression-test/suites/external_table_p0/tvf/test_backends_tvf.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
suite("test_backends_tvf","p0,external,tvf,external_docker") {
2020
List<List<Object>> table = sql """ select * from backends(); """
2121
assertTrue(table.size() > 0)
22-
assertEquals(25, table[0].size())
22+
assertEquals(26, table[0].size())
2323

2424
// filter columns
2525
table = sql """ select BackendId, Host, Alive, TotalCapacity, Version, NodeRole from backends();"""
@@ -51,7 +51,7 @@ suite("test_backends_tvf","p0,external,tvf,external_docker") {
5151
res = sql """ select count(*) from backends() where alive = true; """
5252
assertTrue(res[0][0] > 0)
5353

54-
sql """ select BackendId, Host, HeartbeatPort,
54+
sql """ select BackendId, Host, IP, HeartbeatPort,
5555
BePort, HttpPort, BrpcPort, LastStartTime, LastHeartbeat, Alive
5656
SystemDecommissioned, tabletnum
5757
DataUsedCapacity, AvailCapacity, TotalCapacity, UsedPct

regression-test/suites/external_table_p0/tvf/test_frontends_tvf.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suite("test_frontends_tvf","p0,external,tvf,external_docker") {
2020
List<List<Object>> table = sql """ select * from `frontends`(); """
2121
logger.info("${table}")
2222
assertTrue(table.size() > 0)
23-
assertTrue(table[0].size() == 19)
23+
assertTrue(table[0].size() == 20)
2424

2525
// filter columns
2626
table = sql """ select Name from `frontends`();"""
@@ -43,7 +43,7 @@ suite("test_frontends_tvf","p0,external,tvf,external_docker") {
4343
def res = sql """ select count(*) from frontends() where alive = 'true'; """
4444
assertTrue(res[0][0] > 0)
4545

46-
sql """ select Name, Host, EditLogPort
46+
sql """ select Name, Host, IP, EditLogPort
4747
HttpPort, QueryPort, RpcPort, ArrowFlightSqlPort, `Role`, IsMaster, ClusterId
4848
`Join`, Alive, ReplayedJournalId, LastHeartbeat
4949
IsHelper, ErrMsg, Version, CurrentConnected from frontends();

0 commit comments

Comments
 (0)