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

Add a DeletionMode config variable #5481

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
929cbbe
Add deletionEnabled setting and remove delete request manager
MichelHollands Feb 25, 2022
42bfebf
Rebase
MichelHollands Feb 25, 2022
a6ed435
Remove deletion handling from delete requests manager
MichelHollands Feb 25, 2022
3ce76d6
change store so it stores a logql statement
MichelHollands Feb 25, 2022
bb2b3eb
Add validation code for logql statement
MichelHollands Feb 25, 2022
9397b50
Run deleteRequestsManager when deletion is enabled
MichelHollands Feb 25, 2022
6f676aa
Remove unused variables
MichelHollands Feb 25, 2022
e1afcc3
Revert "Remove deletion handling from delete requests manager"
MichelHollands Mar 1, 2022
f6eb37e
Re-add IsDeleted method
MichelHollands Mar 1, 2022
0fbdbe1
Re-add tests for IsDeleted
MichelHollands Mar 1, 2022
5495668
Fix delete request store test
MichelHollands Mar 1, 2022
027adfd
Fix linting issue
MichelHollands Mar 1, 2022
587f6d2
Revert compactor changes
MichelHollands Mar 1, 2022
b10e121
Add deletion mode
MichelHollands Mar 1, 2022
b90811a
Add v1 mode
MichelHollands Mar 1, 2022
6a7ca3a
Rename LogQLRequest to Query
MichelHollands Mar 1, 2022
815c617
Fix linting issues
MichelHollands Mar 1, 2022
a9b8f73
Use DeleteMode in compactor module
MichelHollands Mar 1, 2022
65504d0
Rename logql to query
MichelHollands Mar 1, 2022
e75c36b
Put cancel under delete verb
MichelHollands Mar 2, 2022
1a5069b
Update documentation
MichelHollands Mar 2, 2022
dc4ab08
Update changelog
MichelHollands Mar 2, 2022
b00482c
Revert only the API surface area while keeping everything else
MasslessParticle Mar 11, 2022
38d819f
Use moved code in syntax package
MichelHollands Mar 15, 2022
3ae0aea
Remove duplicte import
MichelHollands Mar 15, 2022
b6b4734
Use renamed field in tests
MichelHollands Mar 15, 2022
beddf81
Remove duplicates and empty lines in changelog
MichelHollands Mar 15, 2022
e3dbe38
Update changelog description
MichelHollands Mar 15, 2022
1ba285a
Update pkg/storage/stores/shipper/compactor/deletion/delete_request.go
MichelHollands Mar 17, 2022
8152916
Update pkg/storage/stores/shipper/compactor/deletion/delete_requests_…
MichelHollands Mar 17, 2022
eb46a59
Update pkg/storage/stores/shipper/compactor/deletion/delete_requests_…
MichelHollands Mar 17, 2022
197e08b
Update pkg/storage/stores/shipper/compactor/deletion/delete_requests_…
MichelHollands Mar 17, 2022
ff27a1b
Update CHANGELOG.md
MichelHollands Mar 17, 2022
d249f18
Update pkg/storage/stores/shipper/compactor/deletion/delete_requests_…
MichelHollands Mar 17, 2022
0b35252
Make DeletionMode struct member non public
MichelHollands Mar 17, 2022
0b49512
Revert change to docs re cancellation
MichelHollands Mar 17, 2022
1db21ca
Use same variable names
MichelHollands Mar 17, 2022
92aa117
Add parameter validation to changelog
MichelHollands Mar 17, 2022
a574d62
Rename v1 to WholeStreamDeletion
MichelHollands Mar 17, 2022
8098e1b
Fix default value of deletion mode config setting
MichelHollands Mar 18, 2022
86a2a53
reimplement new api
MasslessParticle Mar 18, 2022
16e9ab2
Add delete request handler when delete mode is set
MichelHollands Apr 4, 2022
9bec8a1
Remove unused variable
MichelHollands Apr 4, 2022
a10466b
Add comment to change the code when other deletion modes are available
MichelHollands Apr 5, 2022
f9addc8
create expirationChecker if deletionMode is set
MichelHollands Apr 5, 2022
85a32ea
Address review comments
MichelHollands Apr 6, 2022
a12b157
Update pkg/storage/stores/shipper/compactor/compactor.go
MichelHollands Apr 6, 2022
9d6dc0d
Rename AddQuery to SetQuery
MichelHollands Apr 6, 2022
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
Prev Previous commit
Next Next commit
Revert only the API surface area while keeping everything else
  • Loading branch information
MasslessParticle authored and MichelHollands committed Apr 6, 2022
commit b00482c014211281f3386a82b8d8658584eefefa
25 changes: 12 additions & 13 deletions docs/sources/operations/storage/logs-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ The Compactor exposes endpoints to allow for the deletion of log entries from sp
### Request log entry deletion

```
POST /loki/api/v1/delete
PUT /loki/api/v1/delete
POST /loki/api/admin/delete
PUT /loki/api/admin/delete
```

