Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 31b2ffa

Browse files
authored
Merge pull request #1068 from grafana/perPartitionIdxCat
add partition support to mt-index-cat
2 parents ff14f10 + bee5b03 commit 31b2ffa

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

cmd/mt-index-cat/main.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ func main() {
3232
var maxAge string
3333
var verbose bool
3434
var limit int
35+
var partitionStr string
3536

3637
globalFlags := flag.NewFlagSet("global config flags", flag.ExitOnError)
3738
globalFlags.StringVar(&addr, "addr", "http://localhost:6060", "graphite/metrictank address")
3839
globalFlags.StringVar(&prefix, "prefix", "", "only show metrics that have this prefix")
3940
globalFlags.StringVar(&substr, "substr", "", "only show metrics that have this substring")
4041
globalFlags.StringVar(&suffix, "suffix", "", "only show metrics that have this suffix")
42+
globalFlags.StringVar(&partitionStr, "partitions", "*", "only show metrics from the comma separated list of partitions or * for all")
4143
globalFlags.StringVar(&tags, "tags", "", "tag filter. empty (default), 'some', 'none', 'valid', or 'invalid'")
4244
globalFlags.StringVar(&from, "from", "30min", "for vegeta outputs, will generate requests for data starting from now minus... eg '30min', '5h', '14d', etc. or a unix timestamp")
4345
globalFlags.StringVar(&maxAge, "max-age", "6h30min", "max age (last update diff with now) of metricdefs. use 0 to disable")
@@ -93,6 +95,26 @@ func main() {
9395
os.Exit(-1)
9496
}
9597

98+
var partitions []int32
99+
if partitionStr != "*" {
100+
for _, p := range strings.Split(partitionStr, ",") {
101+
p = strings.TrimSpace(p)
102+
103+
// handle trailing "," on the list of partitions.
104+
if p == "" {
105+
continue
106+
}
107+
108+
id, err := strconv.ParseInt(p, 10, 32)
109+
if err != nil {
110+
log.Printf("invalid partition id %q. must be a int32", p)
111+
flag.Usage()
112+
os.Exit(-1)
113+
}
114+
partitions = append(partitions, int32(id))
115+
}
116+
}
117+
96118
format := os.Args[len(os.Args)-1]
97119
var found bool
98120
if strings.Contains(format, "{{") {
@@ -164,8 +186,12 @@ func main() {
164186
perror(err)
165187
cutoff = uint32(time.Now().Unix() - int64(maxAgeInt))
166188
}
167-
168-
defs := idx.Load(nil, cutoff)
189+
var defs []schema.MetricDefinition
190+
if len(partitions) == 0 {
191+
defs = idx.Load(nil, cutoff)
192+
} else {
193+
defs = idx.LoadPartitions(partitions, nil, cutoff)
194+
}
169195
// set this after doing the query, to assure age can't possibly be negative
170196
out.QueryTime = time.Now().Unix()
171197
total := len(defs)

docs/tools.md

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ global config flags:
6666
only show this many metrics. use 0 to disable
6767
-max-age string
6868
max age (last update diff with now) of metricdefs. use 0 to disable (default "6h30min")
69+
-partitions string
70+
only show metrics from the comma separated list of partitions or * for all (default "*")
6971
-prefix string
7072
only show metrics that have this prefix
7173
-substr string

0 commit comments

Comments
 (0)