Skip to content

Commit ab4a406

Browse files
lukewhitingCopilotelasticsearchmachine
authored
Add deprecation notice for max_size rollover condition (#135765)
* Add deprecation notice for max_size rollover condition * Update docs/changelog/135765.yaml * Remove erroneous copyright message * Fill out changelog * Make deprecation messages more tidy and informative * Remove the copyright message again * PR changes * Update x-pack/plugin/ilm/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ilm/10_basic.yml Co-authored-by: Copilot <[email protected]> * Update x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java Co-authored-by: Copilot <[email protected]> * Fix logger class ref * [CI] Auto commit changes from spotless * Revert PutLifecycleMetadataService --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 5da01ac commit ab4a406

File tree

8 files changed

+244
-3
lines changed

8 files changed

+244
-3
lines changed

docs/changelog/135765.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pr: 135765
2+
summary: Add deprecation notice for `max_size` rollover condition
3+
area: "ILM+SLM"
4+
type: deprecation
5+
issues:
6+
- 130737
7+
deprecation:
8+
title: Add deprecation notice for `max_size` rollover condition
9+
area: "REST API"
10+
details: We have deprecated the `max_size` rollover condition, in favour of `max_primary_shard_size`, when used in `PUT /_ilm/policy/{name}` and `POST /{index}/_rollover` endpoints
11+
impact: Users can continue to use this condition however a warning will be issued via the response headers and in the server logs. The condition may be removed fully in a later version of Elasticsearch.

rest-api-spec/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,6 @@ tasks.named("yamlRestCompatTestTransform").configure ({ task ->
100100
task.skipTest("logsdb/10_settings/end time not allowed in logs mode", "we don't validate for index_mode=tsdb when setting start_date/end_date anymore")
101101
task.skipTest("tsdb/10_settings/set start_time and end_time without timeseries mode", "we don't validate for index_mode=tsdb when setting start_date/end_date anymore")
102102
task.skipTest("tsdb/10_settings/set start_time, end_time and routing_path via put settings api without time_series mode", "we don't validate for index_mode=tsdb when setting start_date/end_date anymore")
103+
// Expected deprecation warning to compat yaml tests:
104+
task.addAllowedWarningRegex("Use of the \\[max_size\\] rollover condition has been deprecated in favour of the \\[max_primary_shard_size\\] condition and will be removed in a later version")
103105
})

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.rollover/30_max_size_condition.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,82 @@
11
---
22
"Rollover with max_size condition":
3+
- requires:
4+
capabilities:
5+
- method: POST
6+
path: /logs_search/_rollover
7+
capabilities: [ max_size_deprecation ]
8+
test_runner_features: [ warnings, capabilities ]
9+
reason: Capability required to run test
10+
11+
# create index with alias and replica
12+
- do:
13+
indices.create:
14+
index: logs-1
15+
wait_for_active_shards: 1
16+
body:
17+
aliases:
18+
logs_search: {}
19+
20+
# index a document
21+
- do:
22+
index:
23+
index: logs-1
24+
id: "1"
25+
body: { "foo": "hello world" }
26+
refresh: true
27+
28+
# perform alias rollover with a large max_size, no action.
29+
- do:
30+
warnings:
31+
- 'Use of the [max_size] rollover condition has been deprecated in favour of the [max_primary_shard_size] condition and will be removed in a later version'
32+
indices.rollover:
33+
alias: "logs_search"
34+
wait_for_active_shards: 1
35+
body:
36+
conditions:
37+
max_size: 100mb
38+
39+
- match: { conditions: { "[max_size: 100mb]": false } }
40+
- match: { rolled_over: false }
41+
42+
# perform alias rollover with a small max_size, got action.
43+
- do:
44+
warnings:
45+
- 'Use of the [max_size] rollover condition has been deprecated in favour of the [max_primary_shard_size] condition and will be removed in a later version'
46+
indices.rollover:
47+
alias: "logs_search"
48+
wait_for_active_shards: 1
49+
body:
50+
conditions:
51+
max_size: 10b
52+
53+
- match: { conditions: { "[max_size: 10b]": true } }
54+
- match: { rolled_over: true }
55+
56+
# perform alias rollover on an empty index, no action.
57+
- do:
58+
warnings:
59+
- 'Use of the [max_size] rollover condition has been deprecated in favour of the [max_primary_shard_size] condition and will be removed in a later version'
60+
indices.rollover:
61+
alias: "logs_search"
62+
wait_for_active_shards: 1
63+
body:
64+
conditions:
65+
max_size: 1b
66+
67+
- match: { conditions: { "[max_size: 1b]": false } }
68+
- match: { rolled_over: false }
69+
70+
---
71+
"Rollover with max_size condition (BWC - Pre Deprecation)":
72+
- requires:
73+
test_runner_features: [ capabilities ]
74+
- skip:
75+
capabilities:
76+
- method: POST
77+
path: /logs_search/_rollover
78+
capabilities: [ max_size_deprecation ]
79+
reason: Capability must be missing to run test
380

481
# create index with alias and replica
582
- do:

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
1313
import org.elasticsearch.action.support.ActiveShardCount;
1414
import org.elasticsearch.client.internal.node.NodeClient;
15+
import org.elasticsearch.common.logging.DeprecationCategory;
16+
import org.elasticsearch.common.logging.DeprecationLogger;
1517
import org.elasticsearch.rest.BaseRestHandler;
1618
import org.elasticsearch.rest.RestRequest;
1719
import org.elasticsearch.rest.Scope;
@@ -30,6 +32,10 @@
3032
@ServerlessScope(Scope.PUBLIC)
3133
public class RestRolloverIndexAction extends BaseRestHandler {
3234

35+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(RestRolloverIndexAction.class);
36+
public static final String MAX_SIZE_DEPRECATION_MESSAGE = "Use of the [max_size] rollover condition has been deprecated in favour of "
37+
+ "the [max_primary_shard_size] condition and will be removed in a later version";
38+
3339
@Override
3440
public List<Route> routes() {
3541
return List.of(new Route(POST, "/{index}/_rollover"), new Route(POST, "/{index}/_rollover/{new_index}"));
@@ -42,7 +48,7 @@ public String getName() {
4248

4349
@Override
4450
public Set<String> supportedCapabilities() {
45-
return Set.of("return-404-on-missing-target", "index_expression_selectors");
51+
return Set.of("return-404-on-missing-target", "index_expression_selectors", "max_size_deprecation");
4652
}
4753

4854
@Override
@@ -55,6 +61,12 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
5561
rolloverIndexRequest.masterNodeTimeout(getMasterNodeTimeout(request));
5662
rolloverIndexRequest.getCreateIndexRequest()
5763
.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
64+
65+
// Check for deprecated conditions
66+
if (rolloverIndexRequest.getConditions().getMaxSize() != null) {
67+
DEPRECATION_LOGGER.warn(DeprecationCategory.API, "rollover-max-size-condition", MAX_SIZE_DEPRECATION_MESSAGE);
68+
}
69+
5870
return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).admin()
5971
.indices()
6072
.rolloverIndex(rolloverIndexRequest, new RestToXContentListener<>(channel));

x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ilm/CCRIndexLifecycleIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.http.util.EntityUtils;
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
14+
import org.apache.logging.log4j.message.ParameterizedMessage;
1415
import org.elasticsearch.client.Request;
1516
import org.elasticsearch.client.Response;
1617
import org.elasticsearch.client.ResponseException;
@@ -31,6 +32,7 @@
3132
import org.elasticsearch.xpack.core.ilm.Phase;
3233
import org.elasticsearch.xpack.core.ilm.UnfollowAction;
3334
import org.elasticsearch.xpack.core.ilm.WaitUntilTimeSeriesEndTimePassesStep;
35+
import org.elasticsearch.xpack.ilm.action.RestPutLifecycleAction;
3436

3537
import java.io.IOException;
3638
import java.io.InputStream;
@@ -53,6 +55,7 @@
5355
public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
5456

5557
private static final Logger LOGGER = LogManager.getLogger(CCRIndexLifecycleIT.class);
58+
private static final String TEST_PHASE = "hot";
5659
private static final String TSDB_INDEX_TEMPLATE = """
5760
{
5861
"index_patterns": ["%s*"],
@@ -677,7 +680,7 @@ private static void putILMPolicy(String name, String maxSize, Integer maxDocs, T
677680
{
678681
builder.startObject("phases");
679682
{
680-
builder.startObject("hot");
683+
builder.startObject(TEST_PHASE);
681684
{
682685
builder.startObject("actions");
683686
{
@@ -733,6 +736,13 @@ private static void putILMPolicy(String name, String maxSize, Integer maxDocs, T
733736
}
734737
builder.endObject();
735738
request.setJsonEntity(Strings.toString(builder));
739+
if (maxSize != null) {
740+
request.setOptions(
741+
expectWarnings(
742+
ParameterizedMessage.format(RestPutLifecycleAction.MAX_SIZE_DEPRECATION_MESSAGE, new Object[] { TEST_PHASE })
743+
)
744+
);
745+
}
736746
assertOK(client().performRequest(request));
737747
}
738748

x-pack/plugin/ilm/qa/rest/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies {
88

99
restResources {
1010
restApi {
11-
include '_common', 'cluster', 'indices', 'index', 'snapshot', 'ilm', 'slm', 'health_report'
11+
include '_common', 'cluster', 'indices', 'index', 'snapshot', 'ilm', 'slm', 'health_report', 'capabilities'
1212
}
1313
}
1414

x-pack/plugin/ilm/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ilm/10_basic.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,99 @@ setup:
395395
}
396396
}
397397
}
398+
399+
---
400+
# This test checks that the deprecation warning is issued when a deprecated rollover condition is part of the policy
401+
# On both creation and update of an existing policy
402+
"Test Deprecated Condition On Policy Put / Update":
403+
- requires:
404+
test_runner_features: [ warnings, capabilities ]
405+
capabilities:
406+
- method: PUT
407+
path: /_ilm/policy/my_timeseries_lifecycle
408+
capabilities: [ max_size_deprecation ]
409+
reason: Capability must be present to run test
410+
411+
- do:
412+
warnings:
413+
- 'Use of the [max_size] rollover condition found in phase [hot]. This condition has been deprecated in favour of the [max_primary_shard_size] condition and will be removed in a later version'
414+
ilm.put_lifecycle:
415+
policy: "my_timeseries_lifecycle"
416+
body: |
417+
{
418+
"policy": {
419+
"phases": {
420+
"hot": {
421+
"actions": {
422+
"rollover": {
423+
"max_size": "50gb"
424+
}
425+
}
426+
}
427+
}
428+
}
429+
}
430+
431+
- do:
432+
ilm.get_lifecycle:
433+
policy: "my_timeseries_lifecycle"
434+
- match: { my_timeseries_lifecycle.version: 1 }
435+
- is_true: my_timeseries_lifecycle.modified_date
436+
- match: { my_timeseries_lifecycle.policy.phases.hot.actions.rollover.max_size: "50gb" }
437+
438+
# Create a policy with rollover but without max_size
439+
- do:
440+
ilm.put_lifecycle:
441+
policy: "my_timeseries_lifecycle_update"
442+
body: |
443+
{
444+
"policy": {
445+
"phases": {
446+
"hot": {
447+
"actions": {
448+
"rollover": {
449+
"max_docs": 1000
450+
}
451+
}
452+
}
453+
}
454+
}
455+
}
456+
457+
- do:
458+
ilm.get_lifecycle:
459+
policy: "my_timeseries_lifecycle_update"
460+
- match: { my_timeseries_lifecycle_update.version: 1 }
461+
- is_true: my_timeseries_lifecycle_update.modified_date
462+
- match: { my_timeseries_lifecycle_update.policy.phases.hot.actions.rollover.max_docs: 1000 }
463+
- is_false: my_timeseries_lifecycle_update.policy.phases.hot.actions.rollover.max_size
464+
465+
# Update the policy to add max_size and check for deprecation warning
466+
- do:
467+
warnings:
468+
- 'Use of the [max_size] rollover condition found in phase [hot]. This condition has been deprecated in favour of the [max_primary_shard_size] condition and will be removed in a later version'
469+
ilm.put_lifecycle:
470+
policy: "my_timeseries_lifecycle_update"
471+
body: |
472+
{
473+
"policy": {
474+
"phases": {
475+
"hot": {
476+
"actions": {
477+
"rollover": {
478+
"max_docs": 1000,
479+
"max_size": "25gb"
480+
}
481+
}
482+
}
483+
}
484+
}
485+
}
486+
487+
- do:
488+
ilm.get_lifecycle:
489+
policy: "my_timeseries_lifecycle_update"
490+
- match: { my_timeseries_lifecycle_update.version: 2 }
491+
- is_true: my_timeseries_lifecycle_update.modified_date
492+
- match: { my_timeseries_lifecycle_update.policy.phases.hot.actions.rollover.max_docs: 1000 }
493+
- match: { my_timeseries_lifecycle_update.policy.phases.hot.actions.rollover.max_size: "25gb" }

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@
88
package org.elasticsearch.xpack.ilm.action;
99

1010
import org.elasticsearch.client.internal.node.NodeClient;
11+
import org.elasticsearch.common.logging.DeprecationCategory;
12+
import org.elasticsearch.common.logging.DeprecationLogger;
1113
import org.elasticsearch.rest.BaseRestHandler;
1214
import org.elasticsearch.rest.RestRequest;
1315
import org.elasticsearch.rest.action.RestToXContentListener;
16+
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
1417
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
18+
import org.elasticsearch.xpack.core.ilm.Phase;
19+
import org.elasticsearch.xpack.core.ilm.RolloverAction;
1520
import org.elasticsearch.xpack.core.ilm.action.ILMActions;
1621
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest;
1722

1823
import java.io.IOException;
1924
import java.util.List;
25+
import java.util.Set;
2026

2127
import static org.elasticsearch.rest.RestRequest.Method.PUT;
2228
import static org.elasticsearch.rest.RestUtils.getAckTimeout;
2329
import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout;
2430

2531
public class RestPutLifecycleAction extends BaseRestHandler {
2632

33+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(RestPutLifecycleAction.class);
34+
35+
public static final String MAX_SIZE_DEPRECATION_MESSAGE = "Use of the [max_size] rollover condition found in phase [{}]. This"
36+
+ " condition has been deprecated in favour of the [max_primary_shard_size] condition and will be removed in a later version";
37+
2738
@Override
2839
public List<Route> routes() {
2940
return List.of(new Route(PUT, "/_ilm/policy/{name}"));
@@ -50,6 +61,28 @@ public String getPolicyName() {
5061
}
5162
}, parser);
5263
}
64+
65+
// Check for deprecated rollover conditions
66+
for (Phase phase : putLifecycleRequest.getPolicy().getPhases().values()) {
67+
for (LifecycleAction actionObj : phase.getActions().values()) {
68+
if (actionObj instanceof RolloverAction rolloverAction) {
69+
if (rolloverAction.getConditions().getMaxSize() != null) {
70+
DEPRECATION_LOGGER.warn(
71+
DeprecationCategory.API,
72+
"rollover-max-size-condition",
73+
MAX_SIZE_DEPRECATION_MESSAGE,
74+
phase.getName()
75+
);
76+
}
77+
}
78+
}
79+
}
80+
5381
return channel -> client.execute(ILMActions.PUT, putLifecycleRequest, new RestToXContentListener<>(channel));
5482
}
83+
84+
@Override
85+
public Set<String> supportedCapabilities() {
86+
return Set.of("max_size_deprecation");
87+
}
5588
}

0 commit comments

Comments
 (0)