Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/defaults.py: 100%
32 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-25 19:21 -0600
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-25 19:21 -0600
1"""Default values and constants"""
2import typing as t
3# pylint: disable=missing-function-docstring
5EPILOG: str = 'Learn more at https://github.com/untergeek/es-testbed'
7HELP_OPTIONS: dict = {'help_option_names': ['-h', '--help']}
9ARGSCLASSES: list = ['IlmBuilder', 'IlmExplain', 'TestPlan']
11COLD_PREFIX: str = 'restored-'
12FROZEN_PREFIX: str = 'partial-'
14SS_PREFIX: t.Dict[str, str] = {'cold': COLD_PREFIX, 'frozen': FROZEN_PREFIX}
16MAPPING: dict = {
17 'properties': {
18 '@timestamp': {'type': 'date'},
19 'message': {'type': 'keyword'},
20 'number': {'type': 'long'},
21 'nested': {'properties': {'key': {'type': 'keyword'}}},
22 'deep': {'properties': {'l1': {'properties': {'l2': {
23 'properties': {'l3': {'type': 'keyword'}}}}}}
24 }
25 }
26}
28NAMEMAPPER: t.Dict[str, str] = {
29 'index': 'idx',
30 'data_stream': 'ds',
31 'component': 'cmp',
32 'ilm': 'ilm',
33 'template': 'tmpl',
34 'snapshot': 'snp',
35}
37PAUSE_DEFAULT: str = '0.25'
38PAUSE_ENVVAR: str = 'ES_TESTBED_PAUSE'
40PLURALMAP: t.Dict[str, str] = {
41 'ilm': 'ILM Policie',
42 'index': 'indice',
43}
45TESTPLAN: dict = {
46 'type': 'indices',
47 'prefix': 'es-testbed',
48 'repository': None,
49 'rollover_alias': None,
50 'ilm': {
51 'enabled': False,
52 'tiers': ['hot', 'delete'],
53 'forcemerge': False,
54 'max_num_segments': 1
55 },
56 'defaults': {
57 'entity_count': 3,
58 'docs': 10,
59 'match': True,
60 'searchable': None,
61 },
62 'entities': [],
63}
65TIER: dict = {
66 'hot': {
67 'pref': 'data_hot,data_content'
68 },
69 'warm': {
70 'pref': 'data_warm,data_hot,data_content'
71 },
72 'cold': {
73 'pref': 'data_cold,data_warm,data_hot,data_content',
74 'prefix': 'restored',
75 'storage': 'full_copy',
76 },
77 'frozen': {
78 'pref': 'data_frozen',
79 'prefix': 'partial',
80 'storage': 'shared_cache',
81 }
82}
84TIMEOUT_DEFAULT: str = '30'
85TIMEOUT_ENVVAR: str = 'ES_TESTBED_TIMEOUT'
87IlmPhase: t.TypeAlias = (
88 t.Dict[str, t.Union[str, t.Dict[str, str], t.Dict[str, t.Dict[str, t.Dict[str, str]]]]]
89)
91def ilmhot() -> IlmPhase:
92 return {
93 'actions': {
94 'rollover': {
95 'max_primary_shard_size': '1gb',
96 'max_age': '1d'
97 }
98 }
99 }
100def ilmwarm() -> IlmPhase:
101 return {'min_age': '2d', 'actions': {}}
102def ilmcold() -> IlmPhase:
103 return {'min_age': '3d', 'actions': {}}
104def ilmfrozen() -> IlmPhase:
105 return {'min_age': '4d', 'actions': {}}
106def ilmdelete() -> IlmPhase:
107 return {'min_age': '5d', 'actions': {'delete': {}}}
109def ilm_phase(tier):
110 """Return the default phase step based on 'tier'"""
111 phase_map = {
112 'hot': ilmhot(),
113 'warm': ilmwarm(),
114 'cold': ilmcold(),
115 'frozen': ilmfrozen(),
116 'delete': ilmdelete(),
117 }
118 return {tier: phase_map[tier]}
120def ilm_force_merge(max_num_segments=1):
121 """Return an ILM policy force merge action block using max_num_segments"""
122 return {'forcemerge': {'max_num_segments': max_num_segments}}