Query parameters:

* `query=<series_selector>`: A label matcher argument that identifies the streams from which to delete. This argument must be provided.
* `match[]=<series_selector>`: Repeated label matcher argument that identifies the streams from which to delete. At least one `match[]` argument must be provided.
* `start=<rfc3339 | unix_timestamp>`: A timestamp that identifies the start of the time window within which entries will be deleted. If not specified, defaults to 0, the Unix Epoch time.
* `end=<rfc3339 | unix_timestamp>`: A timestamp that identifies the end of the time window within which entries will be deleted. If not specified, defaults to the current time.

A 204 response indicates success.

URL encode the `query` parameter. This sample form of a cURL command URL encodes `query={foo="bar"}`:
URL encode the `match[]` parameter. This sample form of a cURL command URL encodes `match[]={foo="bar"}`:

```
curl -g -X POST \
'http://127.0.0.1:3100/loki/api/v1/delete?query={foo="bar"}&start=1591616227&end=1591619692' \
'http://127.0.0.1:3100/loki/api/admin/delete?match[]={foo="bar"}&start=1591616227&end=1591619692' \
-H 'x-scope-orgid: 1'
```

Expand All @@ -53,39 +53,38 @@ curl -g -X POST \
List the existing delete requests using the following API:

```
GET /loki/api/v1/delete
GET /loki/api/admin/delete
```

Sample form of a cURL command:

```
curl -X GET \
<compactor_addr>/loki/api/v1/delete \
<compactor_addr>/loki/api/admin/delete \
-H 'x-scope-orgid: <orgid>'
```

This endpoint returns both processed and unprocessed requests. It does not list canceled requests, as those requests will have been removed from storage.

### Request cancellation of a delete request

Loki allows cancellation of delete requests until the requests are picked up for processing. It is controlled by the `delete_request_cancel_period` YAML configuration or the equivalent command line option when invoking Loki.

Cancel a delete request using this Compactor endpoint:

```
DELETE /loki/api/v1/delete
POST /loki/api/admin/cancel_delete_request
PUT /loki/api/admin/cancel_delete_request
```

Query parameters:

* `request_id=<request_id>`: Identifies the delete request to cancel; IDs are found using the GET method on this endpoint.
* `request_id=<request_id>`: Identifies the delete request to cancel; IDs are found using the `delete` endpoint.

A 204 response indicates success.

Sample form of a cURL command:

