21
21
from pathlib import Path
22
22
from typing import Optional , Tuple
23
23
24
- from elasticsearch_serverless import Elasticsearch , RequestError
24
+ from elasticsearch_serverless import Elasticsearch
25
25
26
26
SOURCE_DIR = Path (__file__ ).absolute ().parent .parent
27
27
@@ -68,20 +68,10 @@ def wipe_cluster(client, elasticsearch_api_key):
68
68
except ImportError :
69
69
pass
70
70
71
- is_xpack = True
72
- if is_xpack :
73
- wipe_data_streams (client )
71
+ wipe_data_streams (client )
74
72
wipe_indices (client )
75
-
76
- if is_xpack :
77
- wipe_xpack_templates (client )
78
- else :
79
- client .indices .delete_template (name = "*" )
80
- client .indices .delete_index_template (name = "*" )
81
- client .cluster .delete_component_template (name = "*" )
82
-
83
- if is_xpack :
84
- wipe_transforms (client )
73
+ wipe_xpack_templates (client )
74
+ wipe_transforms (client )
85
75
86
76
if close_after_wipe :
87
77
client .close ()
@@ -109,22 +99,12 @@ def wipe_xpack_templates(client):
109
99
# indices aren't cleaned up in time before we issue the delete.
110
100
templates = client .cluster .get_component_template ()["component_templates" ]
111
101
templates_to_delete = [
112
- template for template in templates if not is_xpack_template (template ["name" ])
102
+ template ["name" ]
103
+ for template in templates
104
+ if not is_xpack_template (template ["name" ])
113
105
]
114
- for _ in range (3 ):
115
- for template in list (templates_to_delete ):
116
- try :
117
- client .cluster .delete_component_template (
118
- name = template ["name" ],
119
- )
120
- except RequestError :
121
- pass
122
- else :
123
- templates_to_delete .remove (template )
124
-
125
- if not templates_to_delete :
126
- break
127
- time .sleep (0.01 )
106
+ if templates_to_delete :
107
+ client .cluster .delete_component_template (name = "," .join (templates_to_delete ))
128
108
129
109
130
110
def wipe_transforms (client : Elasticsearch , timeout = 30 ):
@@ -143,38 +123,53 @@ def wipe_transforms(client: Elasticsearch, timeout=30):
143
123
144
124
145
125
def is_xpack_template (name ):
146
- if name .startswith (".monitoring -" ):
126
+ if name .startswith (".alerts -" ):
147
127
return True
148
- elif name .startswith (".watch" ) or name . startswith ( ".triggered_watches " ):
128
+ elif name .startswith (".kibana-data-quality-dashboard- " ):
149
129
return True
150
- elif name .startswith (".data-frame -" ):
130
+ elif name .startswith (".kibana-elastic-ai-assistant-component-template -" ):
151
131
return True
152
- elif name .startswith (".ml- " ):
132
+ elif name .startswith ("behavioral_analytics-events " ):
153
133
return True
154
- elif name .startswith (".transform-" ):
155
- return True
156
- elif name .startswith (".deprecation-" ):
134
+ elif name .startswith ("elastic-connectors-" ):
157
135
return True
158
136
if name in {
159
- ".watches" ,
160
- "security_audit_log" ,
161
- ".slm-history" ,
162
- ".async-search" ,
163
- "saml-service-provider" ,
164
- "logs" ,
165
- "logs-settings" ,
137
+ "apm-10d@lifecycle" ,
138
+ "apm-180d@lifecycle" ,
139
+ "apm-390d@lifecycle" ,
140
+ "apm-90d@lifecycle" ,
141
+ "apm@mappings" ,
142
+ "apm@settings" ,
143
+ "data-streams-mappings" ,
144
+ "data-streams@mappings" ,
145
+ "ecs@dynamic_templates" ,
146
+ "ecs@mappings" ,
147
+ "kibana-reporting@settings" ,
148
+ "logs-apm.error@mappings" ,
149
+ "logs-apm@settings" ,
166
150
"logs-mappings" ,
167
- "metrics" ,
168
- "metrics-settings" ,
151
+ "logs@mappings" ,
152
+ "logs-settings" ,
153
+ "logs@settings" ,
154
+ "metrics-apm@mappings" ,
155
+ "metrics-apm.service_destination@mappings" ,
156
+ "metrics-apm.service_summary@mappings" ,
157
+ "metrics-apm.service_transaction@mappings" ,
158
+ "metrics-apm@settings" ,
159
+ "metrics-apm.transaction@mappings" ,
169
160
"metrics-mappings" ,
170
- "synthetics" ,
171
- "synthetics-settings" ,
161
+ "metrics@mappings" ,
162
+ "metrics-settings" ,
163
+ "metrics@settings" ,
164
+ "metrics-tsdb-settings" ,
165
+ "metrics@tsdb-settings" ,
172
166
"synthetics-mappings" ,
173
- ".snapshot-blob-cache" ,
174
- "ilm-history" ,
175
- "logstash-index-template" ,
176
- "security-index-template" ,
177
- "data-streams-mappings" ,
167
+ "synthetics@mappings" ,
168
+ "synthetics-settings" ,
169
+ "synthetics@settings" ,
170
+ "traces-apm@mappings" ,
171
+ "traces-apm.rum@mappings" ,
172
+ "traces@mappings" ,
178
173
}:
179
174
return True
180
175
return False
0 commit comments