Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This improves the log ouput for statistics in the logcli. #1644

Merged
merged 2 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pkg/logcli/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package query
import (
"fmt"
"log"
"os"
"sort"
"strings"
"text/tabwriter"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -168,14 +170,21 @@ func (q *Query) printVector(vector loghttp.Vector) {
fmt.Print(string(bytes))
}

func (q *Query) printStats(stats stats.Result) {
bytes, err := json.MarshalIndent(stats, "", " ")
type kvLogger struct {
*tabwriter.Writer
}

if err != nil {
log.Fatalf("Error marshalling stats: %v", err)
func (k kvLogger) Log(keyvals ...interface{}) error {
for i := 0; i < len(keyvals); i += 2 {
fmt.Fprintln(k.Writer, color.BlueString("%s", keyvals[i]), "\t", fmt.Sprintf("%v", keyvals[i+1]))
}
k.Flush()
return nil
}

fmt.Print(string(bytes))
func (q *Query) printStats(stats stats.Result) {
writer := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
stats.Summary.Log(kvLogger{Writer: writer})
}

func (q *Query) resultsDirection() logproto.Direction {
Expand Down
15 changes: 10 additions & 5 deletions pkg/logql/stats/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ func (r Result) Log(log log.Logger) {
"Store.DecompressedLines", r.Store.DecompressedLines,
"Store.CompressedBytes", humanize.Bytes(uint64(r.Store.CompressedBytes)),
"Store.TotalDuplicates", r.Store.TotalDuplicates,
)
r.Summary.Log(log)
}

"Summary.BytesProcessedPerSeconds", humanize.Bytes(uint64(r.Summary.BytesProcessedPerSeconds)),
"Summary.LinesProcessedPerSeconds", r.Summary.LinesProcessedPerSeconds,
"Summary.TotalBytesProcessed", humanize.Bytes(uint64(r.Summary.TotalBytesProcessed)),
"Summary.TotalLinesProcessed", r.Summary.TotalLinesProcessed,
"Summary.ExecTime", time.Duration(int64(r.Summary.ExecTime*float64(time.Second))),
func (s Summary) Log(log log.Logger) {
_ = log.Log(
"Summary.BytesProcessedPerSeconds", humanize.Bytes(uint64(s.BytesProcessedPerSeconds)),
"Summary.LinesProcessedPerSeconds", s.LinesProcessedPerSeconds,
"Summary.TotalBytesProcessed", humanize.Bytes(uint64(s.TotalBytesProcessed)),
"Summary.TotalLinesProcessed", s.TotalLinesProcessed,
"Summary.ExecTime", time.Duration(int64(s.ExecTime*float64(time.Second))),
)
}

Expand Down