Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/defaults.py: 91%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-08-30 20:56 -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 

83# Define IlmPhase as a typing alias to be reused multiple times 

84# 

85# In all currently supported Python versions (3.8 -> 3.12), the syntax: 

86# 

87# IlmPhase = t.Dict[ 

88# 

89# is supported. In 3.10 and up, you can use the more explicit syntax: 

90# 

91# IlmPhase: t.TypeAlias = t.Dict[ 

92# 

93# making use of the TypeAlias class. 

94# 

95# To support Python versions 3.8 and 3.9 (still), the older syntax is used. 

96IlmPhase = t.Dict[ 

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

98] 

99 

100 

101def ilmhot() -> IlmPhase: 

102 """Return a default hot ILM phase""" 

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

104 

105 

106def ilmwarm() -> IlmPhase: 

107 """Return a default warm ILM phase""" 

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

109 

110 

111def ilmcold() -> IlmPhase: 

112 """Return a default cold ILM phase""" 

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

114 

115 

116def ilmfrozen() -> IlmPhase: 

117 """Return a default frozen ILM phase""" 

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

119 

120 

121def ilmdelete() -> IlmPhase: 

122 """Return a default delete ILM phase""" 

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

124 

125 

126def ilm_phase(value): 

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

128 phase_map = { 

129 'hot': ilmhot(), 

130 'warm': ilmwarm(), 

131 'cold': ilmcold(), 

132 'frozen': ilmfrozen(), 

133 'delete': ilmdelete(), 

134 } 

135 return {value: phase_map[value]} 

136 

137 

138def ilm_force_merge(max_num_segments=1): 

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

140 return {'forcemerge': {'max_num_segments': max_num_segments}}