From 16f601b6ff9aa381de3caee1273c6aa2001ce804 Mon Sep 17 00:00:00 2001 From: gaobinlong Date: Wed, 11 Oct 2023 19:49:03 +0800 Subject: [PATCH] Fix integration test failure by allowing direct access to system index warning (#784) (#785) * Fix integration test failure by allowing direct access to system index warning Signed-off-by: gaobinlong * Fix bwc test failure of throwing direct access to system index when getting mapping Signed-off-by: gaobinlong --------- Signed-off-by: gaobinlong (cherry picked from commit 0a7a5f99e71248cce9d5c15b0b99f9f270261d21) --- .../integtest/PluginRestTestCase.kt | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt index 026ddffd..112ece61 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/PluginRestTestCase.kt @@ -367,17 +367,44 @@ abstract class PluginRestTestCase : OpenSearchRestTestCase() { } protected fun getCurrentMappingsSchemaVersion(): Int { - val indexName = ".opensearch-notifications-config" - val getMappingRequest = Request(RestRequest.Method.GET.name, "$indexName/_mappings") - val options = RequestOptions.DEFAULT.toBuilder() - options.setWarningsHandler(PERMISSIVE) - getMappingRequest.options = options.build() + val getMappingRequest = Request(RestRequest.Method.GET.name, "${NotificationConfigIndex.INDEX_NAME}/_mappings") + val requestOptions = RequestOptions.DEFAULT.toBuilder() + // Allow direct access to system index warning + requestOptions.setWarningsHandler { warnings: List -> + if (warnings.isEmpty()) { + return@setWarningsHandler false + } else if (warnings.size > 1) { + return@setWarningsHandler true + } else { + return@setWarningsHandler !warnings[0].startsWith("this request accesses system indices:") + } + } + getMappingRequest.setOptions(requestOptions) val response = executeRequest(getMappingRequest, RestStatus.OK.status, client()) - val mappingsObject = response.get(indexName).asJsonObject.get("mappings").asJsonObject + val mappingsObject = response.get(NotificationConfigIndex.INDEX_NAME).asJsonObject.get("mappings").asJsonObject return mappingsObject.get(NotificationConfigIndex._META)?.asJsonObject?.get(NotificationConfigIndex.SCHEMA_VERSION)?.asInt ?: NotificationConfigIndex.DEFAULT_SCHEMA_VERSION } + // only refresh the notification config index to avoid too many warnings + @Throws(IOException::class) + override fun refreshAllIndices() { + val refreshRequest = Request("POST", "${NotificationConfigIndex.INDEX_NAME}/_refresh") + val requestOptions = RequestOptions.DEFAULT.toBuilder() + // Allow direct access to system index warning + requestOptions.setWarningsHandler { warnings: List -> + if (warnings.isEmpty()) { + return@setWarningsHandler false + } else if (warnings.size > 1) { + return@setWarningsHandler true + } else { + return@setWarningsHandler !warnings[0].startsWith("this request accesses system indices:") + } + } + refreshRequest.setOptions(requestOptions) + client().performRequest(refreshRequest) + } + protected class ClusterSetting(val type: String, val name: String, var value: Any?) { init { this.value = if (value == null) "null" else "\"" + value + "\""