Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/defaults.py: 100%
33 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-17 19:29 -0600
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-17 19:29 -0600
1"""Default values and constants"""
3import typing as t
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': {
23 'properties': {
24 'l1': {
25 'properties': {'l2': {'properties': {'l3': {'type': 'keyword'}}}}
26 }
27 }
28 },
29 }
30}
32NAMEMAPPER: t.Dict[str, str] = {
33 'index': 'idx',
34 'indices': 'idx', # This is to aid testing and other places where kind is indices
35 'data_stream': 'ds',
36 'component': 'cmp',
37 'ilm': 'ilm',
38 'template': 'tmpl',
39 'snapshot': 'snp',
40}
42PAUSE_DEFAULT: str = '1.0'
43PAUSE_ENVVAR: str = 'ES_TESTBED_PAUSE'
45PLURALMAP: t.Dict[str, str] = {
46 'ilm': 'ILM Policies',
47 'index': 'indices',
48}
50TESTPLAN: dict = {
51 'type': 'indices',
52 'prefix': 'es-testbed',
53 'repository': None,
54 'rollover_alias': None,
55 'ilm': {
56 'enabled': False,
57 'phases': ['hot', 'delete'],
58 'readonly': None,
59 'forcemerge': False,
60 'max_num_segments': 1,
61 },
62 'entities': [],
63}
64"""Default values for the TestPlan settings"""
66TIER: dict = {
67 'hot': {'pref': 'data_hot,data_content'},
68 'warm': {'pref': 'data_warm,data_hot,data_content'},
69 'cold': {
70 'pref': 'data_cold,data_warm,data_hot,data_content',
71 'prefix': 'restored',
72 'storage': 'full_copy',
73 },
74 'frozen': {
75 'pref': 'data_frozen',
76 'prefix': 'partial',
77 'storage': 'shared_cache',
78 },
79}
81TIMEOUT_DEFAULT: str = '30'
82TIMEOUT_ENVVAR: str = 'ES_TESTBED_TIMEOUT'
84# Define IlmPhase as a typing alias to be reused multiple times
85#
86# In all currently supported Python versions (3.8 -> 3.12), the syntax:
87#
88# IlmPhase = t.Dict[
89#
90# is supported. In 3.10 and up, you can use the more explicit syntax:
91#
92# IlmPhase: t.TypeAlias = t.Dict[
93#
94# making use of the TypeAlias class.
95#
96# To support Python versions 3.8 and 3.9 (still), the older syntax is used.
97IlmPhase = t.Dict[
98 str, t.Union[str, t.Dict[str, str], t.Dict[str, t.Dict[str, t.Dict[str, str]]]]
99]
102def ilmhot() -> IlmPhase:
103 """Return a default hot ILM phase"""
104 return {'actions': {'rollover': {'max_primary_shard_size': '1gb', 'max_age': '1d'}}}
107def ilmwarm() -> IlmPhase:
108 """Return a default warm ILM phase"""
109 return {'min_age': '2d', 'actions': {}}
112def ilmcold() -> IlmPhase:
113 """Return a default cold ILM phase"""
114 return {'min_age': '3d', 'actions': {}}
117def ilmfrozen() -> IlmPhase:
118 """Return a default frozen ILM phase"""
119 return {'min_age': '4d', 'actions': {}}
122def ilmdelete() -> IlmPhase:
123 """Return a default delete ILM phase"""
124 return {'min_age': '5d', 'actions': {'delete': {}}}
127def ilm_phase(value: str) -> IlmPhase:
128 """Return the default phase step based on 'value'"""
129 phase_map = {
130 'hot': ilmhot(),
131 'warm': ilmwarm(),
132 'cold': ilmcold(),
133 'frozen': ilmfrozen(),
134 'delete': ilmdelete(),
135 }
136 return {value: phase_map[value]}
139def ilm_force_merge(max_num_segments: int = 1) -> t.Dict[str, t.Dict[str, int]]:
140 """Return an ILM policy force merge action block using max_num_segments"""
141 return {'forcemerge': {'max_num_segments': max_num_segments}}