Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/helpers/config.py: 0%
40 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-09 18:23 -0600
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-09 18:23 -0600
1"""Configuration bits returned by function"""
2from es_testbed.defaults import MAPPING
4SETTINGS: dict = {
5 'index.lifecycle.name': 'my-lifecycle-policy'
6}
8COMP_MAPPINGS: dict = {
9 "template": {
10 "settings": SETTINGS
11 }
12}
14COMP_SETTINGS: dict = {
15 "template": {
16 "mappings": MAPPING
17 }
18}
20def hot() -> dict:
21 """Return the hot ILM phase"""
22 return {
23 "actions": {
24 "rollover": {
25 "max_primary_shard_size": "1gb"
26 }
27 }
28 }
30def warm() -> dict:
31 """Return the warm ILM phase"""
32 return {
33 "min_age": "30m",
34 "actions": {}
35 }
37def cold(repository='found-snapshots') -> dict:
38 """Return the cold ILM phase"""
39 return {
40 "min_age": "1h",
41 "actions": {
42 "searchable_snapshot": {
43 "snapshot_repository": repository
44 }
45 }
46 }
48def frozen(repository='found-snapshots') -> dict:
49 """Return the frozen ILM phase"""
50 return {
51 "min_age": "2h",
52 "actions": {
53 "searchable_snapshot": {
54 "snapshot_repository": repository
55 }
56 }
57 }
59def delete() -> dict:
60 """Return the delete ILM phase"""
61 return {
62 "min_age": "2d",
63 "actions": {
64 "delete": {}
65 }
66 }
68def generate_ilm(phases: list=['hot', 'delete'], repository=None) -> dict:
69 """Generate a full ILM policy based on which phases are passed"""
70 policy = {"policy": {"phases": {}}}
71 # We always have at least a hot and a delete phase
72 policy['policy']['phases']['hot'] = hot()
73 if 'warm' in phases:
74 policy['policy']['phases']['warm'] = warm()
75 if repository:
76 if 'cold' in phases:
77 policy['policy']['phases']['cold'] = cold(repository=repository)
78 if 'frozen' in phases:
79 policy['policy']['phases']['frozen'] = frozen(repository=repository)
80 # We always have at least a hot and a delete phase
81 policy['policy']['phases']['delete'] = delete()
82 return policy
84def index_settings(ilm_policy=None) -> dict:
85 """Generate index settings suitable for an index template"""
86 settings = {}
87 if ilm_policy:
88 settings = {'index.lifecycle.name': ilm_policy}
89 return settings
91def index_mapping() -> dict:
92 """Generate index mappings suitable for an index template"""
93 return MAPPING
95def index_template(index_patterns: list, data_stream: bool=True, components: list=None) -> dict:
96 """Generate the body of an index template"""
97 template = {"index_patterns": index_patterns}
98 if data_stream:
99 template['data_stream'] = { }
100 if components:
101 template['composed_of'] = components
102 return template