Skip to content

Commit 1719218

Browse files
committed
add IndexNameFrequency.NEVER
Add possibility to write index to the exact name specified without any datetime suffixes. Fixes cmanaha#69
1 parent e4a16a8 commit 1719218

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cmreslogging/handlers.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ class IndexNameFrequency(Enum):
5151
- Weekly indices
5252
- Monthly indices
5353
- Year indices
54+
- Never expiring indices
5455
"""
5556
DAILY = 0
5657
WEEKLY = 1
5758
MONTHLY = 2
5859
YEARLY = 3
60+
NEVER = 4
5961

6062
# Defaults for the class
6163
__DEFAULT_ELASTICSEARCH_HOST = [{'host': 'localhost', 'port': 9200}]
@@ -115,11 +117,20 @@ def _get_yearly_index_name(es_index_name):
115117
"""
116118
return "{0!s}-{1!s}".format(es_index_name, datetime.datetime.now().strftime('%Y'))
117119

120+
@staticmethod
121+
def _get_never_index_name(es_index_name):
122+
""" Return elasticsearch index name
123+
:param: index_name the prefix to be used in the index
124+
:return: A srting containing the elasticsearch indexname used which should include just the index name
125+
"""
126+
return "{0!s}".format(es_index_name)
127+
118128
_INDEX_FREQUENCY_FUNCION_DICT = {
119129
IndexNameFrequency.DAILY: _get_daily_index_name,
120130
IndexNameFrequency.WEEKLY: _get_weekly_index_name,
121131
IndexNameFrequency.MONTHLY: _get_monthly_index_name,
122-
IndexNameFrequency.YEARLY: _get_yearly_index_name
132+
IndexNameFrequency.YEARLY: _get_yearly_index_name,
133+
IndexNameFrequency.NEVER: _get_never_index_name,
123134
}
124135

125136
def __init__(self,

tests/test_cmreshandler.py

+11
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ def test_index_name_frequency_functions(self):
169169
CMRESHandler._get_yearly_index_name(index_name)
170170
)
171171

172+
handler = CMRESHandler(hosts=[{'host': self.getESHost(), 'port': self.getESPort()}],
173+
auth_type=CMRESHandler.AuthType.NO_AUTH,
174+
es_index_name=index_name,
175+
use_ssl=False,
176+
index_name_frequency=CMRESHandler.IndexNameFrequency.NEVER,
177+
raise_on_indexing_exceptions=True)
178+
self.assertEqual(
179+
handler._index_name_func.__func__(index_name),
180+
CMRESHandler._get_never_index_name(index_name)
181+
)
182+
172183

173184
if __name__ == '__main__':
174185
unittest.main()

0 commit comments

Comments
 (0)