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

Commit

Permalink
Merge pull request #1942 from grafana/orgid-filter
Browse files Browse the repository at this point in the history
mt-index-cat: add orgID filter
  • Loading branch information
Dieterbe authored Dec 4, 2020
2 parents a474a9e + 0e8999b commit d82e79c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit d82e79c

Please sign in to comment.