Skip to content

Commit a18fcd9

Browse files
committed
added test cases
Signed-off-by: Shashank <[email protected]>
1 parent 318890a commit a18fcd9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

pkg/storegateway/sharding_strategy.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ func NewDefaultShardingStrategy(r *ring.Ring, instanceAddr string, logger log.Lo
7171

7272
// FilterUsers implements ShardingStrategy.
7373
func (s *DefaultShardingStrategy) FilterUsers(_ context.Context, userIDs []string) []string {
74-
allUserIDs := userIDs
75-
74+
filteredUserIDs := []string{}
7675
for _, userID := range userIDs {
7776
if !s.allowedTenants.IsAllowed(userID) {
7877
level.Debug(s.logger).Log("msg", "ignoring storage gateway for user, not allowed", "user", userID)
78+
continue
7979
}
80+
81+
filteredUserIDs = append(filteredUserIDs, userID)
8082
}
8183

82-
return allUserIDs
84+
return filteredUserIDs
8385
}
8486

8587
// FilterBlocks implements ShardingStrategy.

pkg/storegateway/sharding_strategy_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func TestDefaultShardingStrategy(t *testing.T) {
4242
zoneAwarenessEnabled bool
4343
setupRing func(*ring.Desc)
4444
expectedBlocks map[string][]ulid.ULID
45+
enableTenants []string
46+
disableTenants []string
47+
allowedTenants func(*DefaultShardingStrategy)
4548
}{
4649
"one ACTIVE instance in the ring with replication factor = 1": {
4750
replicationFactor: 1,
@@ -64,6 +67,21 @@ func TestDefaultShardingStrategy(t *testing.T) {
6467
"127.0.0.2": {block2, block4},
6568
},
6669
},
70+
"two ACTIVE instances in the ring with replication factor = 1 and one tenant disabled": {
71+
replicationFactor: 1,
72+
setupRing: func(r *ring.Desc) {
73+
r.AddIngester("instance-1", "127.0.0.1", "", []uint32{block1Hash + 1, block3Hash + 1}, ring.ACTIVE, registeredAt)
74+
r.AddIngester("instance-2", "127.0.0.2", "", []uint32{block2Hash + 1, block4Hash + 1}, ring.ACTIVE, registeredAt)
75+
},
76+
allowedTenants: func(r *DefaultShardingStrategy) {
77+
enableTenants: []string{"u-1"}
78+
r.FilterUsers(context.Background(), enableTenants)
79+
},
80+
expectedBlocks: map[string][]ulid.ULID{
81+
"127.0.0.1": {block1, block3}, // Tenant 1 blocks expected
82+
"127.0.0.2": {}, // Tenant 2 blocks disabled
83+
},
84+
},
6785
"one ACTIVE instance in the ring with replication factor = 2": {
6886
replicationFactor: 2,
6987
setupRing: func(r *ring.Desc) {

0 commit comments

Comments
 (0)