Merge pull request #8373 from sebito91/influx_inspect_sort_tags

sort influx_inspect detailed report results
pull/8381/head
Jason Wilder 2017-05-10 12:24:49 -06:00 committed by GitHub
commit 76428d168c
1 changed files with 27 additions and 15 deletions

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strconv" "strconv"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
@ -67,14 +68,14 @@ func (cmd *Command) Run(args ...string) error {
} }
if len(files) == 0 { if len(files) == 0 {
return fmt.Errorf("no tsm files at %v\n", cmd.dir) return fmt.Errorf("no tsm files at %v", cmd.dir)
} }
tw := tabwriter.NewWriter(cmd.Stdout, 8, 8, 1, '\t', 0) tw := tabwriter.NewWriter(cmd.Stdout, 8, 8, 1, '\t', 0)
fmt.Fprintln(tw, strings.Join([]string{"File", "Series", "Load Time"}, "\t")) fmt.Fprintln(tw, strings.Join([]string{"File", "Series", "Load Time"}, "\t"))
totalSeries := hllpp.New() totalSeries := hllpp.New()
tagCardialities := map[string]*hllpp.HLLPP{} tagCardinalities := map[string]*hllpp.HLLPP{}
measCardinalities := map[string]*hllpp.HLLPP{} measCardinalities := map[string]*hllpp.HLLPP{}
fieldCardinalities := map[string]*hllpp.HLLPP{} fieldCardinalities := map[string]*hllpp.HLLPP{}
@ -118,10 +119,10 @@ func (cmd *Command) Run(args ...string) error {
fieldCount.Add([]byte(field)) fieldCount.Add([]byte(field))
for _, t := range tags { for _, t := range tags {
tagCount, ok := tagCardialities[string(t.Key)] tagCount, ok := tagCardinalities[string(t.Key)]
if !ok { if !ok {
tagCount = hllpp.New() tagCount = hllpp.New()
tagCardialities[string(t.Key)] = tagCount tagCardinalities[string(t.Key)] = tagCount
} }
tagCount.Add(t.Value) tagCount.Add(t.Value)
} }
@ -140,22 +141,23 @@ func (cmd *Command) Run(args ...string) error {
tw.Flush() tw.Flush()
println() println()
fmt.Printf("Statistics\n") fmt.Printf("Statistics\n")
fmt.Printf(" Series:\n") fmt.Printf("\tSeries:\n")
fmt.Printf(" Total (est): %d\n", totalSeries.Count()) fmt.Printf("\t\tTotal (est): %d\n", totalSeries.Count())
if cmd.detailed { if cmd.detailed {
fmt.Printf(" Measurements (est):\n") fmt.Printf("\tMeasurements (est):\n")
for t, card := range measCardinalities { for _, t := range sortKeys(measCardinalities) {
fmt.Printf(" %v: %d (%d%%)\n", t, card.Count(), int((float64(card.Count())/float64(totalSeries.Count()))*100)) fmt.Printf("\t\t%v: %d (%d%%)\n", t, measCardinalities[t].Count(), int((float64(measCardinalities[t].Count())/float64(totalSeries.Count()))*100))
} }
fmt.Printf(" Fields (est):\n") fmt.Printf("\tFields (est):\n")
for t, card := range fieldCardinalities { for _, t := range sortKeys(fieldCardinalities) {
fmt.Printf(" %v: %d\n", t, card.Count()) fmt.Printf("\t\t%v: %d\n", t, fieldCardinalities[t].Count())
} }
fmt.Printf(" Tags (est):\n") fmt.Printf("\tTags (est):\n")
for t, card := range tagCardialities { for _, t := range sortKeys(tagCardinalities) {
fmt.Printf(" %v: %d\n", t, card.Count()) fmt.Printf("\t\t%v: %d\n", t, tagCardinalities[t].Count())
} }
} }
@ -163,6 +165,16 @@ func (cmd *Command) Run(args ...string) error {
return nil return nil
} }
// sortKeys is a quick helper to return the sorted set of a map's keys
func sortKeys(vals map[string]*hllpp.HLLPP) (keys []string) {
for k := range vals {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
// printUsage prints the usage message to STDERR. // printUsage prints the usage message to STDERR.
func (cmd *Command) printUsage() { func (cmd *Command) printUsage() {
usage := `Displays shard level report. usage := `Displays shard level report.