Skip to content

Commit 356a349

Browse files
authored
Merge branch 'main' into cluster_info_for_write_decider
2 parents 0853c8e + 63258f4 commit 356a349

File tree

10 files changed

+389
-95
lines changed

10 files changed

+389
-95
lines changed

docs/reference/query-languages/esql/_snippets/commands/layout/completion.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,39 @@ including:
4646
**Requirements**
4747

4848
To use this command, you must deploy your LLM model in Elasticsearch as
49-
an [inference endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) with the
49+
an [inference endpoint](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put) with the
5050
task type `completion`.
5151

52+
#### Handling timeouts
53+
54+
`COMPLETION` commands may time out when processing large datasets or complex prompts. The default timeout is 10 minutes, but you can increase this limit if necessary.
55+
56+
How you increase the timeout depends on your deployment type:
57+
58+
::::{tab-set}
59+
:::{tab-item} {{ech}}
60+
* You can adjust {{es}} settings in the [Elastic Cloud Console](docs-content://deploy-manage/deploy/elastic-cloud/edit-stack-settings.md)
61+
* You can also adjust the `search.default_search_timeout` cluster setting using [Kibana's Advanced settings](kibana://reference/advanced-settings.md#kibana-search-settings)
62+
:::
63+
64+
:::{tab-item} Self-managed
65+
* You can configure at the cluster level by setting `search.default_search_timeout` in `elasticsearch.yml` or updating via [Cluster Settings API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-settings)
66+
* You can also adjust the `search:timeout` setting using [Kibana's Advanced settings](kibana://reference/advanced-settings.md#kibana-search-settings)
67+
* Alternatively, you can add timeout parameters to individual queries
68+
:::
69+
70+
:::{tab-item} {{serverless-full}}
71+
* Requires a manual override from Elastic Support because you cannot modify timeout settings directly
72+
:::
73+
::::
74+
75+
If you don't want to increase the timeout limit, try the following:
76+
77+
* Reduce data volume with `LIMIT` or more selective filters before the `COMPLETION` command
78+
* Split complex operations into multiple simpler queries
79+
* Configure your HTTP client's response timeout (Refer to [HTTP client configuration](/reference/elasticsearch/configuration-reference/networking-settings.md#_http_client_configuration))
80+
81+
5282
**Examples**
5383

5484
Use the default column name (results stored in `completion` column):

muted-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ tests:
608608
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldIndexTypeUpdateIT
609609
method: testDenseVectorMappingUpdate {initialType=int4_flat updateType=hnsw}
610610
issue: https://github.com/elastic/elasticsearch/issues/132150
611+
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldIndexTypeUpdateIT
612+
method: testDenseVectorMappingUpdate {initialType=int8_flat updateType=bbq_flat}
613+
issue: https://github.com/elastic/elasticsearch/issues/132151
614+
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldIndexTypeUpdateIT
615+
method: "testDenseVectorMappingUpdate {initialType=bbq_hnsw updateType=bbq_disk #2}"
616+
issue: https://github.com/elastic/elasticsearch/issues/132152
611617

612618
# Examples:
613619
#
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.cluster.project;
11+
12+
import org.elasticsearch.cluster.ClusterChangedEvent;
13+
import org.elasticsearch.cluster.metadata.ProjectId;
14+
import org.elasticsearch.cluster.service.ClusterService;
15+
16+
import java.util.function.Consumer;
17+
18+
/**
19+
* Utility class to make it easy to run a block of code whenever a project is deleted (e.g. to cleanup cache entries)
20+
*/
21+
public class ProjectDeletedListener {
22+
23+
private final Consumer<ProjectId> consumer;
24+
25+
public ProjectDeletedListener(Consumer<ProjectId> consumer) {
26+
this.consumer = consumer;
27+
}
28+
29+
public void attach(ClusterService clusterService) {
30+
clusterService.addListener(event -> {
31+
final ClusterChangedEvent.ProjectsDelta delta = event.projectDelta();
32+
delta.removed().forEach(consumer);
33+
});
34+
}
35+
36+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.cluster.project;
11+
12+
import org.elasticsearch.cluster.ClusterName;
13+
import org.elasticsearch.cluster.ClusterState;
14+
import org.elasticsearch.cluster.metadata.Metadata;
15+
import org.elasticsearch.cluster.metadata.ProjectId;
16+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
17+
import org.elasticsearch.cluster.routing.GlobalRoutingTableTestHelper;
18+
import org.elasticsearch.cluster.routing.RoutingTable;
19+
import org.elasticsearch.cluster.service.ClusterService;
20+
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
21+
import org.elasticsearch.test.ClusterServiceUtils;
22+
import org.elasticsearch.test.ESTestCase;
23+
24+
import java.util.HashSet;
25+
import java.util.List;
26+
import java.util.Set;
27+
28+
import static org.hamcrest.Matchers.equalTo;
29+
30+
public class ProjectDeletedListenerTests extends ESTestCase {
31+
32+
public void testInvocation() {
33+
final List<ProjectId> existingProjects = randomList(5, 15, ESTestCase::randomUniqueProjectId);
34+
35+
try (ClusterService clusterService = ClusterServiceUtils.createClusterService(new DeterministicTaskQueue().getThreadPool())) {
36+
final ClusterState.Builder csBuilder = ClusterState.builder(ClusterName.DEFAULT);
37+
existingProjects.forEach(p -> csBuilder.putProjectMetadata(ProjectMetadata.builder(p).build()));
38+
final ClusterState cs0 = csBuilder.build();
39+
40+
ClusterServiceUtils.setState(clusterService, cs0);
41+
42+
final Set<ProjectId> notifiedProjects = new HashSet<>();
43+
var pdl = new ProjectDeletedListener(notifiedProjects::add);
44+
pdl.attach(clusterService);
45+
46+
final Set<ProjectId> projectsToDelete = Set.copyOf(
47+
randomSubsetOf(randomIntBetween(1, existingProjects.size() / 2), existingProjects)
48+
);
49+
final List<ProjectId> projectsToCreate = randomList(0, 3, ESTestCase::randomUniqueProjectId);
50+
51+
final var mdBuilder = Metadata.builder(cs0.metadata());
52+
projectsToDelete.forEach(mdBuilder::removeProject);
53+
projectsToCreate.forEach(p -> mdBuilder.put(ProjectMetadata.builder(p).build()));
54+
var md = mdBuilder.build();
55+
var cs1 = ClusterState.builder(cs0)
56+
.metadata(md)
57+
.routingTable(GlobalRoutingTableTestHelper.buildRoutingTable(md, RoutingTable.Builder::addAsNew))
58+
.build();
59+
ClusterServiceUtils.setState(clusterService, cs1);
60+
61+
assertThat(notifiedProjects, equalTo(projectsToDelete));
62+
}
63+
}
64+
65+
}

test/framework/src/main/java/org/elasticsearch/cluster/project/TestProjectResolvers.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020
import java.util.Collection;
2121
import java.util.Objects;
22+
import java.util.function.Supplier;
2223

2324
/**
2425
* An implementation of {@link ProjectResolver} that handles multiple projects for testing purposes. Not usable in production
2526
*/
2627
public final class TestProjectResolvers {
2728

28-
public static final ProjectResolver DEFAULT_PROJECT_ONLY = singleProject(Metadata.DEFAULT_PROJECT_ID, true);
29+
public static final ProjectResolver DEFAULT_PROJECT_ONLY = singleProject(() -> Metadata.DEFAULT_PROJECT_ID, true);
2930

3031
/**
3132
* @return a ProjectResolver that must only be used in a cluster context. It throws in single project related methods.
@@ -131,6 +132,14 @@ public static ProjectResolver alwaysThrow() {
131132
* The ProjectResolver can work with cluster state containing multiple projects and its supportsMultipleProjects returns true.
132133
*/
133134
public static ProjectResolver singleProject(ProjectId projectId) {
135+
return singleProject(() -> projectId, false);
136+
}
137+
138+
/**
139+
* This method returns a ProjectResolver that gives back the specified project-id when its getProjectId method is called.
140+
* The ProjectResolver can work with cluster state containing multiple projects and its supportsMultipleProjects returns true.
141+
*/
142+
public static ProjectResolver singleProject(Supplier<ProjectId> projectId) {
134143
return singleProject(projectId, false);
135144
}
136145

@@ -140,11 +149,11 @@ public static ProjectResolver singleProject(ProjectId projectId) {
140149
* In addition, the ProjectResolvers returns false for supportsMultipleProjects.
141150
*/
142151
public static ProjectResolver singleProjectOnly(ProjectId projectId) {
143-
return singleProject(projectId, true);
152+
return singleProject(() -> projectId, true);
144153
}
145154

146-
private static ProjectResolver singleProject(ProjectId projectId, boolean only) {
147-
Objects.requireNonNull(projectId);
155+
private static ProjectResolver singleProject(Supplier<ProjectId> projectIdSupplier, boolean only) {
156+
Objects.requireNonNull(projectIdSupplier);
148157
return new ProjectResolver() {
149158

150159
@Override
@@ -157,7 +166,7 @@ public ProjectMetadata getProjectMetadata(Metadata metadata) {
157166

158167
@Override
159168
public ProjectId getProjectId() {
160-
return projectId;
169+
return projectIdSupplier.get();
161170
}
162171

163172
@Override
@@ -170,6 +179,7 @@ public Collection<ProjectId> getProjectIds(ClusterState clusterState) {
170179

171180
@Override
172181
public <E extends Exception> void executeOnProject(ProjectId otherProjectId, CheckedRunnable<E> body) throws E {
182+
final ProjectId projectId = projectIdSupplier.get();
173183
if (projectId.equals(otherProjectId)) {
174184
body.run();
175185
} else {

0 commit comments

Comments
 (0)