The getHistoryIndexToDelete method incorrectly returned the index name
for deletion when the index had no matching alias in the history type
being checked. A findings index with no alert-history alias would be
deleted after exceeding alert_history_retention_period instead of
finding_history_retention_period.
Fix: return null (do not delete) when an index does not belong to the
history type being evaluated (alias == null). Only delete when the index
positively matches the history type's alias AND exceeds that type's
retention period.
Also makes getHistoryIndexToDelete package-private static for
testability and adds unit tests covering:
- Findings index not deleted by alert retention check
- Findings index deleted when exceeding finding retention
- Findings index not deleted when younger than retention
Resolves opensearch-project#1759
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
The getHistoryIndexToDelete method incorrectly returned the index name for deletion when the index had no matching alias in the history type being checked. A findings index with no alert-history alias would be deleted after exceeding alert_history_retention_period instead of finding_history_retention_period.
Fix: return null (do not delete) when an index does not belong to the history type being evaluated (alias == null). Only delete when the index positively matches the history type's alias AND exceeds that type's retention period.
Also makes getHistoryIndexToDelete package-private static for testability and adds unit tests covering:
Resolves #1759
Description
Fixes the getHistoryIndexToDelete method in DetectorIndexManagementService which incorrectly deleted findings indices based on alert_history_retention_period instead of finding_history_retention_period.
Root cause: The method is called once per history type (alert, finding, correlation, IOC) for each index. When an index had no matching alias for the history type being checked (e.g., a findings index checked against alert history aliases), the method fell through and returned the index for deletion. It should have returned null (skip — this index doesn't belong to me).
Fix: Return null when no alias match is found, meaning the index doesn't belong to this history type. Only return the index name for deletion when it positively matches the type's alias AND exceeds that type's retention period.
Also makes getHistoryIndexToDelete package-private static (uses no instance state) and adds 3 unit tests.
Related Issues
Resolves #1759
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.