Skip to content

Commit 9948453

Browse files
Merge branch 'main' into 2025/10/08/ES-12631-enable-stats
2 parents a983080 + abb7c29 commit 9948453

File tree

17 files changed

+247
-374
lines changed

17 files changed

+247
-374
lines changed

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.io.IOException;
2525
import java.util.List;
26-
import java.util.Optional;
2726
import java.util.Set;
2827
import java.util.function.Predicate;
2928

@@ -39,12 +38,10 @@ public class RestSearchTemplateAction extends BaseRestHandler {
3938

4039
private final Predicate<NodeFeature> clusterSupportsFeature;
4140
private final Settings settings;
42-
private final boolean inCpsContext;
4341

4442
public RestSearchTemplateAction(Predicate<NodeFeature> clusterSupportsFeature, Settings settings) {
4543
this.clusterSupportsFeature = clusterSupportsFeature;
4644
this.settings = settings;
47-
this.inCpsContext = settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false);
4845
}
4946

5047
@Override
@@ -64,7 +61,7 @@ public String getName() {
6461

6562
@Override
6663
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
67-
if (inCpsContext) {
64+
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
6865
// accept but drop project_routing param until fully supported
6966
request.param("project_routing");
7067
}
@@ -76,9 +73,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
7673
request,
7774
null,
7875
clusterSupportsFeature,
79-
size -> searchRequest.source().size(size),
80-
// This endpoint is CPS-enabled so propagate the right value.
81-
Optional.of(inCpsContext)
76+
size -> searchRequest.source().size(size)
8277
);
8378

8479
// Creates the search template request

modules/reindex/src/main/java/org/elasticsearch/reindex/AbstractBulkByQueryRestHandler.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.io.IOException;
2828
import java.util.Map;
29-
import java.util.Optional;
3029
import java.util.function.Consumer;
3130
import java.util.function.Predicate;
3231

@@ -53,14 +52,7 @@ protected void parseInternalRequest(
5352
SearchRequest searchRequest = internal.getSearchRequest();
5453

5554
try (XContentParser parser = extractRequestSpecificFields(restRequest, bodyConsumers)) {
56-
RestSearchAction.parseSearchRequest(
57-
searchRequest,
58-
restRequest,
59-
parser,
60-
clusterSupportsFeature,
61-
size -> failOnSizeSpecified(),
62-
Optional.empty()
63-
);
55+
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, clusterSupportsFeature, size -> failOnSizeSpecified());
6456
}
6557

6658
searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size()));

server/src/main/java/org/elasticsearch/cluster/routing/allocation/WriteLoadConstraintMonitor.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.common.Strings;
2222
import org.elasticsearch.common.settings.ClusterSettings;
2323
import org.elasticsearch.common.util.set.Sets;
24+
import org.elasticsearch.core.TimeValue;
2425
import org.elasticsearch.gateway.GatewayService;
2526
import org.elasticsearch.threadpool.ThreadPool;
2627

