Skip to content

Commit 30e36ff

Browse files
kderussoelasticsearchmachineMikep86
authored
Register action named writeables with indices (#136218)
* Register action named writeables with indices * [CI] Auto commit changes from spotless * Added multi-node YAML test with text similarity reranker and cluster stats * Push fix and tests * Cleanup based on PR feedback * Rename --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Mike Pellegrini <[email protected]>
1 parent 5ca8738 commit 30e36ff

File tree

6 files changed

+211
-2
lines changed

6 files changed

+211
-2
lines changed

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ public ReservedClusterStateService getReservedClusterStateService() {
11031103
return reservedClusterStateService;
11041104
}
11051105

1106-
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
1106+
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
11071107
return List.of(
11081108
new NamedWriteableRegistry.Entry(
11091109
ExtendedSearchUsageMetric.class,

server/src/main/java/org/elasticsearch/cluster/ClusterModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.cluster;
1111

12+
import org.elasticsearch.action.ActionModule;
1213
import org.elasticsearch.action.admin.indices.rollover.MetadataRolloverService;
1314
import org.elasticsearch.action.admin.indices.sampling.SamplingMetadata;
1415
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
@@ -321,6 +322,9 @@ public static List<Entry> getNamedWriteables() {
321322
// Streams
322323
registerProjectCustom(entries, StreamsMetadata.TYPE, StreamsMetadata::new, StreamsMetadata::readDiffFrom);
323324

325+
// Actions
326+
entries.addAll(ActionModule.getNamedWriteables());
327+
324328
return entries;
325329
}
326330

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import org.elasticsearch.gradle.util.GradleUtils
2+
3+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
4+
5+
dependencies {
6+
clusterPlugins project(':x-pack:plugin:inference:qa:test-service-plugin')
7+
}
8+
9+
tasks.named('yamlRestTest') {
10+
usesDefaultDistribution("to be triaged")
11+
maxParallelForks = 1
12+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference;
9+
10+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
11+
12+
import org.elasticsearch.client.Request;
13+
import org.elasticsearch.common.Strings;
14+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
15+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
16+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
17+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
18+
import org.junit.After;
19+
import org.junit.ClassRule;
20+
21+
import java.io.IOException;
22+
import java.util.List;
23+
import java.util.Map;
24+
25+
public class InferenceRestMultiNodeIT extends ESClientYamlSuiteTestCase {
26+
27+
public InferenceRestMultiNodeIT(final ClientYamlTestCandidate testCandidate) {
28+
super(testCandidate);
29+
}
30+
31+
@ClassRule
32+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
33+
.systemProperty("tests.seed", System.getProperty("tests.seed"))
34+
.setting("xpack.security.enabled", "false")
35+
.setting("xpack.security.http.ssl.enabled", "false")
36+
.setting("xpack.license.self_generated.type", "trial")
37+
.plugin("inference-service-test")
38+
.nodes(3)
39+
.distribution(DistributionType.DEFAULT)
40+
.build();
41+
42+
@Override
43+
protected String getTestRestCluster() {
44+
return cluster.getHttpAddresses();
45+
}
46+
47+
@ParametersFactory
48+
public static Iterable<Object[]> parameters() throws Exception {
49+
return ESClientYamlSuiteTestCase.createParameters();
50+
}
51+
52+
@After
53+
public void cleanup() throws Exception {
54+
for (var model : getAllModels()) {
55+
var inferenceId = model.get("inference_id");
56+
try {
57+
var endpoint = Strings.format("_inference/%s?force", inferenceId);
58+
adminClient().performRequest(new Request("DELETE", endpoint));
59+
} catch (Exception ex) {
60+
logger.warn(() -> "failed to delete inference endpoint " + inferenceId, ex);
61+
}
62+
}
63+
}
64+
65+
@SuppressWarnings("unchecked")
66+
static List<Map<String, Object>> getAllModels() throws IOException {
67+
var request = new Request("GET", "_inference/_all");
68+
var response = client().performRequest(request);
69+
return (List<Map<String, Object>>) entityAsMap(response).get("endpoints");
70+
}
71+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
setup:
2+
- requires:
3+
cluster_features: "search.usage.extended_data"
4+
reason: extended search usage data introduced in 9.2.0
5+
6+
- do:
7+
inference.put:
8+
task_type: rerank
9+
inference_id: my-rerank-model
10+
body: >
11+
{
12+
"service": "test_reranking_service",
13+
"service_settings": {
14+
"model_id": "my_model",
15+
"api_key": "abc64"
16+
},
17+
"task_settings": {
18+
}
19+
}
20+
21+
- do:
22+
inference.put:
23+
task_type: sparse_embedding
24+
inference_id: sparse-inference-id
25+
body: >
26+
{
27+
"service": "test_service",
28+
"service_settings": {
29+
"model": "my_model",
30+
"api_key": "abc64"
31+
},
32+
"task_settings": {
33+
}
34+
}
35+
36+
- do:
37+
indices.create:
38+
index: test-index
39+
body:
40+
mappings:
41+
properties:
42+
text:
43+
type: text
44+
copy_to: semantic_text_field
45+
topic:
46+
type: keyword
47+
subtopic:
48+
type: keyword
49+
inference_text_field:
50+
type: text
51+
semantic_text_field:
52+
type: semantic_text
53+
inference_id: sparse-inference-id
54+
chunking_settings:
55+
strategy: word
56+
max_chunk_size: 10
57+
overlap: 1
58+
59+
- do:
60+
index:
61+
index: test-index
62+
id: doc_2
63+
body:
64+
text: "The phases of the Moon come from the position of the Moon relative to the Earth and Sun."
65+
topic: [ "science" ]
66+
subtopic: [ "astronomy" ]
67+
inference_text_field: "0"
68+
refresh: true
69+
70+
- do:
71+
index:
72+
index: test-index
73+
id: doc_3
74+
body:
75+
text: "Sun Moon Lake is a lake in Nantou County, Taiwan. It is the largest lake in Taiwan."
76+
topic: [ "geography" ]
77+
inference_text_field: "1"
78+
refresh: true
79+
80+
- do:
81+
index:
82+
index: test-index
83+
id: doc_1
84+
body:
85+
text: "As seen from Earth, a solar eclipse happens when the Moon is directly between the Earth and the Sun."
86+
topic: [ "science" ]
87+
subtopic: [ "technology" ]
88+
inference_text_field: "-1"
89+
refresh: true
90+
91+
---
92+
"Reranking based on rescore_chunks is reflected in extended search usage stats":
93+
94+
- do:
95+
search:
96+
index: test-index
97+
body:
98+
track_total_hits: true
99+
fields: [ "text", "semantic_text_field", "topic" ]
100+
retriever:
101+
text_similarity_reranker:
102+
retriever:
103+
standard:
104+
query:
105+
match:
106+
topic:
107+
query: "science"
108+
rank_window_size: 10
109+
inference_id: my-rerank-model
110+
inference_text: "how often does the moon hide the sun?"
111+
field: semantic_text_field
112+
chunk_rescorer: {}
113+
size: 10
114+
115+
- do:
116+
cluster.stats: {}
117+
118+
- not_exists: _nodes.failures
119+
- exists: indices.search.extended.retrievers.text_similarity_reranker.chunk_rescorer
120+

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferenceFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class InferenceFeatures implements FeatureSpecification {
5252
private static final NodeFeature SEMANTIC_TEXT_FIELDS_CHUNKS_FORMAT = new NodeFeature("semantic_text.fields_chunks_format");
5353

5454
public static final NodeFeature INFERENCE_ENDPOINT_CACHE = new NodeFeature("inference.endpoint.cache");
55+
public static final NodeFeature SEARCH_USAGE_EXTENDED_DATA = new NodeFeature("search.usage.extended_data");
5556

5657
@Override
5758
public Set<NodeFeature> getFeatures() {
@@ -96,7 +97,8 @@ public Set<NodeFeature> getTestFeatures() {
9697
SemanticQueryBuilder.SEMANTIC_QUERY_FILTER_FIELD_CAPS_FIX,
9798
InterceptedInferenceQueryBuilder.NEW_SEMANTIC_QUERY_INTERCEPTORS,
9899
TEXT_SIMILARITY_RERANKER_SNIPPETS,
99-
ModelStats.SEMANTIC_TEXT_USAGE
100+
ModelStats.SEMANTIC_TEXT_USAGE,
101+
SEARCH_USAGE_EXTENDED_DATA
100102
)
101103
);
102104
testFeatures.addAll(getFeatures());

0 commit comments

Comments
 (0)