Преглед изворни кода

Search Applications: Remove inconsistent indices warning (#98348)

* Remove inconsistent indices warning

* Revert docs changes for inconsistent indices warning
Ioana Tagirta пре 2 година
родитељ
комит
b2ba56a804

+ 0 - 3
docs/reference/search-application/apis/get-search-application.asciidoc

@@ -10,9 +10,6 @@ beta::[]
 
 Retrieves information about a search application.
 
-If the search application has an inconsistent state between its alias and configured indices, a warning header will be returned with the response.
-To resolve this inconsistent state, issue an updated <<put-search-application>> command.
-
 [[get-search-application-request]]
 ==== {api-request-title}
 

+ 0 - 3
docs/reference/search-application/apis/search-application-search.asciidoc

@@ -11,9 +11,6 @@ beta::[]
 Given specified query parameters, creates an Elasticsearch query to run. Any unspecified template parameters will be
 assigned their default values if applicable.
 
-If the search application has an inconsistent state between its alias and configured indices, a warning header will be returned with the response.
-To resolve this inconsistent state, issue an updated <<put-search-application>> command.
-
 [[search-application-search-request]]
 ==== {api-request-title}
 

+ 0 - 66
x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/30_search_application_get.yml

@@ -123,72 +123,6 @@ teardown:
       search_application.get:
         name: test-nonexistent-search-application
 
----
-"Get Search Application - Warning returned when indices and aliases are inconsistent":
-  - skip:
-      features: warnings
-
-  - do:
-      indices.create:
-        index: test-index3
-        body:
-          settings:
-            index:
-              number_of_shards: 1
-              number_of_replicas: 0
-
-  - do:
-      indices.update_aliases:
-        body:
-          actions:
-            - add:
-                index: test-index1
-                alias: test-search-application-1
-            - add:
-                index: test-index2
-                alias: test-search-application-1
-            - add:
-                index: test-index3
-                alias: test-search-application-1
-
-  - do:
-      indices.delete:
-        index: test-index2
-        ignore: 404
-
-  - do:
-      warnings:
-        - "test-index2 index is in search application but not in associated alias"
-        - "test-index3 index is in alias but not associcated with search application"
-      search_application.get:
-        name: test-search-application-1
-
-  - match: { name: "test-search-application-1" }
-  - match: { analytics_collection_name: "test-analytics" }
-  - match: {
-    template: {
-      script: {
-        source: {
-          query: {
-            query_string: {
-              query: "{{query_string}}"
-            }
-          }
-        },
-        lang: "mustache",
-        options: {
-          content_type: "application/json;charset=utf-8"
-        }
-      },
-      dictionary: {
-        query_string: {
-          type: string
-        }
-      }
-    }
-  }
-  - gte: { updated_at_millis: 0 }
-
 ---
 "Get search application fails for unprivileged user":
   - skip:

+ 0 - 44
x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/55_search_application_search.yml

@@ -258,50 +258,6 @@ teardown:
             field_name: field3
             field_value: value3
 
----
-"Query Search Application - Warning returned when indices and aliases are inconsistent":
-  - skip:
-      features: ["warnings", "headers"]
-
-  - do:
-      indices.create:
-        index: test-index3
-        body:
-          settings:
-            index:
-              number_of_shards: 1
-              number_of_replicas: 0
-
-  - do:
-      indices.update_aliases:
-        body:
-          actions:
-            - add:
-                index: test-search-index1
-                alias: test-search-application-1
-            - add:
-                index: test-search-index2
-                alias: test-search-application-1
-            - add:
-                index: test-index3
-                alias: test-search-application-1
-
-  - do:
-      indices.delete:
-        index: test-search-index2
-        ignore: 404
-
-  - do:
-      warnings:
-        - "test-search-index2 index is in search application but not in associated alias"
-        - "test-index3 index is in alias but not associcated with search application"
-      headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" }  # user
-      search_application.search:
-        name: test-search-application-1
-
-  - match: { hits.total.value: 1 }
-  - match: { hits.hits.0._id: "doc1" }
-
 ---
 "Search application search fails for unprivileged user":
   - skip:

+ 0 - 39
x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplicationIndexService.java

@@ -73,7 +73,6 @@ import java.nio.CharBuffer;
 import java.util.Arrays;
 import java.util.Base64;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -95,8 +94,6 @@ public class SearchApplicationIndexService {
     public static final String SEARCH_APPLICATION_ALIAS_NAME = ".search-app";
     public static final String SEARCH_APPLICATION_CONCRETE_INDEX_NAME = ".search-app-1";
     public static final String SEARCH_APPLICATION_INDEX_NAME_PATTERN = ".search-app-*";
-    private static final String INCONSISTENT_INDICES_NOT_IN_ALIAS_MSG = "index is in search application but not in associated alias";
-    private static final String INCONSISTENT_ALIAS_NOT_IN_INDICES_MSG = "index is in alias but not associcated with search application";
 
     // The client to perform any operations on user indices (alias, ...).
     private final Client client;
@@ -207,42 +204,6 @@ public class SearchApplicationIndexService {
         }));
     }
 
