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

Fix/name based ages #1728

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions curator/indexlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re
import itertools
import logging
import sys

from elasticsearch8.exceptions import NotFoundError, TransportError
from es_client.helpers.schemacheck import SchemaCheck
from es_client.helpers.utils import ensure_list
Expand Down Expand Up @@ -426,6 +428,8 @@ def _get_name_based_ages(self, timestring):
epoch = tstr.get_epoch(index)
if isinstance(epoch, int):
self.index_info[index]['age']['name'] = epoch
else:
self.index_info[index]['age']['name'] = sys.maxsize


def _get_field_stats_dates(self, field='@timestamp'):
Expand Down
44 changes: 44 additions & 0 deletions tests/integration/test_delete_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,50 @@ def test_delete_in_period_absolute_date(self):
self.assertEqual(0, self.result.exit_code)
self.assertEqual(1, len(indices))
self.assertEqual(expected, indices[0])
def test_name_days_pattern_with_index_with_month_pattern(self):
delete_days_pattern = ('---\n'
'actions:\n'
' 1:\n'
' description: "Delete indices as filtered"\n'
' action: delete_indices\n'
' options:\n'
' continue_if_exception: False\n'
' disable_action: False\n'
' filters:\n'
' - filtertype: {0}\n'
' source: {1}\n'
' direction: {2}\n'
' timestring: {3}\n'
' unit: {4}\n'
' unit_count: {5}\n ')
self.create_indices(2, unit='months')
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(self.args['actionfile'],
delete_days_pattern.format('age', 'name', 'older', "'%Y.%m.%d'", 'days', 7))
self.invoke_runner()
self.assertEqual(2, len(exclude_ilm_history(get_indices(self.client))))
def test_name_month_pattern_with_index_without_pattern(self):
delete_no_pattern = ('---\n'
'actions:\n'
' 1:\n'
' description: "Delete indices as filtered"\n'
' action: delete_indices\n'
' options:\n'
' continue_if_exception: False\n'
' disable_action: False\n'
' filters:\n'
' - filtertype: {0}\n'
' source: {1}\n'
' direction: {2}\n'
' timestring: {3}\n'
' unit: {4}\n'
' unit_count: {5}\n ')
self.create_index("index-prod")
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(self.args['actionfile'],
delete_no_pattern.format('age', 'name', 'older', "'%Y.%m'", 'days', 1))
self.invoke_runner()
self.assertEqual(1, len(exclude_ilm_history(get_indices(self.client))))
def test_delete_in_period_intersect(self):
# filtertype: {0}
# source: {1}
Expand Down