@@ -62,12 +63,12 @@ public WriteLoadConstraintMonitor(
6263
public void onNewInfo(ClusterInfo clusterInfo) {
6364
final ClusterState state = clusterStateSupplier.get();
6465
if (state.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
65-
logger.debug("skipping monitor as the cluster state is not recovered yet");
66+
logger.trace("skipping monitor as the cluster state is not recovered yet");
6667
return;
6768
}
6869

6970
if (writeLoadConstraintSettings.getWriteLoadConstraintEnabled().notFullyEnabled()) {
70-
logger.debug("skipping monitor because the write load decider is not fully enabled");
71+
logger.trace("skipping monitor because the write load decider is not fully enabled");
7172
return;
7273
}
7374

@@ -85,7 +86,7 @@ public void onNewInfo(ClusterInfo clusterInfo) {
8586
});
8687

8788
if (nodeIdsExceedingLatencyThreshold.isEmpty()) {
88-
logger.debug("No hot-spotting nodes detected");
89+
logger.trace("No hot-spotting nodes detected");
8990
return;
9091
}
9192

@@ -94,12 +95,22 @@ public void onNewInfo(ClusterInfo clusterInfo) {
9495
final boolean haveCalledRerouteRecently = timeSinceLastRerouteMillis < writeLoadConstraintSettings.getMinimumRerouteInterval()
9596
.millis();
9697

98+
// We know that there is at least one hot-spotting node if we've reached this code. Now check whether there are any new hot-spots
99+
// or hot-spots that are persisting and need further balancing work.
97100
if (haveCalledRerouteRecently == false
98101
|| Sets.difference(nodeIdsExceedingLatencyThreshold, lastSetOfHotSpottedNodes).isEmpty() == false) {
99102
if (logger.isDebugEnabled()) {
100103
logger.debug(
101-
"Found {} exceeding the write thread pool queue latency threshold ({} total), triggering reroute",
104+
"""
105+
Nodes [{}] are hot-spotting, of {} total cluster nodes. Reroute for hot-spotting {}. \
106+
Previously hot-spotting nodes are [{}]. The write thread pool queue latency threshold is [{}]. Triggering reroute.
107+
""",
102108
nodeSummary(nodeIdsExceedingLatencyThreshold),
109+
state.nodes().size(),
110+
lastRerouteTimeMillis == 0
111+
? "has never previously been called"
112+
: "was last called [" + TimeValue.timeValueMillis(timeSinceLastRerouteMillis) + "] ago",
113+
nodeSummary(lastSetOfHotSpottedNodes),
103114
state.nodes().size()
104115
);
105116
}
@@ -115,7 +126,10 @@ public void onNewInfo(ClusterInfo clusterInfo) {
115126
lastRerouteTimeMillis = currentTimeMillisSupplier.getAsLong();
116127
lastSetOfHotSpottedNodes = nodeIdsExceedingLatencyThreshold;
117128
} else {
118-
logger.debug("Not calling reroute because we called reroute recently and there are no new hot spots");
129+
logger.debug(
130+
"Not calling reroute because we called reroute [{}] ago and there are no new hot spots",
131+
TimeValue.timeValueMillis(timeSinceLastRerouteMillis)
132+
);
119133
}
120134
}
121135

server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.Arrays;
4444
import java.util.List;
4545
import java.util.Locale;
46-
import java.util.Optional;
4746
import java.util.Set;
4847
import java.util.function.IntConsumer;
4948
import java.util.function.Predicate;
@@ -69,7 +68,6 @@ public class RestSearchAction extends BaseRestHandler {
6968
private final SearchUsageHolder searchUsageHolder;
7069
private final Predicate<NodeFeature> clusterSupportsFeature;
7170
private final Settings settings;
72-
private final boolean inCpsContext;
7371

7472
public RestSearchAction(SearchUsageHolder searchUsageHolder, Predicate<NodeFeature> clusterSupportsFeature) {
7573
this(searchUsageHolder, clusterSupportsFeature, null);
@@ -79,7 +77,6 @@ public RestSearchAction(SearchUsageHolder searchUsageHolder, Predicate<NodeFeatu
7977
this.searchUsageHolder = searchUsageHolder;
8078
this.clusterSupportsFeature = clusterSupportsFeature;
8179
this.settings = settings;
82-
this.inCpsContext = settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false);
8380
}
8481

8582
@Override
@@ -112,7 +109,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
112109
// this might be set by old clients
113110
request.param("min_compatible_shard_node");
114111

115-
if (inCpsContext) {
112+
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
116113
// accept but drop project_routing param until fully supported
117114
request.param("project_routing");
118115
}
@@ -131,16 +128,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
131128
*/
132129
IntConsumer setSize = size -> searchRequest.source().size(size);
133130
request.withContentOrSourceParamParserOrNull(
134-
parser -> parseSearchRequest(
135-
searchRequest,
136-
request,
137-
parser,
138-
clusterSupportsFeature,
139-
setSize,
140-
searchUsageHolder,
141-
// This endpoint is CPS-enabled so propagate the right value.
142-
Optional.of(inCpsContext)
143-
)
131+
parser -> parseSearchRequest(searchRequest, request, parser, clusterSupportsFeature, setSize, searchUsageHolder)
144132
);
145133

146134
return channel -> {
@@ -158,23 +146,15 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
158146
* parameter
159147
* @param clusterSupportsFeature used to check if certain features are available in this cluster
160148
* @param setSize how the size url parameter is handled. {@code udpate_by_query} and regular search differ here.
161-
* @param inCpsContext specifies if we're in CPS context.
162-
* <br>
163-
* true - the endpoint that's invoking this method is CPS-enabled and in a CPS/Serverless context.
164-
* <br>
165-
* false - the endpoint that's invoking this method is CPS-enabled but not in a CPS/Serverless context.
166-
* <br>
167-
* Optional.empty - the endpoint is not CPS-enabled irrespective of the environment.
168149
*/
169150
public static void parseSearchRequest(
170151
SearchRequest searchRequest,
171152
RestRequest request,
172153
XContentParser requestContentParser,
173154
Predicate<NodeFeature> clusterSupportsFeature,
174-
IntConsumer setSize,
175-
Optional<Boolean> inCpsContext
155+
IntConsumer setSize
176156
) throws IOException {
177-
parseSearchRequest(searchRequest, request, requestContentParser, clusterSupportsFeature, setSize, null, inCpsContext);
157+
parseSearchRequest(searchRequest, request, requestContentParser, clusterSupportsFeature, setSize, null);
178158
}
179159

180160
/**
@@ -187,22 +167,14 @@ public static void parseSearchRequest(
187167
* @param clusterSupportsFeature used to check if certain features are available in this cluster
188168
* @param setSize how the size url parameter is handled. {@code udpate_by_query} and regular search differ here.
189169
* @param searchUsageHolder the holder of search usage stats
190-
* @param inCpsContext specifies if we're in CPS context.
191-
* <br>
192-
* true - the endpoint that's invoking this method is CPS-enabled and in a CPS/Serverless context.
193-
* <br>
194-
* false - the endpoint that's invoking this method is CPS-enabled but not in a CPS/Serverless context.
195-
* <br>
196-
* Optional.empty - the endpoint is not CPS-enabled irrespective of the environment.
197170
*/
198171
public static void parseSearchRequest(
199172
SearchRequest searchRequest,
200173
RestRequest request,
201174
@Nullable XContentParser requestContentParser,
202175
Predicate<NodeFeature> clusterSupportsFeature,
203176
IntConsumer setSize,
204-
@Nullable SearchUsageHolder searchUsageHolder,
205-
Optional<Boolean> inCpsContext
177+
@Nullable SearchUsageHolder searchUsageHolder
206178
) throws IOException {
207179
if (searchRequest.source() == null) {
208180
searchRequest.source(new SearchSourceBuilder());
@@ -257,17 +229,9 @@ public static void parseSearchRequest(
257229
if (searchRequest.pointInTimeBuilder() != null) {
258230
preparePointInTime(searchRequest, request);
259231
} else {
260-
if (inCpsContext.orElse(false)) {
261-
// We're in CPS environment. MRT should not be settable by the user.
262-
if (request.hasParam("ccs_minimize_roundtrips")) {
263-
throw new IllegalArgumentException("Setting ccs_minimize_roundtrips is not supported in cross-project search context");
264-
}
265-
} else {
266-
// Either we're in non-CPS environment or the endpoint isn't CPS enabled, so parse what's in the request.
267-
searchRequest.setCcsMinimizeRoundtrips(
268-
request.paramAsBoolean("ccs_minimize_roundtrips", searchRequest.isCcsMinimizeRoundtrips())
269-
);
270-
}
232+
searchRequest.setCcsMinimizeRoundtrips(
233+
request.paramAsBoolean("ccs_minimize_roundtrips", searchRequest.isCcsMinimizeRoundtrips())
234+
);
271235
}
272236
if (request.paramAsBoolean("force_synthetic_source", false)) {
273237
searchRequest.setForceSyntheticSource(true);

server/src/test/java/org/elasticsearch/cluster/routing/allocation/WriteLoadConstraintMonitorTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void testRerouteIsCalledWhenAHotSpotIsDetected() {
6262
}
6363

6464
@TestLogging(
65-
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:DEBUG",
65+
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:TRACE",
6666
reason = "ensure we're skipping reroute for the right reason"
6767
)
6868
public void testRerouteIsNotCalledWhenStateIsNotRecovered() {
@@ -81,7 +81,7 @@ public void testRerouteIsNotCalledWhenStateIsNotRecovered() {
8181
new MockLog.SeenEventExpectation(
8282
"don't reroute due to global block",
8383
WriteLoadConstraintMonitor.class.getCanonicalName(),
84-
Level.DEBUG,
84+
Level.TRACE,
8585
"skipping monitor as the cluster state is not recovered yet"
8686
)
8787
);
@@ -93,7 +93,7 @@ public void testRerouteIsNotCalledWhenStateIsNotRecovered() {
9393
}
9494

9595
@TestLogging(
96-
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:DEBUG",
96+
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:TRACE",
9797
reason = "ensure we're skipping reroute for the right reason"
9898
)
9999
public void testRerouteIsNotCalledWhenDeciderIsNotEnabled() {
@@ -117,7 +117,7 @@ public void testRerouteIsNotCalledWhenDeciderIsNotEnabled() {
117117
new MockLog.SeenEventExpectation(
118118
"don't reroute due to decider being disabled",
119119
WriteLoadConstraintMonitor.class.getCanonicalName(),
120-
Level.DEBUG,
120+
Level.TRACE,
121121
"skipping monitor because the write load decider is not fully enabled"
122122
)
123123
);
@@ -129,7 +129,7 @@ public void testRerouteIsNotCalledWhenDeciderIsNotEnabled() {
129129
}
130130

131131
@TestLogging(
132-
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:DEBUG",
132+
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:TRACE",
133133
reason = "ensure we're skipping reroute for the right reason"
134134
)
135135
public void testRerouteIsNotCalledWhenNoNodesAreHotSpotting() {
@@ -146,7 +146,7 @@ public void testRerouteIsNotCalledWhenNoNodesAreHotSpotting() {
146146
new MockLog.SeenEventExpectation(
147147
"don't reroute due to no nodes hot-spotting",
148148
WriteLoadConstraintMonitor.class.getCanonicalName(),
149-
Level.DEBUG,
149+
Level.TRACE,
150150
"No hot-spotting nodes detected"
151151
)
152152
);
@@ -196,7 +196,7 @@ public void testRerouteIsNotCalledAgainBeforeMinimumIntervalHasPassed() {
196196
"don't reroute due to reroute being called recently",
197197
WriteLoadConstraintMonitor.class.getCanonicalName(),
198198
Level.DEBUG,
199-
"Not calling reroute because we called reroute recently and there are no new hot spots"
199+
"Not calling reroute because we called reroute * ago and there are no new hot spots"
200200
)
201201
);
202202
writeLoadConstraintMonitor.onNewInfo(testState.clusterInfo);
@@ -213,7 +213,7 @@ public void testRerouteIsNotCalledAgainBeforeMinimumIntervalHasPassed() {
213213
}
214214

215215
@TestLogging(
216-
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:DEBUG",
216+
value = "org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintMonitor:TRACE",
217217
reason = "ensure we're skipping reroute for the right reason"
218218
)
219219
public void testRerouteIsCalledBeforeMinimumIntervalHasPassedIfNewNodesBecomeHotSpotted() {

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public enum FeatureFlag {
2525
"es.index_dimensions_tsid_optimization_feature_flag_enabled=true",
2626
Version.fromString("9.2.0"),
2727
null
28-
),
29-
ELASTIC_RERANKER_CHUNKING("es.elastic_reranker_chunking_long_documents=true", Version.fromString("9.2.0"), null);
28+
);
3029

3130
public final String systemProperty;
3231
public final Version from;

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/RestSubmitAsyncSearchAction.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.IOException;
2525
import java.util.Collections;
2626
import java.util.List;
27-
import java.util.Optional;
2827
import java.util.Set;
2928
import java.util.function.IntConsumer;
3029
import java.util.function.Predicate;
@@ -40,7 +39,6 @@ public final class RestSubmitAsyncSearchAction extends BaseRestHandler {
4039
private final SearchUsageHolder searchUsageHolder;
4140
private final Predicate<NodeFeature> clusterSupportsFeature;
4241
private final Settings settings;
43-
private final boolean inCpsContext;
4442

4543
public RestSubmitAsyncSearchAction(SearchUsageHolder searchUsageHolder, Predicate<NodeFeature> clusterSupportsFeature) {
4644
this(searchUsageHolder, clusterSupportsFeature, null);
@@ -54,7 +52,6 @@ public RestSubmitAsyncSearchAction(
5452
this.searchUsageHolder = searchUsageHolder;
5553
this.clusterSupportsFeature = clusterSupportsFeature;
5654
this.settings = settings;
57-
this.inCpsContext = settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false);
5855
}
5956

6057
@Override
@@ -74,10 +71,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
7471
}
7572
SubmitAsyncSearchRequest submit = new SubmitAsyncSearchRequest();
7673

77-
if (inCpsContext) {
74+
if (settings != null && settings.getAsBoolean("serverless.cross_project.enabled", false)) {
7875
// accept but drop project_routing param until fully supported
7976
request.param("project_routing");
80-
submit.getSearchRequest().setCcsMinimizeRoundtrips(true);
8177
}
8278

8379
IntConsumer setSize = size -> submit.getSearchRequest().source().size(size);
@@ -86,16 +82,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
8682
// them as supported. We rely on SubmitAsyncSearchRequest#validate to fail in case they are set.
8783
// Note that ccs_minimize_roundtrips is also set this way, which is a supported option.
8884
request.withContentOrSourceParamParserOrNull(
89-
parser -> parseSearchRequest(
90-
submit.getSearchRequest(),
91-
request,
92-
parser,
93-
clusterSupportsFeature,
94-
setSize,
95-
searchUsageHolder,
96-
// This endpoint is CPS-enabled so propagate the right value.
97-
Optional.of(inCpsContext)
98-
)
85+
parser -> parseSearchRequest(submit.getSearchRequest(), request, parser, clusterSupportsFeature, setSize, searchUsageHolder)
9986
);
10087

10188
if (request.hasParam("wait_for_completion_timeout")) {

0 commit comments

Comments
 (0)