Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only delete data when WholeStreamDeletion or FilterAndDelete #6286

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .github/workflows/snyk.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (d *DeleteRequestsManager) Expired(ref retention.ChunkEntry, _ model.Time)
return false, nil
}

if d.deletionMode == Disabled || d.deletionMode == FilterOnly {
// Don't process deletes
return false, nil
}

d.chunkIntervalsToRetain = d.chunkIntervalsToRetain[:0]
d.chunkIntervalsToRetain = append(d.chunkIntervalsToRetain, retention.IntervalFilter{
Interval: model.Interval{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {

for _, tc := range []struct {
name string
deletionMode Mode
deleteRequestsFromStore []DeleteRequest
expectedResp resp
}{
{
name: "no delete requests",
name: "no delete requests",
deletionMode: WholeStreamDeletion,
expectedResp: resp{
isExpired: false,
nonDeletedIntervals: nil,
},
},
{
name: "no relevant delete requests",
name: "no relevant delete requests",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: "different-user",
Expand All @@ -61,7 +64,8 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
},
},
{
name: "whole chunk deleted by single request",
name: "whole chunk deleted by single request",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Expand All @@ -76,7 +80,8 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
},
},
{
name: "deleted interval out of range",
name: "deleted interval out of range",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Expand All @@ -91,7 +96,8 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
},
},
{
name: "multiple delete requests with one deleting the whole chunk",
name: "multiple delete requests with one deleting the whole chunk",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Expand All @@ -112,7 +118,8 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
},
},
{
name: "multiple delete requests causing multiple holes",
name: "multiple delete requests causing multiple holes",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Expand Down Expand Up @@ -164,7 +171,8 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
},
},
{
name: "multiple overlapping requests deleting the whole chunk",
name: "multiple overlapping requests deleting the whole chunk",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Expand All @@ -185,7 +193,8 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
},
},
{
name: "multiple non-overlapping requests deleting the whole chunk",
name: "multiple non-overlapping requests deleting the whole chunk",
deletionMode: WholeStreamDeletion,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Expand All @@ -211,9 +220,77 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
nonDeletedIntervals: nil,
},
},
{
name: "deletes are disabled",
deletionMode: Disabled,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-13 * time.Hour),
EndTime: now.Add(-11 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-10 * time.Hour),
EndTime: now.Add(-8 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-6 * time.Hour),
EndTime: now.Add(-5 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-2 * time.Hour),
EndTime: now,
},
},
expectedResp: resp{
isExpired: false,
nonDeletedIntervals: nil,
},
},
{
name: "deletes are `filter-only`",
deletionMode: FilterOnly,
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-13 * time.Hour),
EndTime: now.Add(-11 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-10 * time.Hour),
EndTime: now.Add(-8 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-6 * time.Hour),
EndTime: now.Add(-5 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
StartTime: now.Add(-2 * time.Hour),
EndTime: now,
},
},
expectedResp: resp{
isExpired: false,
nonDeletedIntervals: nil,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
mgr := NewDeleteRequestsManager(mockDeleteRequestsStore{deleteRequests: tc.deleteRequestsFromStore}, time.Hour, nil, WholeStreamDeletion)
mgr := NewDeleteRequestsManager(mockDeleteRequestsStore{deleteRequests: tc.deleteRequestsFromStore}, time.Hour, nil, tc.deletionMode)
require.NoError(t, mgr.loadDeleteRequestsToProcess())

isExpired, nonDeletedIntervals := mgr.Expired(chunkEntry, model.Now())
Expand Down