-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[fix] Allow es-index-cleaner to delete indices based on current time #6790
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c7a2a85
Update es-index-cleaner to delete indices 24 hours before runtime
Asatyam 1e2c795
Introduce es.index.relativeTimeIndexDeletion feature gate to prevent …
Asatyam 585325a
add RegisterFromVersion to the feature gate es.index.relativeTimeInde…
Asatyam 298bb95
Merge branch 'main' into fix_index_cleaner_date
Asatyam 6f777bc
Extract the calculation of cuttoff time for index deletion to its own…
Asatyam 5a9f3fe
Add tests for cutoff time calculation in index deletion
Asatyam 8b80757
Merge branch 'main' into fix_index_cleaner_date
yurishkuro b6395f8
fix version
yurishkuro d68e036
Update cmd/es-index-cleaner/app/cutoff_time.go
yurishkuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
func CalculateDeletionCutoff(currTime time.Time, numOfDays int, relativeIndexEnabled bool) time.Time { | ||
year, month, day := currTime.Date() | ||
// tomorrow midnight | ||
cutoffTime := time.Date(year, month, day, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1) | ||
if relativeIndexEnabled { | ||
cutoffTime = currTime | ||
} | ||
return cutoffTime.Add(-time.Hour * 24 * time.Duration(numOfDays)) | ||
} |
This file contains hidden or 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,72 @@ | ||
// Copyright (c) 2025 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCalculateDeletionCutoff(t *testing.T) { | ||
time20250309163053 := time.Date(2025, time.March, 9, 16, 30, 53, 0, time.UTC) | ||
tests := []struct { | ||
name string | ||
currTime time.Time | ||
numOfDays int | ||
relativeIndexEnabled bool | ||
expectedCutoff time.Time | ||
}{ | ||
{ | ||
name: "get today's midnight", | ||
currTime: time20250309163053, | ||
numOfDays: 1, | ||
relativeIndexEnabled: false, | ||
expectedCutoff: time.Date(2025, time.March, 9, 0, 0, 0, 0, time.UTC), | ||
}, | ||
{ | ||
name: "get exactly 24 hours before execution time", | ||
currTime: time20250309163053, | ||
numOfDays: 1, | ||
relativeIndexEnabled: true, | ||
expectedCutoff: time.Date(2025, time.March, 8, 16, 30, 53, 0, time.UTC), | ||
}, | ||
{ | ||
name: "get the current time if numOfDays is 0 and relativeIndexEnabled is true", | ||
currTime: time20250309163053, | ||
numOfDays: 0, | ||
relativeIndexEnabled: true, | ||
expectedCutoff: time20250309163053, | ||
}, | ||
{ | ||
name: "get tomorrow's midnight if numOfDays is 0 relativeIndexEnabled is False", | ||
currTime: time20250309163053, | ||
numOfDays: 0, | ||
relativeIndexEnabled: false, | ||
expectedCutoff: time.Date(2025, time.March, 10, 0, 0, 0, 0, time.UTC), | ||
}, | ||
{ | ||
name: "get (numOfDays-1)'s midnight", | ||
currTime: time20250309163053, | ||
numOfDays: 3, | ||
relativeIndexEnabled: false, | ||
expectedCutoff: time.Date(2025, time.March, 7, 0, 0, 0, 0, time.UTC), | ||
}, | ||
{ | ||
name: "get exactly (24*numOfDays) hours before execution time", | ||
currTime: time20250309163053, | ||
numOfDays: 3, | ||
relativeIndexEnabled: true, | ||
expectedCutoff: time.Date(2025, time.March, 6, 16, 30, 53, 0, time.UTC), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
cutoffTime := CalculateDeletionCutoff(time20250309163053, test.numOfDays, test.relativeIndexEnabled) | ||
assert.Equal(t, test.expectedCutoff, cutoffTime) | ||
}) | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.