Implement missing bits in result listing
This commit is contained in:
parent
15c901ed68
commit
703b260903
|
@ -23,24 +23,9 @@ func init() {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Info("Results")
|
||||
for idx, result := range doneResults {
|
||||
output.ResultItem(output.ResultItemData{
|
||||
ID: result.ID,
|
||||
Index: idx,
|
||||
TotalCount: len(doneResults),
|
||||
Name: result.Name,
|
||||
StartTime: result.StartTime,
|
||||
NetworkName: result.NetworkName,
|
||||
Country: result.Country,
|
||||
ASN: result.ASN,
|
||||
Summary: result.Summary,
|
||||
Done: result.Done,
|
||||
DataUsageUp: result.DataUsageUp,
|
||||
DataUsageDown: result.DataUsageDown,
|
||||
})
|
||||
if len(incompleteResults) > 0 {
|
||||
output.SectionTitle("Incomplete results")
|
||||
}
|
||||
log.Info("Incomplete results")
|
||||
for idx, result := range incompleteResults {
|
||||
output.ResultItem(output.ResultItemData{
|
||||
ID: result.ID,
|
||||
|
@ -57,6 +42,34 @@ func init() {
|
|||
DataUsageDown: result.DataUsageDown,
|
||||
})
|
||||
}
|
||||
|
||||
resultSummary := output.ResultSummaryData{}
|
||||
netCount := make(map[string]int)
|
||||
output.SectionTitle("Results")
|
||||
for idx, result := range doneResults {
|
||||
output.ResultItem(output.ResultItemData{
|
||||
ID: result.ID,
|
||||
Index: idx,
|
||||
TotalCount: len(doneResults),
|
||||
Name: result.Name,
|
||||
StartTime: result.StartTime,
|
||||
NetworkName: result.NetworkName,
|
||||
Country: result.Country,
|
||||
ASN: result.ASN,
|
||||
Summary: result.Summary,
|
||||
Done: result.Done,
|
||||
DataUsageUp: result.DataUsageUp,
|
||||
DataUsageDown: result.DataUsageDown,
|
||||
})
|
||||
resultSummary.TotalTests++
|
||||
netCount[result.ASN]++
|
||||
resultSummary.TotalDataUsageUp += result.DataUsageUp
|
||||
resultSummary.TotalDataUsageDown += result.DataUsageDown
|
||||
}
|
||||
resultSummary.TotalNetworks = int64(len(netCount))
|
||||
|
||||
output.ResultSummary(resultSummary)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -60,6 +61,16 @@ func New(w io.Writer) *Handler {
|
|||
}
|
||||
}
|
||||
|
||||
func logSectionTitle(w io.Writer, f log.Fields) error {
|
||||
colWidth := 24
|
||||
|
||||
title := f.Get("title").(string)
|
||||
fmt.Fprintf(w, "┏"+strings.Repeat("━", colWidth+2)+"┓\n")
|
||||
fmt.Fprintf(w, "┃ %s ┃\n", RightPad(title, colWidth))
|
||||
fmt.Fprintf(w, "┗"+strings.Repeat("━", colWidth+2)+"┛\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
// TypedLog is used for handling special "typed" logs to the CLI
|
||||
func (h *Handler) TypedLog(t string, e *log.Entry) error {
|
||||
switch t {
|
||||
|
@ -70,6 +81,10 @@ func (h *Handler) TypedLog(t string, e *log.Entry) error {
|
|||
return nil
|
||||
case "result_item":
|
||||
return logResultItem(h.Writer, e.Fields)
|
||||
case "result_summary":
|
||||
return logResultSummary(h.Writer, e.Fields)
|
||||
case "section_title":
|
||||
return logSectionTitle(h.Writer, e.Fields)
|
||||
default:
|
||||
return h.DefaultLog(e)
|
||||
}
|
||||
|
|
|
@ -10,10 +10,6 @@ import (
|
|||
"github.com/apex/log"
|
||||
)
|
||||
|
||||
func RightPad(str string, length int) string {
|
||||
return str + strings.Repeat(" ", length-len(str))
|
||||
}
|
||||
|
||||
// XXX Copy-pasta from nettest/groups
|
||||
// PerformanceSummary is the result summary for a performance test
|
||||
type PerformanceSummary struct {
|
||||
|
@ -145,3 +141,20 @@ func logResultItem(w io.Writer, f log.Fields) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func logResultSummary(w io.Writer, f log.Fields) error {
|
||||
|
||||
networks := f.Get("total_networks").(int64)
|
||||
tests := f.Get("total_tests").(int64)
|
||||
dataUp := f.Get("total_data_usage_up").(int64)
|
||||
dataDown := f.Get("total_data_usage_down").(int64)
|
||||
|
||||
// └┬──────────────┬──────────────┬──────────────┬
|
||||
fmt.Fprintf(w, " │ %s │ %s │ %s │\n",
|
||||
RightPad(fmt.Sprintf("%d tests", tests), 12),
|
||||
RightPad(fmt.Sprintf("%d nets", networks), 12),
|
||||
RightPad(fmt.Sprintf("%d ⬆ %d ⬇", dataUp, dataDown), 12))
|
||||
fmt.Fprintf(w, " └──────────────┴──────────────┴──────────────┘\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
10
internal/log/handlers/cli/util.go
Normal file
10
internal/log/handlers/cli/util.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func RightPad(str string, length int) string {
|
||||
return str + strings.Repeat(" ", length-utf8.RuneCountInString(str))
|
||||
}
|
|
@ -51,3 +51,28 @@ func ResultItem(result ResultItemData) {
|
|||
"total_count": result.TotalCount,
|
||||
}).Info("result item")
|
||||
}
|
||||
|
||||
type ResultSummaryData struct {
|
||||
TotalTests int64
|
||||
TotalDataUsageUp int64
|
||||
TotalDataUsageDown int64
|
||||
TotalNetworks int64
|
||||
}
|
||||
|
||||
func ResultSummary(result ResultSummaryData) {
|
||||
log.WithFields(log.Fields{
|
||||
"type": "result_summary",
|
||||
"total_tests": result.TotalTests,
|
||||
"total_data_usage_up": result.TotalDataUsageUp,
|
||||
"total_data_usage_down": result.TotalDataUsageDown,
|
||||
"total_networks": result.TotalNetworks,
|
||||
}).Info("result summary")
|
||||
}
|
||||
|
||||
// SectionTitle is the title of a section
|
||||
func SectionTitle(text string) {
|
||||
log.WithFields(log.Fields{
|
||||
"type": "section_title",
|
||||
"title": text,
|
||||
}).Info(text)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user