Coverage for src/es_testbed/defaults.py: 100%
30 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:14 -0600
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:14 -0600
1"""Default values and constants"""
2import typing as t
3# pylint: disable=E1120
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 'rollover_alias': False,
49 'ilm': {
50 'tiers': ['hot', 'delete'],
51 'forcemerge': False,
52 'max_num_segments': 1,
53 'repository': None,
54 },
55 'defaults': {
56 'entity_count': 3,
57 'docs': 10,
58 'match': True,
59 'searchable': None,
60 }
61}
63TIER: dict = {
64 'hot': {
65 'pref': 'data_hot,data_content'
66 },
67 'warm': {
68 'pref': 'data_warm,data_hot,data_content'
69 },
70 'cold': {
71 'pref': 'data_cold,data_warm,data_hot,data_content',
72 'prefix': 'restored',
73 'storage': 'full_copy',
74 },
75 'frozen': {
76 'pref': 'data_frozen',
77 'prefix': 'partial',
78 'storage': 'shared_cache',
79 }
80}
82IlmPhase: t.TypeAlias = (
83 t.Dict[str, t.Union[str, t.Dict[str, str], t.Dict[str, t.Dict[str, t.Dict[str, str]]]]]
84)
86def ilmhot() -> IlmPhase:
87 return {
88 'actions': {
89 'rollover': {
90 'max_primary_shard_size': '1gb',
91 'max_age': '1d'
92 }
93 }
94 }
95def ilmwarm() -> IlmPhase:
96 return {'min_age': '2d', 'actions': {}}
97def ilmcold() -> IlmPhase:
98 return {'min_age': '3d', 'actions': {}}
99def ilmfrozen() -> IlmPhase:
100 return {'min_age': '4d', 'actions': {}}
101def ilmdelete() -> IlmPhase:
102 return {'min_age': '5d', 'actions': {'delete': {}}}
104def ilm_phase(tier):
105 """Return the default phase step based on 'tier'"""
106 phase_map = {
107 'hot': ilmhot(),
108 'warm': ilmwarm(),
109 'cold': ilmcold(),
110 'frozen': ilmfrozen(),
111 'delete': ilmdelete(),
112 }
113 return {tier: phase_map[tier]}
115def ilm_force_merge(max_num_segments=1):
116 """Return an ILM policy force merge action block using max_num_segments"""
117 return {'forcemerge': {'max_num_segments': max_num_segments}}