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

mt-index-cat: add orgID filter #1942

Merged
merged 1 commit into from
Dec 4, 2020
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
9 changes: 8 additions & 1 deletion cmd/mt-index-cat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func main() {
var prefix string
var substr string
var suffix string
var orgFilter int
var regexStr string
var regex *regexp.Regexp
var tags string
Expand All @@ -55,6 +56,7 @@ func main() {
globalFlags.StringVar(&prefix, "prefix", "", "only show metrics that have this prefix")
globalFlags.StringVar(&substr, "substr", "", "only show metrics that have this substring")
globalFlags.StringVar(&suffix, "suffix", "", "only show metrics that have this suffix")
globalFlags.IntVar(&orgFilter, "org", -1, "show only metrics with this OrgID (-1 to disable)")
globalFlags.StringVar(&partitionStr, "partitions", "*", "only show metrics from the comma separated list of partitions or * for all")
globalFlags.IntVar(&btTotalPartitions, "bt-total-partitions", -1, "total number of partitions (when using bigtable and partitions='*')")
globalFlags.StringVar(&regexStr, "regex", "", "only show metrics that match this regex")
Expand Down Expand Up @@ -318,6 +320,11 @@ func main() {
if !strings.Contains(d.Name, substr) {
continue
}

if orgFilter != -1 && d.OrgId != uint32(orgFilter) {
continue
}

if tags == "none" && len(d.Tags) != 0 {
continue
}
Expand Down Expand Up @@ -364,7 +371,7 @@ func main() {
} else {
now := time.Now()
for _, p := range partitions {
defs = btIdx.LoadPartition(p, nil, now)
defs = btIdx.LoadPartition(p, nil, now, orgFilter)
// set this after doing the query, to assure age can't possibly be negative unless if clocks are misconfigured.
out.QueryTime = time.Now().Unix()
processDefs(defs)
Expand Down
2 changes: 2 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ global config flags:
exclude series that have not been seen for this much time (compared against LastUpdate). use 0 to disable (default "6h30min")
-min-stale string
exclude series that have been seen in this much time (compared against LastUpdate). use 0 to disable (default "0")
-org int
show only metrics with this OrgID (-1 to disable) (default -1)
-partitions string
only show metrics from the comma separated list of partitions or * for all (default "*")
-prefix string
Expand Down
7 changes: 5 additions & 2 deletions idx/bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ func (b *BigtableIdx) rebuildIndex() {
num := 0
var defs []schema.MetricDefinition
for _, partition := range cluster.Manager.GetPartitions() {
defs = b.LoadPartition(partition, defs[:0], pre)
defs = b.LoadPartition(partition, defs[:0], pre, -1)
num += b.MemoryIndex.LoadPartition(partition, defs)
}

log.Infof("bigtable-idx: Rebuilding Memory Index Complete. Imported %d. Took %s", num, time.Since(pre))
}

func (b *BigtableIdx) LoadPartition(partition int32, defs []schema.MetricDefinition, now time.Time) []schema.MetricDefinition {
func (b *BigtableIdx) LoadPartition(partition int32, defs []schema.MetricDefinition, now time.Time, orgFilter int) []schema.MetricDefinition {
ctx := context.Background()
rr := bigtable.PrefixRange(fmt.Sprintf("%d_", partition))
defsByNames := make(map[string][]schema.MetricDefinition)
Expand All @@ -296,6 +296,9 @@ func (b *BigtableIdx) LoadPartition(partition int32, defs []schema.MetricDefinit
if marshalErr != nil {
return false
}
if orgFilter != -1 && def.OrgId != uint32(orgFilter) {
return true
}
log.Debugf("bigtable-idx: found def %+v", def)
nameWithTags := def.NameWithTags()
defsByNames[nameWithTags] = append(defsByNames[nameWithTags], def)
Expand Down