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-08-21 12:05 -0600

1"""Default values and constants""" 

2 

3import typing as t 

4 

5EPILOG: str = 'Learn more at https://github.com/untergeek/es-testbed' 

6 

7HELP_OPTIONS: dict = {'help_option_names': ['-h', '--help']} 

8 

9ARGSCLASSES: list = ['IlmBuilder', 'IlmExplain', 'TestPlan'] 

10 

11COLD_PREFIX: str = 'restored-' 

12FROZEN_PREFIX: str = 'partial-' 

13 

14SS_PREFIX: t.Dict[str, str] = {'cold': COLD_PREFIX, 'frozen': FROZEN_PREFIX} 

15 

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} 

31 

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} 

41 

42PAUSE_DEFAULT: str = '0.25' 

43PAUSE_ENVVAR: str = 'ES_TESTBED_PAUSE' 

44 

45PLURALMAP: t.Dict[str, str] = { 

46 'ilm': 'ILM Policie', 

47 'index': 'indice', 

48} 

49 

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 

65TIER: dict = { 

66 'hot': {'pref': 'data_hot,data_content'}, 

67 'warm': {'pref': 'data_warm,data_hot,data_content'}, 

68 'cold': { 

69 'pref': 'data_cold,data_warm,data_hot,data_content', 

70 'prefix': 'restored', 

71 'storage': 'full_copy', 

72 }, 

73 'frozen': { 

74 'pref': 'data_frozen', 

75 'prefix': 'partial', 

76 'storage': 'shared_cache', 

77 }, 

78} 

79 

80TIMEOUT_DEFAULT: str = '30' 

81TIMEOUT_ENVVAR: str = 'ES_TESTBED_TIMEOUT' 

82 

83IlmPhase: t.TypeAlias = t.Dict[ 

84 str, t.Union[str, t.Dict[str, str], t.Dict[str, t.Dict[str, t.Dict[str, str]]]] 

85] 

86 

87 

88def ilmhot() -> IlmPhase: 

89 """Return a default hot ILM phase""" 

90 return {'actions': {'rollover': {'max_primary_shard_size': '1gb', 'max_age': '1d'}}} 

91 

92 

93def ilmwarm() -> IlmPhase: 

94 """Return a default warm ILM phase""" 

95 return {'min_age': '2d', 'actions': {}} 

96 

97 

98def ilmcold() -> IlmPhase: 

99 """Return a default cold ILM phase""" 

100 return {'min_age': '3d', 'actions': {}} 

101 

102 

103def ilmfrozen() -> IlmPhase: 

104 """Return a default frozen ILM phase""" 

105 return {'min_age': '4d', 'actions': {}} 

106 

107 

108def ilmdelete() -> IlmPhase: 

109 """Return a default delete ILM phase""" 

110 return {'min_age': '5d', 'actions': {'delete': {}}} 

111 

112 

113def ilm_phase(value): 

114 """Return the default phase step based on 'value'""" 

115 phase_map = { 

116 'hot': ilmhot(), 

117 'warm': ilmwarm(), 

118 'cold': ilmcold(), 

119 'frozen': ilmfrozen(), 

120 'delete': ilmdelete(), 

121 } 

122 return {value: phase_map[value]} 

123 

124 

125def ilm_force_merge(max_num_segments=1): 

126 """Return an ILM policy force merge action block using max_num_segments""" 

127 return {'forcemerge': {'max_num_segments': max_num_segments}}