Skip to content

Commit

Permalink
feat(inspect): Add report-disk for disk usage by measurement (#20917)
Browse files Browse the repository at this point in the history
* feat(inspect): Add report-disk for disk usage by measurement

(cherry picked from commit a6152e8)

* fix(inspect): bad pattern matching

(cherry picked from commit 3a31e23)

* chore: fix goimports

* chore: update changelog
  • Loading branch information
lesam authored Mar 11, 2021
1 parent 8a31b0e commit e95a6a4
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 90 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ v1.8.5 [unreleased]

### Features

- [#20917](https://github.com/influxdata/influxdb/pull/20917): feat(inspect): Add report-disk for disk usage by measurement
- [#20118](https://github.com/influxdata/influxdb/pull/20118): feat: Optimize shard lookups in groups containing only one shard. Thanks @StoneYunZhao!
- [#20910](https://github.com/influxdata/influxdb/pull/20910): feat: Make meta queries respect QueryTimeout values

Expand Down
6 changes: 6 additions & 0 deletions cmd/influx_inspect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/influxdata/influxdb/cmd/influx_inspect/export"
"github.com/influxdata/influxdb/cmd/influx_inspect/help"
"github.com/influxdata/influxdb/cmd/influx_inspect/report"
"github.com/influxdata/influxdb/cmd/influx_inspect/reportdisk"
"github.com/influxdata/influxdb/cmd/influx_inspect/reporttsi"
"github.com/influxdata/influxdb/cmd/influx_inspect/verify/seriesfile"
"github.com/influxdata/influxdb/cmd/influx_inspect/verify/tombstone"
Expand Down Expand Up @@ -98,6 +99,11 @@ func (m *Main) Run(args ...string) error {
if err := name.Run(args...); err != nil {
return fmt.Errorf("report: %s", err)
}
case "report-disk":
name := reportdisk.NewCommand()
if err := name.Run(args...); err != nil {
return fmt.Errorf("report: %s", err)
}
case "reporttsi":
name := reporttsi.NewCommand()
if err := name.Run(args...); err != nil {
Expand Down
65 changes: 4 additions & 61 deletions cmd/influx_inspect/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/pkg/reporthelper"
"github.com/influxdata/influxdb/tsdb/engine/tsm1"
"github.com/retailnext/hllpp"
)
Expand Down Expand Up @@ -60,7 +61,7 @@ func (cmd *Command) Run(args ...string) error {

cmd.dir = fs.Arg(0)

err := cmd.isShardDir(cmd.dir)
err := reporthelper.IsShardDir(cmd.dir)
if cmd.detailed && err != nil {
return fmt.Errorf("-detailed only supported for shard dirs")
}
Expand All @@ -79,8 +80,8 @@ func (cmd *Command) Run(args ...string) error {

minTime, maxTime := int64(math.MaxInt64), int64(math.MinInt64)
var fileCount int
if err := cmd.walkShardDirs(cmd.dir, func(db, rp, id, path string) error {
if cmd.pattern != "" && strings.Contains(path, cmd.pattern) {
if err := reporthelper.WalkShardDirs(cmd.dir, func(db, rp, id, path string) error {
if cmd.pattern != "" && !strings.Contains(path, cmd.pattern) {
return nil
}

Expand Down Expand Up @@ -218,64 +219,6 @@ func sortKeys(vals map[string]counter) (keys []string) {
return keys
}

func (cmd *Command) isShardDir(dir string) error {
name := filepath.Base(dir)
if id, err := strconv.Atoi(name); err != nil || id < 1 {
return fmt.Errorf("not a valid shard dir: %v", dir)
}

return nil
}

func (cmd *Command) walkShardDirs(root string, fn func(db, rp, id, path string) error) error {
type location struct {
db, rp, id, path string
}

var dirs []location
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

if filepath.Ext(info.Name()) == "."+tsm1.TSMFileExtension {
shardDir := filepath.Dir(path)

if err := cmd.isShardDir(shardDir); err != nil {
return err
}
absPath, err := filepath.Abs(path)
if err != nil {
return err
}
parts := strings.Split(absPath, string(filepath.Separator))
db, rp, id := parts[len(parts)-4], parts[len(parts)-3], parts[len(parts)-2]
dirs = append(dirs, location{db: db, rp: rp, id: id, path: path})
return nil
}
return nil
}); err != nil {
return err
}

sort.Slice(dirs, func(i, j int) bool {
a, _ := strconv.Atoi(dirs[i].id)
b, _ := strconv.Atoi(dirs[j].id)
return a < b
})

for _, shard := range dirs {
if err := fn(shard.db, shard.rp, shard.id, shard.path); err != nil {
return err
}
}
return nil
}

// printUsage prints the usage message to STDERR.
func (cmd *Command) printUsage() {
usage := `Displays shard level report.
Expand Down
Loading

0 comments on commit e95a6a4

Please sign in to comment.