```
curl -X DELETE \
'<compactor_addr>/loki/api/v1/delete?request_id=<request_id>' \
curl -X POST \
'<compactor_addr>/loki/api/admin/cancel_delete_request?request_id=<request_id>' \
-H 'x-scope-orgid: <tenant-id>'
```
6 changes: 3 additions & 3 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,9 @@ func (t *Loki) initCompactor() (services.Service, error) {
t.Server.HTTP.Path("/compactor/ring").Methods("GET", "POST").Handler(t.compactor)

if t.Cfg.CompactorConfig.RetentionEnabled && t.compactor.DeleteMode == deletion.V1 {
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("PUT", "POST").Handler(t.HTTPAuthMiddleware.Wrap(http.HandlerFunc(t.compactor.DeleteRequestsHandler.AddDeleteRequestHandler)))
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("GET").Handler(t.HTTPAuthMiddleware.Wrap(http.HandlerFunc(t.compactor.DeleteRequestsHandler.GetAllDeleteRequestsHandler)))
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("DELETE").Handler(t.HTTPAuthMiddleware.Wrap(http.HandlerFunc(t.compactor.DeleteRequestsHandler.CancelDeleteRequestHandler)))
t.Server.HTTP.Path("/loki/api/admin/delete").Methods("PUT", "POST").Handler(t.HTTPAuthMiddleware.Wrap(http.HandlerFunc(t.compactor.DeleteRequestsHandler.AddDeleteRequestHandler)))
t.Server.HTTP.Path("/loki/api/admin/delete").Methods("GET").Handler(t.HTTPAuthMiddleware.Wrap(http.HandlerFunc(t.compactor.DeleteRequestsHandler.GetAllDeleteRequestsHandler)))
t.Server.HTTP.Path("/loki/api/admin/cancel_delete_request").Methods("PUT", "POST").Handler(t.HTTPAuthMiddleware.Wrap(http.HandlerFunc(t.compactor.DeleteRequestsHandler.CancelDeleteRequestHandler)))
}

return t.compactor, nil
Expand Down
18 changes: 11 additions & 7 deletions pkg/storage/stores/shipper/compactor/deletion/delete_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ type DeleteRequest struct {
RequestID string `json:"request_id"`
StartTime model.Time `json:"start_time"`
EndTime model.Time `json:"end_time"`
Query string `json:"logql_requests"`
Queries []string `json:"logql_requests"`
Status DeleteRequestStatus `json:"status"`
CreatedAt model.Time `json:"created_at"`

UserID string `json:"-"`
matchers []*labels.Matcher `json:"-"`
}

func (d *DeleteRequest) AddQuery(logQL string) error {
d.Query = logQL
matchers, err := parseDeletionQuery(logQL)
if err != nil {
return err
func (d *DeleteRequest) AddQueries(queries []string) error {
d.Queries = queries
for _, query := range queries {
matchers, err := parseDeletionQuery(query)
if err != nil {
return err
}

d.matchers = append(d.matchers, matchers...)
}
d.matchers = matchers

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
now := model.Now()
user1 := "user1"

lbls := `{foo="bar", fizz="buzz"}`
lbls := []string{`{foo="bar", fizz="buzz"}`}

chunkEntry := retention.ChunkEntry{
ChunkRef: retention.ChunkRef{
UserID: []byte(user1),
From: now.Add(-3 * time.Hour),
Through: now.Add(-time.Hour),
},
Labels: mustParseLabel(lbls),
Labels: mustParseLabel(lbls[0]),
}

type resp struct {
Expand All @@ -43,7 +43,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: user1,
StartTime: now.Add(-3 * time.Hour),
EndTime: now.Add(-time.Hour),
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: true,
Expand All @@ -56,7 +56,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: user1,
StartTime: now.Add(-3 * time.Hour),
EndTime: now.Add(-2 * time.Hour),
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: true,
Expand All @@ -74,7 +74,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: user1,
StartTime: now.Add(-2 * time.Hour),
EndTime: now,
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: true,
Expand All @@ -92,7 +92,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: user1,
StartTime: now.Add(-2 * time.Hour),
EndTime: now,
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: true,
Expand All @@ -110,7 +110,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: user1,
StartTime: now.Add(-(2*time.Hour + 30*time.Minute)),
EndTime: now.Add(-(time.Hour + 30*time.Minute)),
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: true,
Expand All @@ -132,7 +132,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: user1,
StartTime: now.Add(-12 * time.Hour),
EndTime: now.Add(-10 * time.Hour),
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: false,
Expand All @@ -144,7 +144,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: "user1",
StartTime: now.Add(-3 * time.Hour),
EndTime: now.Add(-time.Hour),
Query: `{foo1="bar"}`,
Queries: []string{`{foo1="bar"}`},
},
expectedResp: resp{
isDeleted: false,
Expand All @@ -156,15 +156,15 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
UserID: "user2",
StartTime: now.Add(-3 * time.Hour),
EndTime: now.Add(-time.Hour),
Query: lbls,
Queries: lbls,
},
expectedResp: resp{
isDeleted: false,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
require.NoError(t, tc.deleteRequest.AddQuery(tc.deleteRequest.Query))
require.NoError(t, tc.deleteRequest.AddQueries(tc.deleteRequest.Queries))
isDeleted, nonDeletedIntervals := tc.deleteRequest.IsDeleted(chunkEntry)
require.Equal(t, tc.expectedResp.isDeleted, isDeleted)
require.Equal(t, tc.expectedResp.nonDeletedIntervals, nonDeletedIntervals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (m mockDeleteRequestsStore) UpdateStatus(ctx context.Context, userID, reque
return nil
}

func (m mockDeleteRequestsStore) AddDeleteRequest(ctx context.Context, userID string, startTime, endTime model.Time, LogQLRequest string) error {
func (m mockDeleteRequestsStore) AddDeleteRequest(ctx context.Context, userID string, startTime, endTime model.Time, LogQLRequest []string) error {
panic("implement me")
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: "different-user",
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-24 * time.Hour),
EndTime: now,
},
Expand All @@ -105,7 +105,7 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-24 * time.Hour),
EndTime: now,
},
Expand All @@ -120,7 +120,7 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-48 * time.Hour),
EndTime: now.Add(-24 * time.Hour),
},
Expand All @@ -135,13 +135,13 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-48 * time.Hour),
EndTime: now.Add(-24 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-12 * time.Hour),
EndTime: now,
},
Expand All @@ -156,25 +156,25 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-13 * time.Hour),
EndTime: now.Add(-11 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-10 * time.Hour),
EndTime: now.Add(-8 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-6 * time.Hour),
EndTime: now.Add(-5 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-2 * time.Hour),
EndTime: now,
},
Expand Down Expand Up @@ -202,13 +202,13 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-13 * time.Hour),
EndTime: now.Add(-6 * time.Hour),
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-8 * time.Hour),
EndTime: now,
},
Expand All @@ -223,19 +223,19 @@ func TestDeleteRequestsManager_Expired(t *testing.T) {
deleteRequestsFromStore: []DeleteRequest{
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-12 * time.Hour),
EndTime: now.Add(-6*time.Hour) - 1,
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-6 * time.Hour),
EndTime: now.Add(-4*time.Hour) - 1,
},
{
UserID: testUserID,
Query: lblFoo.String(),
Queries: []string{lblFoo.String()},
StartTime: now.Add(-4 * time.Hour),
EndTime: now,
},
Expand Down
Loading