-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid making delete requests if deletes are disabled for a user (#6583)
- Loading branch information
1 parent
1c8ebaf
commit a92e048
Showing
3 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
pkg/storage/stores/shipper/compactor/deletion/tenant_delete_requests_client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package deletion | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/grafana/loki/pkg/storage/stores/shipper/compactor/retention" | ||
) | ||
|
||
type perTenantDeleteRequestsClient struct { | ||
client DeleteRequestsClient | ||
limits retention.Limits | ||
} | ||
|
||
func NewPerTenantDeleteRequestsClient(c DeleteRequestsClient, l retention.Limits) DeleteRequestsClient { | ||
return &perTenantDeleteRequestsClient{ | ||
client: c, | ||
limits: l, | ||
} | ||
} | ||
|
||
func (c *perTenantDeleteRequestsClient) GetAllDeleteRequestsForUser(ctx context.Context, userID string) ([]DeleteRequest, error) { | ||
allLimits := c.limits.AllByUserID() | ||
userLimits, ok := allLimits[userID] | ||
if ok && userLimits.CompactorDeletionEnabled || c.limits.DefaultLimits().CompactorDeletionEnabled { | ||
return c.client.GetAllDeleteRequestsForUser(ctx, userID) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (c *perTenantDeleteRequestsClient) Stop() { | ||
c.client.Stop() | ||
} |
62 changes: 62 additions & 0 deletions
62
pkg/storage/stores/shipper/compactor/deletion/tenant_delete_requests_client_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package deletion | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTenantDeleteRequestsClient(t *testing.T) { | ||
fakeClient := &fakeRequestsClient{ | ||
reqs: []DeleteRequest{{ | ||
RequestID: "test-request", | ||
}}, | ||
} | ||
perTenantClient := NewPerTenantDeleteRequestsClient(fakeClient, limits) | ||
|
||
t.Run("tenant enabled", func(t *testing.T) { | ||
reqs, err := perTenantClient.GetAllDeleteRequestsForUser(context.Background(), "1") | ||
require.Nil(t, err) | ||
require.Equal(t, []DeleteRequest{{RequestID: "test-request"}}, reqs) | ||
}) | ||
|
||
t.Run("tenant disabled", func(t *testing.T) { | ||
reqs, err := perTenantClient.GetAllDeleteRequestsForUser(context.Background(), "2") | ||
require.Nil(t, err) | ||
require.Empty(t, reqs) | ||
}) | ||
|
||
t.Run("default is enabled", func(t *testing.T) { | ||
limits.defaultLimit.compactorDeletionEnabled = true | ||
reqs, err := perTenantClient.GetAllDeleteRequestsForUser(context.Background(), "3") | ||
require.Nil(t, err) | ||
require.Equal(t, []DeleteRequest{{RequestID: "test-request"}}, reqs) | ||
}) | ||
|
||
t.Run("default is disabled", func(t *testing.T) { | ||
limits.defaultLimit.compactorDeletionEnabled = false | ||
reqs, err := perTenantClient.GetAllDeleteRequestsForUser(context.Background(), "3") | ||
require.Nil(t, err) | ||
require.Empty(t, reqs) | ||
}) | ||
} | ||
|
||
type fakeRequestsClient struct { | ||
DeleteRequestsClient | ||
|
||
reqs []DeleteRequest | ||
} | ||
|
||
func (c *fakeRequestsClient) GetAllDeleteRequestsForUser(_ context.Context, userID string) ([]DeleteRequest, error) { | ||
return c.reqs, nil | ||
} | ||
|
||
var ( | ||
limits = &fakeLimits{ | ||
perTenant: map[string]retentionLimit{ | ||
"1": {compactorDeletionEnabled: true}, | ||
"2": {compactorDeletionEnabled: false}, | ||
}, | ||
} | ||
) |