feat(cli): print group status for flashnode #1000021930

Signed-off-by: clinx <chenlin1@oppo.com>
This commit is contained in:
clinx 2025-03-28 15:11:00 +08:00 committed by zhumingze1108
parent f5783cd728
commit 2176a61e7e
3 changed files with 34 additions and 17 deletions

View File

@ -297,7 +297,7 @@ func newCmdFlashGroupGet(client *master.MasterClient) *cobra.Command {
tbl = table{formatFlashNodeSimpleViewTableTitle}
}
for _, flashNodeViewInfos := range fgView.ZoneFlashNodes {
tbl = showFlashNodesView(flashNodeViewInfos, showHitRate, tbl)
tbl = showFlashNodesView(flashNodeViewInfos, showHitRate, nil, tbl)
}
stdoutln(alignTable(tbl...))
return
@ -435,7 +435,7 @@ func newCmdFlashGroupSearch(client *master.MasterClient) *cobra.Command {
stdoutlnf("Found in FlashGroup:%d", whichGroup)
tbl := table{formatFlashNodeSimpleViewTableTitle}
for _, fnNodes := range fg.ZoneFlashNodes {
tbl = showFlashNodesView(fnNodes, false, tbl)
tbl = showFlashNodesView(fnNodes, false, nil, tbl)
}
stdoutln(alignTable(tbl...))
return
@ -460,10 +460,12 @@ func newCmdFlashGroupGraph(client *master.MasterClient) *cobra.Command {
set := make(map[uint32]struct{})
groups := make(map[uint64]proto.FlashGroupAdminView)
groupn := make(map[uint64]int)
groupStatusMap := make(map[uint64]string)
slots := make([]slotInfo, 0)
for _, fg := range fgView.FlashGroups {
groups[fg.ID] = fg
groupn[fg.ID] = 0
groupStatusMap[fg.ID] = fg.Status.String()
for _, slot := range fg.Slots {
if _, in := set[slot]; in {
continue
@ -478,7 +480,6 @@ func newCmdFlashGroupGraph(client *master.MasterClient) *cobra.Command {
sort.Slice(slots, func(i, j int) bool {
return slots[i].slot < slots[j].slot
})
stdoutln("[Flash Groups]")
tbl := table{arow("Slot", "ID", "Status", "Count", "Ref", "Proportion")}
for idx, slot := range slots {
@ -508,11 +509,15 @@ func newCmdFlashGroupGraph(client *master.MasterClient) *cobra.Command {
}
}
}
graphFlashNodeTitle := make([]interface{}, len(formatFlashNodeViewTableTitle)+1)
copy(graphFlashNodeTitle, formatFlashNodeViewTableTitle[:6])
graphFlashNodeTitle[6] = "GroupStatus"
copy(graphFlashNodeTitle[7:], formatFlashNodeViewTableTitle[6:])
stdoutln("[FlashNodes Busy]")
tbl = showFlashNodesView(busyNodes, true, table{formatFlashNodeViewTableTitle})
tbl = showFlashNodesView(busyNodes, true, groupStatusMap, table{graphFlashNodeTitle})
stdoutln(alignTable(tbl...))
stdoutln("[FlashNodes Idle]")
tbl = showFlashNodesView(idleNodes, true, table{formatFlashNodeViewTableTitle})
tbl = showFlashNodesView(idleNodes, true, groupStatusMap, table{graphFlashNodeTitle})
stdoutln(alignTable(tbl...))
return
},

View File

@ -168,7 +168,7 @@ func newCmdFlashNodeList(client *master.MasterClient) *cobra.Command {
stdoutln(fmt.Sprintf("[FlashNodes] active:%d", activeFilter))
tbl := table{formatFlashNodeViewTableTitle}
for _, flashNodeViewInfos := range zoneFlashNodes {
tbl = showFlashNodesView(flashNodeViewInfos, true, tbl)
tbl = showFlashNodesView(flashNodeViewInfos, true, nil, tbl)
}
stdoutln(alignTable(tbl...))
return
@ -266,14 +266,24 @@ func newCmdFlashNodeHTTPInactiveDisk(client *master.MasterClient) *cobra.Command
}
}
func showFlashNodesView(flashNodeViewInfos []*proto.FlashNodeViewInfo, showStat bool, tbl table) table {
func showFlashNodesView(flashNodeViewInfos []*proto.FlashNodeViewInfo, showStat bool, groupStats map[uint64]string, tbl table) table {
sort.Slice(flashNodeViewInfos, func(i, j int) bool {
return flashNodeViewInfos[i].ID < flashNodeViewInfos[j].ID
})
var groupActiveInfo string
for _, fn := range flashNodeViewInfos {
groupActiveInfo = ""
nodeInfo := arow(fn.ZoneName, fn.ID, fn.Addr, formatYesNo(fn.IsActive), formatYesNo(fn.IsEnable),
fn.FlashGroupID, formatTimeToString(fn.ReportTime))
if groupStats != nil {
if v, ok := groupStats[fn.FlashGroupID]; ok {
groupActiveInfo = v
}
nodeInfo = arow(fn.ZoneName, fn.ID, fn.Addr, formatYesNo(fn.IsActive), formatYesNo(fn.IsEnable),
fn.FlashGroupID, groupActiveInfo, formatTimeToString(fn.ReportTime))
}
if !showStat {
tbl = tbl.append(arow(fn.ZoneName, fn.ID, fn.Addr, formatYesNo(fn.IsActive), formatYesNo(fn.IsEnable),
fn.FlashGroupID, formatTimeToString(fn.ReportTime)))
tbl = tbl.append(nodeInfo)
continue
}
@ -289,13 +299,15 @@ func showFlashNodesView(flashNodeViewInfos []*proto.FlashNodeViewInfo, showStat
num = strconv.Itoa(stat.KeyNum)
status = strconv.Itoa(stat.Status)
}
if index == 0 {
tbl = tbl.append(arow(fn.ZoneName, fn.ID, fn.Addr, formatYesNo(fn.IsActive), formatYesNo(fn.IsEnable),
fn.FlashGroupID, formatTimeToString(fn.ReportTime), dataPath, hitRate, evicts, limit, maxAlloc, hasAlloc, num, status))
} else {
tbl = tbl.append(arow("", "", "", "", "",
"", "", dataPath, hitRate, evicts, limit, maxAlloc, hasAlloc, num, status))
if index != 0 {
if groupStats != nil {
nodeInfo = arow("", "", "", "", "", "", "", "")
} else {
nodeInfo = arow("", "", "", "", "", "", "")
}
}
nodeInfo = append(nodeInfo, dataPath, hitRate, evicts, limit, maxAlloc, hasAlloc, num, status)
tbl = tbl.append(nodeInfo)
}
}
return tbl

View File

@ -79,7 +79,7 @@ func TestFmtFlashNode(t *testing.T) {
stdoutln()
for zone, nodes := range zoneNodes {
stdoutln("[Flash Nodes]", zone)
tbl = showFlashNodesView(nodes, false, table{formatFlashNodeSimpleViewTableTitle})
tbl = showFlashNodesView(nodes, false, nil, table{formatFlashNodeSimpleViewTableTitle})
stdoutln(alignTable(tbl...))
}
@ -87,7 +87,7 @@ func TestFmtFlashNode(t *testing.T) {
stdoutln("[FlashNodes All]")
tbl = table{formatFlashNodeSimpleViewTableTitle}
for _, nodes := range zoneNodes {
tbl = showFlashNodesView(nodes, false, tbl)
tbl = showFlashNodesView(nodes, false, nil, tbl)
}
stdoutln(alignTable(tbl...))
}