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

mt-index-cat tags valid filter #817

Merged
merged 4 commits into from
Jan 11, 2018
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
47 changes: 40 additions & 7 deletions cmd/mt-index-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
var addr string
var prefix string
var substr string
var tags string
var from string
var maxAge string
var verbose bool
Expand All @@ -35,6 +36,7 @@ func main() {
globalFlags.StringVar(&addr, "addr", "http://localhost:6060", "graphite/metrictank address")
globalFlags.StringVar(&prefix, "prefix", "", "only show metrics that have this prefix")
globalFlags.StringVar(&substr, "substr", "", "only show metrics that have this substring")
globalFlags.StringVar(&tags, "tags", "", "tag filter. empty (default), 'some', 'none', 'valid', or 'invalid'")
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")
globalFlags.StringVar(&maxAge, "max-age", "6h30min", "max age (last update diff with now) of metricdefs. use 0 to disable")
globalFlags.IntVar(&limit, "limit", 0, "only show this many metrics. use 0 to disable")
Expand All @@ -55,6 +57,13 @@ func main() {
fmt.Printf("global config flags:\n\n")
globalFlags.PrintDefaults()
fmt.Println()
fmt.Println("tags filter:")
fmt.Println(" '' no filtering based on tags")
fmt.Println(" 'none' only show metrics that have no tags")
fmt.Println(" 'some' only show metrics that have one or more tags")
fmt.Println(" 'valid' only show metrics whose tags (if any) are valid")
fmt.Println(" 'invalid' only show metrics that have one or more invalid tags")
fmt.Println()
fmt.Printf("idxtype: only 'cass' supported for now\n\n")
fmt.Printf("cass config flags:\n\n")
cassFlags.PrintDefaults()
Expand Down Expand Up @@ -111,6 +120,12 @@ func main() {
os.Exit(1)
}

if tags != "" && tags != "valid" && tags != "invalid" && tags != "some" && tags != "none" {
log.Println("invalid tags filter")
flag.Usage()
os.Exit(1)
}

globalFlags.Parse(os.Args[1:cassI])
cassFlags.Parse(os.Args[cassI+1 : len(os.Args)-1])
cassandra.Enabled = true
Expand Down Expand Up @@ -155,15 +170,33 @@ func main() {
shown := 0

for _, d := range defs {
if prefix == "" || strings.HasPrefix(d.Metric, prefix) {
if substr == "" || strings.Contains(d.Metric, substr) {
show(d)
shown += 1
if shown == limit {
break
}
// note that prefix and substr can be "", meaning filter disabled.
// the conditions handle this fine as well.
if !strings.HasPrefix(d.Metric, prefix) {
continue
}
if !strings.Contains(d.Metric, substr) {
continue
}
if tags == "none" && len(d.Tags) != 0 {
continue
}
if tags == "some" && len(d.Tags) == 0 {
continue
}
if tags == "valid" || tags == "invalid" {
valid := schema.ValidateTags(d.Tags)

// skip the metric if the validation result is not what we want
if valid != (tags == "valid") {
continue
}
}
show(d)
shown += 1
if shown == limit {
break
}
}

if verbose {
Expand Down
9 changes: 9 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,18 @@ global config flags:
only show metrics that have this prefix
-substr string
only show metrics that have this substring
-tags string
tag filter. empty (default), 'some', 'none', 'valid', or 'invalid'
-verbose
print stats to stderr

tags filter:
'' no filtering based on tags
'none' only show metrics that have no tags
'some' only show metrics that have one or more tags
'valid' only show metrics whose tags (if any) are valid
'invalid' only show metrics that have one or more invalid tags

idxtype: only 'cass' supported for now

cass config flags:
Expand Down
23 changes: 10 additions & 13 deletions vendor/gopkg.in/raintank/schema.v1/metric.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.