This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
blocks.go
76 lines (65 loc) 路 2.28 KB
/
blocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"github.com/dustin/go-humanize"
"github.com/go-kit/log/level"
"github.com/olekukonko/tablewriter"
"github.com/grafana/phlare/pkg/objstore/providers/filesystem"
"github.com/grafana/phlare/pkg/phlaredb"
"github.com/grafana/phlare/pkg/phlaredb/block"
)
func fileInfo(f *block.File) string {
if f != nil && f.Parquet != nil {
return fmt.Sprintf("%d (%s in %d RGs)", f.Parquet.NumRows, humanize.Bytes(f.SizeBytes), f.Parquet.NumRowGroups)
}
if f != nil && f.TSDB != nil {
return fmt.Sprintf("%d series", f.TSDB.NumSeries)
}
return ""
}
func blocksList(ctx context.Context) error {
bucket, err := filesystem.NewBucket(cfg.blocks.path)
if err != nil {
return err
}
metas, err := phlaredb.NewBlockQuerier(ctx, bucket).BlockMetas(ctx)
if err != nil {
return err
}
table := tablewriter.NewWriter(output(ctx))
table.SetHeader([]string{"Block ID", "MinTime", "MaxTime", "Duration", "Index", "Profiles", "Stacktraces", "Locations", "Functions", "Strings"})
for _, blockInfo := range metas {
table.Append([]string{
blockInfo.ULID.String(),
blockInfo.MinTime.Time().Format(time.RFC3339),
blockInfo.MaxTime.Time().Format(time.RFC3339),
blockInfo.MaxTime.Time().Sub(blockInfo.MinTime.Time()).String(),
fileInfo(blockInfo.FileByRelPath("index.tsdb")),
fileInfo(blockInfo.FileByRelPath("profiles.parquet")),
fileInfo(blockInfo.FileByRelPath("stacktraces.parquet")),
fileInfo(blockInfo.FileByRelPath("locations.parquet")),
fileInfo(blockInfo.FileByRelPath("functions.parquet")),
fileInfo(blockInfo.FileByRelPath("strings.parquet")),
})
if cfg.blocks.restoreMissingMeta {
blockPath := filepath.Join(cfg.blocks.path, blockInfo.ULID.String())
blockMetaPath := filepath.Join(blockPath, block.MetaFilename)
if _, err := os.Stat(blockMetaPath); err == nil {
continue
} else if !os.IsNotExist(err) {
level.Error(logger).Log("msg", "unable to check for existing "+block.MetaFilename+" file", "path", blockMetaPath, "err", err)
continue
}
if _, err := blockInfo.WriteToFile(logger, blockPath); err != nil {
level.Error(logger).Log("msg", "unable to write regenerated "+block.MetaFilename, "path", blockMetaPath, "err", err)
continue
}
}
}
table.Render()
return nil
}