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

Commit d215f5b

Browse files
committed
remove special case idx.List(-1)
there is never a need to list data across ALL orgs in one request
1 parent 7b798d3 commit d215f5b

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

idx/idx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type MetricIndex interface {
124124
// the timestamp.
125125
Find(int, string, int64) ([]Node, error)
126126

127-
// List returns all Archives for the passed OrgId, or for all organisations if -1 is provided.
127+
// List returns all Archives for the passed OrgId and the public orgId
128128
List(int) []Archive
129129

130130
// Prune deletes all metrics that haven't been seen since the given timestamp.

idx/memory/memory.go

+2-17
Original file line numberDiff line numberDiff line change
@@ -977,26 +977,11 @@ func (m *MemoryIdx) List(orgId int) []idx.Archive {
977977
m.RLock()
978978
defer m.RUnlock()
979979

980-
orgs := make(map[int]struct{})
981-
if orgId == -1 {
982-
log.Info("memory-idx: returning all metricDefs for all orgs")
983-
for org := range m.tree {
984-
orgs[org] = struct{}{}
985-
}
986-
for org := range m.tags {
987-
orgs[org] = struct{}{}
988-
}
989-
} else {
990-
orgs[-1] = struct{}{}
991-
orgs[orgId] = struct{}{}
992-
}
993-
994980
defs := make([]idx.Archive, 0)
995981
for _, def := range m.defById {
996-
if _, ok := orgs[def.OrgId]; !ok {
997-
continue
982+
if def.OrgId == orgId || def.OrgId == idx.OrgIdPublic {
983+
defs = append(defs, *def)
998984
}
999-
defs = append(defs, *def)
1000985
}
1001986

1002987
statListDuration.Value(time.Since(pre))

idx/memory/memory_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ func TestPruneTaggedSeries(t *testing.T) {
506506
}
507507

508508
Convey("after populating index", t, func() {
509-
defs := ix.List(-1)
509+
defs := ix.List(1)
510510
So(defs, ShouldHaveLength, 10)
511511
})
512512

@@ -523,7 +523,7 @@ func TestPruneTaggedSeries(t *testing.T) {
523523
})
524524

525525
Convey("after purge", t, func() {
526-
defs := ix.List(-1)
526+
defs := ix.List(1)
527527
So(defs, ShouldHaveLength, 5)
528528
data := &schema.MetricData{
529529
Name: defs[0].Name,
@@ -638,7 +638,7 @@ func testPrune(t *testing.T) {
638638
ix.AddOrUpdate(d, 1)
639639
}
640640
Convey("after populating index", t, func() {
641-
defs := ix.List(-1)
641+
defs := ix.List(1)
642642
So(defs, ShouldHaveLength, 10)
643643
})
644644
Convey("When purging old series", t, func() {
@@ -654,7 +654,7 @@ func testPrune(t *testing.T) {
654654

655655
})
656656
Convey("after purge", t, func() {
657-
defs := ix.List(-1)
657+
defs := ix.List(1)
658658
So(defs, ShouldHaveLength, 5)
659659
data := &schema.MetricData{
660660
Name: defs[0].Name,

0 commit comments

Comments
 (0)