-    /**
-     * Checks for consistency between the indices specified in the search application and the associated
-     * search application alias. Populates a map of inconsistent indices and the reason for inconsistency
-     * that can be used to generate Warning messages in response headers.
-     * @param app SearchApplication
-     * @param listener
-     */
-    public void checkAliasConsistency(SearchApplication app, ActionListener<Map<String, String>> listener) {
-        final Metadata metadata = clusterService.state().metadata();
-        final String searchAliasName = getSearchAliasName(app);
-        final Map<String, String> inconsistentIndices = new HashMap<>();
-
-        if (metadata.hasAlias(searchAliasName)) {
-            Set<String> indicesInAlias = metadata.aliasedIndices(searchAliasName).stream().map(Index::getName).collect(Collectors.toSet());
-            Set<String> configuredIndices = Set.of(app.indices());
-
-            Set<String> indicesInAliasButNotInSearchApp = findMissingIndices(indicesInAlias, configuredIndices);
-            indicesInAliasButNotInSearchApp.forEach(index -> inconsistentIndices.put(index, INCONSISTENT_ALIAS_NOT_IN_INDICES_MSG));
-
-            Set<String> indicesInSearchAppButNotInAlias = findMissingIndices(configuredIndices, indicesInAlias);
-            indicesInSearchAppButNotInAlias.forEach(index -> inconsistentIndices.put(index, INCONSISTENT_INDICES_NOT_IN_ALIAS_MSG));
-        } else {
-            for (String index : app.indices()) {
-                inconsistentIndices.put(index, INCONSISTENT_INDICES_NOT_IN_ALIAS_MSG);
-            }
-        }
-
-        listener.onResponse(inconsistentIndices);
-    }
-
-    private Set<String> findMissingIndices(Set<String> indices, Set<String> toExclude) {
-        Set<String> diff = new HashSet<>(indices);
-        diff.removeAll(toExclude);
-        return diff;
-    }
-
     private static String getSearchAliasName(SearchApplication app) {
         return app.name();
     }

+ 13 - 21
x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/action/TransportGetSearchApplicationAction.java

@@ -46,26 +46,18 @@ public class TransportGetSearchApplicationAction extends HandledTransportAction<
         GetSearchApplicationAction.Request request,
         ActionListener<GetSearchApplicationAction.Response> listener
     ) {
-        systemIndexService.getSearchApplication(
-            request.getName(),
-            listener.delegateFailure(
-                (l, searchApplication) -> systemIndexService.checkAliasConsistency(searchApplication, l.safeMap(inconsistentIndices -> {
-                    for (String key : inconsistentIndices.keySet()) {
-                        HeaderWarning.addWarning(key + " " + inconsistentIndices.get(key));
-                    }
-                    if (searchApplication.hasStoredTemplate() == false) {
-                        HeaderWarning.addWarning(SearchApplication.NO_TEMPLATE_STORED_WARNING);
-                    }
-                    // Construct a new object to ensure we backfill the stored application with the default template
-                    return new GetSearchApplicationAction.Response(
-                        searchApplication.name(),
-                        searchApplication.indices(),
-                        searchApplication.analyticsCollectionName(),
-                        searchApplication.updatedAtMillis(),
-                        searchApplication.searchApplicationTemplateOrDefault()
-                    );
-                }))
-            )
-        );
+        systemIndexService.getSearchApplication(request.getName(), listener.map(searchApplication -> {
+            if (searchApplication.hasStoredTemplate() == false) {
+                HeaderWarning.addWarning(SearchApplication.NO_TEMPLATE_STORED_WARNING);
+            }
+            // Construct a new object to ensure we backfill the stored application with the default template
+            return new GetSearchApplicationAction.Response(
+                searchApplication.name(),
+                searchApplication.indices(),
+                searchApplication.analyticsCollectionName(),
+                searchApplication.updatedAtMillis(),
+                searchApplication.searchApplicationTemplateOrDefault()
+            );
+        }));
     }
 }

+ 5 - 7
x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/action/TransportQuerySearchApplicationAction.java

@@ -17,7 +17,6 @@ import org.elasticsearch.client.internal.Client;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
-import org.elasticsearch.common.logging.HeaderWarning;
 import org.elasticsearch.common.util.BigArrays;
 import org.elasticsearch.logging.LogManager;
 import org.elasticsearch.logging.Logger;
@@ -61,12 +60,11 @@ public class TransportQuerySearchApplicationAction extends HandledTransportActio
                 SearchSourceBuilder sourceBuilder = templateService.renderQuery(searchApplication, request.queryParams());
                 SearchRequest searchRequest = new SearchRequest(searchApplication.name()).source(sourceBuilder);
 
-                systemIndexService.checkAliasConsistency(searchApplication, l.delegateFailure((l2, inconsistentIndices) -> {
-                    for (String key : inconsistentIndices.keySet()) {
-                        HeaderWarning.addWarning(key + " " + inconsistentIndices.get(key));
-                    }
-                    client.execute(SearchAction.INSTANCE, searchRequest, l2);
-                }));
+                client.execute(
+                    SearchAction.INSTANCE,
+                    searchRequest,
+                    listener.delegateFailure((l2, searchResponse) -> l2.onResponse(searchResponse))
+                );
             } catch (Exception e) {
                 l.onFailure(e);
             }