From fc64e8482905a5b137549a256c844f2390de5e8a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 10 Jun 2022 17:37:20 -0700 Subject: [PATCH] fix: 'mc admin top api' IOPs, RX/TX remove them (#4115) The current implementation didn't cater to concurrency factor i.e X calls happening in parallel so the resulting values for IOPs, RX, and TX were all skewed, change this to print totals instead. We need to bring moving average behavior to know the overall IOPs, RX, TX per second here. Will bring this change subsequently, keep it simple for now. --- cmd/top-api-spinner.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cmd/top-api-spinner.go b/cmd/top-api-spinner.go index debbf851..e735bb35 100644 --- a/cmd/top-api-spinner.go +++ b/cmd/top-api-spinner.go @@ -68,6 +68,7 @@ type traceUI struct { quitting bool startTime time.Time result topAPIResult + lastResult topAPIResult apiStatsMap map[string]*topAPIStats } @@ -82,7 +83,6 @@ func initTraceUI() *traceUI { s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) return &traceUI{ spinner: s, - startTime: time.Now(), apiStatsMap: make(map[string]*topAPIStats), } } @@ -103,6 +103,9 @@ func (m *traceUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case topAPIResult: m.result = msg + if m.result.apiCallInfo.Trace.FuncName != "" { + m.lastResult = m.result + } if msg.final { m.quitting = true return m, tea.Quit @@ -137,6 +140,9 @@ func (m *traceUI) View() string { table.SetNoWhiteSpace(true) res := m.result.apiCallInfo + if m.startTime.IsZero() && !res.Trace.Time.IsZero() { + m.startTime = res.Trace.Time + } if res.Trace.FuncName != "" && res.Trace.FuncName != "errorResponseHandler" { traceSt, ok := m.apiStatsMap[res.Trace.FuncName] if !ok { @@ -170,21 +176,20 @@ func (m *traceUI) View() string { s.WriteString(fmt.Sprintf("\nTopAPI: %s", m.spinner.View())) } else { var totalTX, totalRX, totalCalls uint64 - currentTime := time.Now() - duration := currentTime.Sub(m.startTime).Seconds() - if duration == 0 { - duration = 1 // duration is always 1-sec atleast + lastReqTime := m.lastResult.apiCallInfo.Trace.Time + if m.lastResult.apiCallInfo.Trace.Time.IsZero() { + lastReqTime = time.Now() } for _, stats := range m.apiStatsMap { totalRX += stats.loadAPIBytesRX() totalTX += stats.loadAPIBytesTX() totalCalls += stats.loadAPICall() } - msg := fmt.Sprintf("\n========\n%d IOP/s, RX %s/s, TX %s/s - in the last %s", - totalCalls/uint64(duration), - humanize.IBytes(totalRX/uint64(duration)), - humanize.IBytes(totalTX/uint64(duration)), - humanize.RelTime(m.startTime, currentTime, "", ""), + msg := fmt.Sprintf("\n========\nTotal: %d Calls, %s RX, %s TX - in %.02fs", + totalCalls, + humanize.IBytes(totalRX), + humanize.IBytes(totalTX), + lastReqTime.Sub(m.startTime).Seconds(), ) s.WriteString(msg) s.WriteString("\n")