Skip to content

Commit 8143416

Browse files
authored
Optimize wipe_cluster (#58)
1 parent d973e91 commit 8143416

File tree

1 file changed

+47
-52
lines changed

1 file changed

+47
-52
lines changed

test_elasticsearch_serverless/utils.py

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from pathlib import Path
2222
from typing import Optional, Tuple
2323

24-
from elasticsearch_serverless import Elasticsearch, RequestError
24+
from elasticsearch_serverless import Elasticsearch
2525

2626
SOURCE_DIR = Path(__file__).absolute().parent.parent
2727

@@ -68,20 +68,10 @@ def wipe_cluster(client, elasticsearch_api_key):
6868
except ImportError:
6969
pass
7070

71-
is_xpack = True
72-
if is_xpack:
73-
wipe_data_streams(client)
71+
wipe_data_streams(client)
7472
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)
8575

8676
if close_after_wipe:
8777
client.close()
@@ -109,22 +99,12 @@ def wipe_xpack_templates(client):
10999
# indices aren't cleaned up in time before we issue the delete.
110100
templates = client.cluster.get_component_template()["component_templates"]
111101
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"])
113105
]
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))
128108

129109

130110
def wipe_transforms(client: Elasticsearch, timeout=30):
@@ -143,38 +123,53 @@ def wipe_transforms(client: Elasticsearch, timeout=30):
143123

144124

145125
def is_xpack_template(name):
146-
if name.startswith(".monitoring-"):
126+
if name.startswith(".alerts-"):
147127
return True
148-
elif name.startswith(".watch") or name.startswith(".triggered_watches"):
128+
elif name.startswith(".kibana-data-quality-dashboard-"):
149129
return True
150-
elif name.startswith(".data-frame-"):
130+
elif name.startswith(".kibana-elastic-ai-assistant-component-template-"):
151131
return True
152-
elif name.startswith(".ml-"):
132+
elif name.startswith("behavioral_analytics-events"):
153133
return True
154-
elif name.startswith(".transform-"):
155-
return True
156-
elif name.startswith(".deprecation-"):
134+
elif name.startswith("elastic-connectors-"):
157135
return True
158136
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",
166150
"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",
169160
"metrics-mappings",
170-
"synthetics",
171-
"synthetics-settings",
161+
"metrics@mappings",
162+
"metrics-settings",
163+
"metrics@settings",
164+
"metrics-tsdb-settings",
165+
"metrics@tsdb-settings",
172166
"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",
178173
}:
179174
return True
180175
return False

0 commit comments

Comments
 (0)