Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public abstract class OpenSearchSQLRestTestCase extends OpenSearchRestTestCase {
+ "}";
private static final String SCRIPT_CONTEXT_MAX_COMPILATIONS_RATE_PATTERN =
"script.context.*.max_compilations_rate";
// Per-class cleanup must not delete shared plugin state or force managed indices to be recreated.
private static final List<String> PLUGIN_MANAGED_INDEX_PREFIXES =
List.of(
".opensearch",
".opendistro",
".ql",
".plugins",
".scheduler",
".geospatial",
"security-auditlog-");
private static RestClient remoteClient;

/**
Expand Down Expand Up @@ -212,11 +222,7 @@ protected static void wipeAllOpenSearchIndices(RestClient client) throws IOExcep
JSONObject jsonObject = (JSONObject) object;
String indexName = jsonObject.getString("index");
try {
// System index, mostly named .opensearch-xxx or .opendistro-xxx, are not allowed to
// delete
if (!indexName.startsWith(".opensearch")
&& !indexName.startsWith(".opendistro")
&& !indexName.startsWith(".ql")) {
if (!isPluginManagedIndex(indexName)) {
client.performRequest(new Request("DELETE", "/" + indexName));
}
} catch (Exception e) {
Expand All @@ -230,6 +236,10 @@ protected static void wipeAllOpenSearchIndices(RestClient client) throws IOExcep
}
}

static boolean isPluginManagedIndex(String indexName) {
return PLUGIN_MANAGED_INDEX_PREFIXES.stream().anyMatch(indexName::startsWith);
}

/**
* Configure authentication and pass <b>builder</b> to superclass to configure other stuff.<br>
* By default, auth is configure when <b>https</b> is set only.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.legacy;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class OpenSearchSQLRestTestCaseIT {

@Test
public void identifiesPluginManagedIndices() {
assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".opensearch-observability"));
assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".opendistro_security"));
assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".ql-datasources"));
assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".plugins-ml-config"));
assertTrue(
OpenSearchSQLRestTestCase.isPluginManagedIndex(".scheduler-geospatial-ip2geo-datasource"));
assertTrue(
OpenSearchSQLRestTestCase.isPluginManagedIndex(".geospatial-ip2geo-data.datasource"));
assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex("security-auditlog-2026.07.15"));
}

@Test
public void leavesTestIndicesEligibleForCleanup() {
assertFalse(OpenSearchSQLRestTestCase.isPluginManagedIndex("opensearch-sql_test_index_bank"));
assertFalse(OpenSearchSQLRestTestCase.isPluginManagedIndex("security-test-index"));
assertFalse(OpenSearchSQLRestTestCase.isPluginManagedIndex(".test-hidden-index"));
}
}
Loading