-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve final response headers in asynchronous search (#54349)
This change adds the response headers of the original search request in the stored response in order to be able to restore them when retrieving a result from the async-search index. It also ensures that response headers are preserved for users that retrieve a final response on a running search task. Partial response can eventually return response headers too but this change only ensures that they are present when the response if final. Relates #33936
- Loading branch information
Showing
12 changed files
with
360 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import org.elasticsearch.gradle.info.BuildParams | ||
|
||
apply plugin: 'elasticsearch.testclusters' | ||
apply plugin: 'elasticsearch.esplugin' | ||
|
||
esplugin { | ||
description 'Deprecated query plugin' | ||
classname 'org.elasticsearch.query.DeprecatedQueryPlugin' | ||
} | ||
|
||
restResources { | ||
restApi { | ||
includeCore '_common', 'indices', 'index' | ||
includeXpack 'async_search' | ||
} | ||
} | ||
|
||
testClusters.integTest { | ||
testDistribution = 'DEFAULT' | ||
// add the deprecated query plugin | ||
plugin file(project(':x-pack:plugin:async-search:qa:rest').tasks.bundlePlugin.archiveFile) | ||
setting 'xpack.security.enabled', 'false' | ||
} | ||
|
||
test.enabled = false | ||
|
||
check.dependsOn integTest |
75 changes: 75 additions & 0 deletions
75
...in/async-search/qa/rest/src/main/java/org/elasticsearch/query/DeprecatedQueryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.query; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.lucene.search.MatchAllDocsQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.query.AbstractQueryBuilder; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
|
||
import java.io.IOException; | ||
|
||
public class DeprecatedQueryBuilder extends AbstractQueryBuilder<DeprecatedQueryBuilder> { | ||
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger("Deprecated")); | ||
|
||
public static final String NAME = "deprecated"; | ||
|
||
public DeprecatedQueryBuilder() {} | ||
|
||
DeprecatedQueryBuilder(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
protected void doWriteTo(StreamOutput out) {} | ||
|
||
@Override | ||
protected void doXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(NAME); | ||
builder.endObject(); | ||
} | ||
|
||
private static final ObjectParser<DeprecatedQueryBuilder, Void> PARSER = new ObjectParser<>(NAME, DeprecatedQueryBuilder::new); | ||
|
||
public static DeprecatedQueryBuilder fromXContent(XContentParser parser) { | ||
try { | ||
PARSER.apply(parser, null); | ||
return new DeprecatedQueryBuilder(); | ||
} catch (IllegalArgumentException e) { | ||
throw new ParsingException(parser.getTokenLocation(), e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
protected Query doToQuery(QueryShardContext context) { | ||
deprecationLogger.deprecated("[deprecated] query"); | ||
return new MatchAllDocsQuery(); | ||
} | ||
|
||
@Override | ||
protected boolean doEquals(DeprecatedQueryBuilder other) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected int doHashCode() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return NAME; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...gin/async-search/qa/rest/src/main/java/org/elasticsearch/query/DeprecatedQueryPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.query; | ||
|
||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.SearchPlugin; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
||
public class DeprecatedQueryPlugin extends Plugin implements SearchPlugin { | ||
|
||
public DeprecatedQueryPlugin() {} | ||
|
||
@Override | ||
public List<QuerySpec<?>> getQueries() { | ||
return singletonList(new QuerySpec<>("deprecated", DeprecatedQueryBuilder::new, p -> DeprecatedQueryBuilder.fromXContent(p))); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
x-pack/plugin/async-search/qa/rest/src/test/java/org/elasticsearch/qa/AsyncSearchRestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.qa; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; | ||
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; | ||
|
||
public class AsyncSearchRestIT extends ESClientYamlSuiteTestCase { | ||
|
||
public AsyncSearchRestIT(final ClientYamlTestCandidate testCandidate) { | ||
super(testCandidate); | ||
} | ||
|
||
@ParametersFactory | ||
public static Iterable<Object[]> parameters() throws Exception { | ||
return ESClientYamlSuiteTestCase.createParameters(); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...sync-search/qa/rest/src/test/resources/rest-api-spec/test/async-search/10_deprecation.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
setup: | ||
- do: | ||
indices.create: | ||
index: test-1 | ||
body: | ||
settings: | ||
number_of_shards: "2" | ||
|
||
- do: | ||
indices.create: | ||
index: test-2 | ||
body: | ||
settings: | ||
number_of_shards: "1" | ||
|
||
- do: | ||
indices.create: | ||
index: test-3 | ||
body: | ||
settings: | ||
number_of_shards: "3" | ||
|
||
- do: | ||
index: | ||
index: test-2 | ||
body: { max: 2 } | ||
|
||
- do: | ||
index: | ||
index: test-1 | ||
body: { max: 1 } | ||
|
||
- do: | ||
index: | ||
index: test-3 | ||
body: { max: 3 } | ||
|
||
- do: | ||
indices.refresh: {} | ||
|
||
--- | ||
"Deprecation when retrieved from task": | ||
- skip: | ||
features: "warnings" | ||
|
||
- do: | ||
warnings: | ||
- '[deprecated] query' | ||
async_search.submit: | ||
index: test-* | ||
wait_for_completion_timeout: 10s | ||
body: | ||
query: | ||
deprecated: {} | ||
|
||
- is_false: id | ||
- match: { is_partial: false } | ||
- length: { response.hits.hits: 3 } | ||
|
||
--- | ||
"Deprecation when retrieved from store": | ||
- skip: | ||
features: "warnings" | ||
|
||
- do: | ||
warnings: | ||
- '[deprecated] query' | ||
async_search.submit: | ||
index: test-* | ||
wait_for_completion_timeout: 10s | ||
keep_on_completion: true | ||
body: | ||
query: | ||
deprecated: {} | ||
|
||
- set: { id: id } | ||
- match: { is_partial: false } | ||
- length: { response.hits.hits: 3 } | ||
|
||
- do: | ||
warnings: | ||
- '[deprecated] query' | ||
async_search.get: | ||
id: "$id" | ||
|
||
- match: { is_partial: false } | ||
- length: { response.hits.hits: 3 } | ||
|
||
- do: | ||
async_search.delete: | ||
id: "$id" | ||
|
||
- match: { acknowledged: true } | ||
|
||
- do: | ||
catch: missing | ||
async_search.get: | ||
id: "$id" | ||
|
||
- do: | ||
catch: missing | ||
async_search.delete: | ||
id: "$id" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.