From d8e47e00389cfffac9ca1be4c3d439bbdcb35ae8 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Thu, 6 Jun 2024 10:11:37 +0400 Subject: [PATCH 1/3] Stop deleting serverless component templates --- test_elasticsearch_serverless/utils.py | 61 ++++++++++++++++---------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/test_elasticsearch_serverless/utils.py b/test_elasticsearch_serverless/utils.py index 16d253e..080cf6b 100644 --- a/test_elasticsearch_serverless/utils.py +++ b/test_elasticsearch_serverless/utils.py @@ -143,38 +143,53 @@ def wipe_transforms(client: Elasticsearch, timeout=30): def is_xpack_template(name): - if name.startswith(".monitoring-"): + if name.startswith(".alerts-"): return True - elif name.startswith(".watch") or name.startswith(".triggered_watches"): + elif name.startswith(".kibana-data-quality-dashboard-"): return True - elif name.startswith(".data-frame-"): + elif name.startswith(".kibana-elastic-ai-assistant-component-template-"): return True - elif name.startswith(".ml-"): + elif name.startswith("behavioral_analytics-events"): return True - elif name.startswith(".transform-"): - return True - elif name.startswith(".deprecation-"): + elif name.startswith("elastic-connectors-"): return True if name in { - ".watches", - "security_audit_log", - ".slm-history", - ".async-search", - "saml-service-provider", - "logs", - "logs-settings", + "apm-10d@lifecycle", + "apm-180d@lifecycle", + "apm-390d@lifecycle", + "apm-90d@lifecycle", + "apm@mappings", + "apm@settings", + "data-streams-mappings", + "data-streams@mappings", + "ecs@dynamic_templates", + "ecs@mappings", + "kibana-reporting@settings", + "logs-apm.error@mappings", + "logs-apm@settings", "logs-mappings", - "metrics", - "metrics-settings", + "logs@mappings", + "logs-settings", + "logs@settings", + "metrics-apm@mappings", + "metrics-apm.service_destination@mappings", + "metrics-apm.service_summary@mappings", + "metrics-apm.service_transaction@mappings", + "metrics-apm@settings", + "metrics-apm.transaction@mappings", "metrics-mappings", - "synthetics", - "synthetics-settings", + "metrics@mappings", + "metrics-settings", + "metrics@settings", + "metrics-tsdb-settings", + "metrics@tsdb-settings", "synthetics-mappings", - ".snapshot-blob-cache", - "ilm-history", - "logstash-index-template", - "security-index-template", - "data-streams-mappings", + "synthetics@mappings", + "synthetics-settings", + "synthetics@settings", + "traces-apm@mappings", + "traces-apm.rum@mappings", + "traces@mappings", }: return True return False From 72a825e30d5876e1d9de0932b219ec3a4cd87501 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Thu, 6 Jun 2024 11:58:14 +0400 Subject: [PATCH 2/3] Remove `is_xpack` variable --- test_elasticsearch_serverless/utils.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/test_elasticsearch_serverless/utils.py b/test_elasticsearch_serverless/utils.py index 080cf6b..e447d37 100644 --- a/test_elasticsearch_serverless/utils.py +++ b/test_elasticsearch_serverless/utils.py @@ -68,20 +68,10 @@ def wipe_cluster(client, elasticsearch_api_key): except ImportError: pass - is_xpack = True - if is_xpack: - wipe_data_streams(client) + wipe_data_streams(client) wipe_indices(client) - - if is_xpack: - wipe_xpack_templates(client) - else: - client.indices.delete_template(name="*") - client.indices.delete_index_template(name="*") - client.cluster.delete_component_template(name="*") - - if is_xpack: - wipe_transforms(client) + wipe_xpack_templates(client) + wipe_transforms(client) if close_after_wipe: client.close() From 54b089778ae07d90c88f821f20bfff5093274be4 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Fri, 7 Jun 2024 11:48:36 +0400 Subject: [PATCH 3/3] Delete component templates in one request --- test_elasticsearch_serverless/utils.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/test_elasticsearch_serverless/utils.py b/test_elasticsearch_serverless/utils.py index e447d37..6d6490d 100644 --- a/test_elasticsearch_serverless/utils.py +++ b/test_elasticsearch_serverless/utils.py @@ -21,7 +21,7 @@ from pathlib import Path from typing import Optional, Tuple -from elasticsearch_serverless import Elasticsearch, RequestError +from elasticsearch_serverless import Elasticsearch SOURCE_DIR = Path(__file__).absolute().parent.parent @@ -99,22 +99,12 @@ def wipe_xpack_templates(client): # indices aren't cleaned up in time before we issue the delete. templates = client.cluster.get_component_template()["component_templates"] templates_to_delete = [ - template for template in templates if not is_xpack_template(template["name"]) + template["name"] + for template in templates + if not is_xpack_template(template["name"]) ] - for _ in range(3): - for template in list(templates_to_delete): - try: - client.cluster.delete_component_template( - name=template["name"], - ) - except RequestError: - pass - else: - templates_to_delete.remove(template) - - if not templates_to_delete: - break - time.sleep(0.01) + if templates_to_delete: + client.cluster.delete_component_template(name=",".join(templates_to_delete)) def wipe_transforms(client: Elasticsearch, timeout=30):