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

Commit 0e8999b

Browse files
committed
mt-index-cat: add orgID filter
note: store level filtering only implemented for bigtable for now, which means for cassandra it's naive (fetch all data, then filter)
1 parent c0edf6f commit 0e8999b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

cmd/mt-index-cat/main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func main() {
3939
var prefix string
4040
var substr string
4141
var suffix string
42+
var orgFilter int
4243
var regexStr string
4344
var regex *regexp.Regexp
4445
var tags string
@@ -55,6 +56,7 @@ func main() {
5556
globalFlags.StringVar(&prefix, "prefix", "", "only show metrics that have this prefix")
5657
globalFlags.StringVar(&substr, "substr", "", "only show metrics that have this substring")
5758
globalFlags.StringVar(&suffix, "suffix", "", "only show metrics that have this suffix")
59+
globalFlags.IntVar(&orgFilter, "org", -1, "show only metrics with this OrgID (-1 to disable)")
5860
globalFlags.StringVar(&partitionStr, "partitions", "*", "only show metrics from the comma separated list of partitions or * for all")
5961
globalFlags.IntVar(&btTotalPartitions, "bt-total-partitions", -1, "total number of partitions (when using bigtable and partitions='*')")
6062
globalFlags.StringVar(&regexStr, "regex", "", "only show metrics that match this regex")
@@ -318,6 +320,11 @@ func main() {
318320
if !strings.Contains(d.Name, substr) {
319321
continue
320322
}
323+
324+
if orgFilter != -1 && d.OrgId != uint32(orgFilter) {
325+
continue
326+
}
327+
321328
if tags == "none" && len(d.Tags) != 0 {
322329
continue
323330
}
@@ -364,7 +371,7 @@ func main() {
364371
} else {
365372
now := time.Now()
366373
for _, p := range partitions {
367-
defs = btIdx.LoadPartition(p, nil, now)
374+
defs = btIdx.LoadPartition(p, nil, now, orgFilter)
368375
// set this after doing the query, to assure age can't possibly be negative unless if clocks are misconfigured.
369376
out.QueryTime = time.Now().Unix()
370377
processDefs(defs)

docs/tools.md

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ global config flags:
201201
exclude series that have not been seen for this much time (compared against LastUpdate). use 0 to disable (default "6h30min")
202202
-min-stale string
203203
exclude series that have been seen in this much time (compared against LastUpdate). use 0 to disable (default "0")
204+
-org int
205+
show only metrics with this OrgID (-1 to disable) (default -1)
204206
-partitions string
205207
only show metrics from the comma separated list of partitions or * for all (default "*")
206208
-prefix string

idx/bigtable/bigtable.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ func (b *BigtableIdx) rebuildIndex() {
278278
num := 0
279279
var defs []schema.MetricDefinition
280280
for _, partition := range cluster.Manager.GetPartitions() {
281-
defs = b.LoadPartition(partition, defs[:0], pre)
281+
defs = b.LoadPartition(partition, defs[:0], pre, -1)
282282
num += b.MemoryIndex.LoadPartition(partition, defs)
283283
}
284284

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

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

0 commit comments

Comments
 (0)