Skip to content

Commit 9107d76

Browse files
committed
Update rest endpoints
1 parent 1d383f6 commit 9107d76

File tree

7 files changed

+158
-9
lines changed

7 files changed

+158
-9
lines changed

modules/data-streams/src/main/java/org/elasticsearch/datastreams/lifecycle/rest/RestPutDataStreamLifecycleAction.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.IOException;
2323
import java.util.List;
24+
import java.util.Set;
2425

2526
import static org.elasticsearch.rest.RestRequest.Method.PUT;
2627
import static org.elasticsearch.rest.RestUtils.getAckTimeout;
@@ -29,6 +30,9 @@
2930
@ServerlessScope(Scope.PUBLIC)
3031
public class RestPutDataStreamLifecycleAction extends BaseRestHandler {
3132

33+
private static final String SUPPORTS_DOWNSAMPLING_METHOD = "dlm.downsampling_method";
34+
private static final Set<String> CAPABILITIES = Set.of(SUPPORTS_DOWNSAMPLING_METHOD);
35+
3236
@Override
3337
public String getName() {
3438
return "put_data_lifecycles_action";
@@ -44,13 +48,14 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
4448
try (XContentParser parser = request.contentParser()) {
4549
PutDataStreamLifecycleAction.Request putLifecycleRequest = PutDataStreamLifecycleAction.Request.parseRequest(
4650
parser,
47-
(dataRetention, enabled, downsampling) -> new PutDataStreamLifecycleAction.Request(
51+
(dataRetention, enabled, downsamplingRounds, downsamplingMethod) -> new PutDataStreamLifecycleAction.Request(
4852
getMasterNodeTimeout(request),
4953
getAckTimeout(request),
5054
Strings.splitStringByCommaToArray(request.param("name")),
5155
dataRetention,
5256
enabled,
53-
downsampling
57+
downsamplingRounds,
58+
downsamplingMethod
5459
)
5560
);
5661
putLifecycleRequest.indicesOptions(IndicesOptions.fromRequest(request, putLifecycleRequest.indicesOptions()));
@@ -61,4 +66,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
6166
);
6267
}
6368
}
69+
70+
@Override
71+
public Set<String> supportedCapabilities() {
72+
return CAPABILITIES;
73+
}
6474
}

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/lifecycle/20_basic.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,58 @@ teardown:
171171
- match: { data_streams.1.lifecycle.downsampling.1.after: '100d'}
172172
- match: { data_streams.1.lifecycle.downsampling.1.fixed_interval: '10h'}
173173

174+
---
175+
"Put data stream lifecycle with downsampling method":
176+
- requires:
177+
capabilities:
178+
- method: PUT
179+
path: /_data_stream/{name}/_lifecycle
180+
capabilities: [ "dlm.downsampling_method" ]
181+
test_runner_features: [ "capabilities" ]
182+
reason: "Downsampling method was added to data stream lifecycle was available from 9.3"
183+
184+
- do:
185+
indices.put_data_lifecycle:
186+
name: "*"
187+
body: >
188+
{
189+
"downsampling": [
190+
{
191+
"after": "10d",
192+
"fixed_interval": "1h"
193+
},
194+
{
195+
"after": "100d",
196+
"fixed_interval": "10h"
197+
}
198+
],
199+
"downsampling_method": "aggregate",
200+
"data_retention": "30d",
201+
"enabled": false
202+
}
203+
204+
- is_true: acknowledged
205+
206+
- do:
207+
indices.get_data_lifecycle:
208+
name: "*"
209+
- length: { data_streams: 2 }
210+
- match: { data_streams.0.name: data-stream-with-lifecycle }
211+
- match: { data_streams.0.lifecycle.data_retention: "30d" }
212+
- match: { data_streams.0.lifecycle.enabled: false}
213+
- match: { data_streams.0.lifecycle.downsampling.0.after: '10d'}
214+
- match: { data_streams.0.lifecycle.downsampling.0.fixed_interval: '1h'}
215+
- match: { data_streams.0.lifecycle.downsampling.1.after: '100d'}
216+
- match: { data_streams.0.lifecycle.downsampling.1.fixed_interval: '10h'}
217+
- match: { data_streams.1.name: simple-data-stream1 }
218+
- match: { data_streams.1.lifecycle.data_retention: "30d" }
219+
- match: { data_streams.1.lifecycle.enabled: false}
220+
- match: { data_streams.1.lifecycle.downsampling_method: 'aggregate'}
221+
- match: { data_streams.1.lifecycle.downsampling.0.after: '10d'}
222+
- match: { data_streams.1.lifecycle.downsampling.0.fixed_interval: '1h'}
223+
- match: { data_streams.1.lifecycle.downsampling.1.after: '100d'}
224+
- match: { data_streams.1.lifecycle.downsampling.1.fixed_interval: '10h'}
225+
174226
---
175227
"Enable lifecycle":
176228

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.component_template/10_basic.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,38 @@
142142
- match: {component_templates.0.component_template.template.lifecycle.enabled: true}
143143
- match: {component_templates.0.component_template.template.lifecycle.data_retention: "10d"}
144144

145+
---
146+
"Add data stream lifecycle with downsampling":
147+
- requires:
148+
capabilities:
149+
- method: PUT
150+
path: /_component_template/{name}
151+
capabilities: [ "dlm.downsampling_method" ]
152+
test_runner_features: [ "capabilities" ]
153+
reason: "Downsampling method was added to data stream lifecycle was available from 9.3"
154+
155+
- do:
156+
cluster.put_component_template:
157+
name: test-lifecycle
158+
body:
159+
template:
160+
lifecycle:
161+
data_retention: "10d"
162+
downsampling_method: last_value
163+
downsampling:
164+
- {"after": "1d", "fixed_interval": "5m"}
165+
166+
- do:
167+
cluster.get_component_template:
168+
name: test-lifecycle
169+
170+
- match: {component_templates.0.name: test-lifecycle}
171+
- match: {component_templates.0.component_template.template.lifecycle.enabled: true}
172+
- match: {component_templates.0.component_template.template.lifecycle.data_retention: "10d"}
173+
- match: {component_templates.0.component_template.template.lifecycle.downsampling_method: "last_value"}
174+
- match: {component_templates.0.component_template.template.lifecycle.downsampling.0.after: "1d"}
175+
- match: {component_templates.0.component_template.template.lifecycle.downsampling.0.fixed_interval: "5m"}
176+
145177
---
146178
"Get data stream lifecycle with default rollover":
147179
- requires:

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.put_index_template/10_basic.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,37 @@
197197
name: baz
198198

199199
- match: {index_templates.0.name: baz}
200+
201+
---
202+
"Add data stream lifecycle with downsampling":
203+
- requires:
204+
capabilities:
205+
- method: PUT
206+
path: /_index_template/{name}
207+
capabilities: [ "dlm.downsampling_method" ]
208+
test_runner_features: [ "capabilities" ]
209+
reason: "Downsampling method was added to data stream lifecycle was available from 9.3"
210+
211+
- do:
212+
indices.put_index_template:
213+
name: test-lifecycle
214+
body:
215+
index_patterns: downsampling-*
216+
data_stream: {}
217+
template:
218+
lifecycle:
219+
data_retention: "10d"
220+
downsampling_method: last_value
221+
downsampling:
222+
- {"after": "1d", "fixed_interval": "5m"}
223+
224+
- do:
225+
indices.get_index_template:
226+
name: test-lifecycle
227+
228+
- match: {index_templates.0.name: test-lifecycle}
229+
- match: {index_templates.0.index_template.template.lifecycle.enabled: true}
230+
- match: {index_templates.0.index_template.template.lifecycle.data_retention: "10d"}
231+
- match: {index_templates.0.index_template.template.lifecycle.downsampling_method: "last_value"}
232+
- match: {index_templates.0.index_template.template.lifecycle.downsampling.0.after: "1d"}
233+
- match: {index_templates.0.index_template.template.lifecycle.downsampling.0.fixed_interval: "5m"}

server/src/main/java/org/elasticsearch/action/datastreams/lifecycle/PutDataStreamLifecycleAction.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.action.ActionType;
1313
import org.elasticsearch.action.IndicesRequest;
14+
import org.elasticsearch.action.downsample.DownsampleConfig;
1415
import org.elasticsearch.action.support.IndicesOptions;
1516
import org.elasticsearch.action.support.master.AcknowledgedRequest;
1617
import org.elasticsearch.action.support.master.AcknowledgedResponse;
@@ -33,6 +34,7 @@
3334

3435
import static org.elasticsearch.cluster.metadata.DataStreamLifecycle.DATA_RETENTION_FIELD;
3536
import static org.elasticsearch.cluster.metadata.DataStreamLifecycle.DOWNSAMPLING_FIELD;
37+
import static org.elasticsearch.cluster.metadata.DataStreamLifecycle.DOWNSAMPLING_METHOD_FIELD;
3638
import static org.elasticsearch.cluster.metadata.DataStreamLifecycle.ENABLED_FIELD;
3739

3840
/**
@@ -50,15 +52,21 @@ public interface Factory {
5052
Request create(
5153
@Nullable TimeValue dataRetention,
5254
@Nullable Boolean enabled,
53-
@Nullable List<DataStreamLifecycle.DownsamplingRound> downsampling
55+
@Nullable List<DataStreamLifecycle.DownsamplingRound> downsampling,
56+
@Nullable DownsampleConfig.SamplingMethod downsamplingMethod
5457
);
5558
}
5659

5760
@SuppressWarnings("unchecked")
5861
public static final ConstructingObjectParser<Request, Factory> PARSER = new ConstructingObjectParser<>(
5962
"put_data_stream_lifecycle_request",
6063
false,
61-
(args, factory) -> factory.create((TimeValue) args[0], (Boolean) args[1], (List<DataStreamLifecycle.DownsamplingRound>) args[2])
64+
(args, factory) -> factory.create(
65+
(TimeValue) args[0],
66+
(Boolean) args[1],
67+
(List<DataStreamLifecycle.DownsamplingRound>) args[2],
68+
(DownsampleConfig.SamplingMethod) args[3]
69+
)
6270
);
6371

6472
static {
@@ -75,6 +83,12 @@ Request create(
7583
DOWNSAMPLING_FIELD,
7684
ObjectParser.ValueType.OBJECT_ARRAY
7785
);
86+
PARSER.declareField(
87+
ConstructingObjectParser.optionalConstructorArg(),
88+
(p, c) -> DownsampleConfig.SamplingMethod.fromString(p.text()),
89+
DOWNSAMPLING_METHOD_FIELD,
90+
ObjectParser.ValueType.STRING
91+
);
7892
}
7993

8094
public static Request parseRequest(XContentParser parser, Factory factory) {
@@ -120,7 +134,7 @@ public void writeTo(StreamOutput out) throws IOException {
120134
}
121135

122136
public Request(TimeValue masterNodeTimeout, TimeValue ackTimeout, String[] names, @Nullable TimeValue dataRetention) {
123-
this(masterNodeTimeout, ackTimeout, names, dataRetention, null, null);
137+
this(masterNodeTimeout, ackTimeout, names, dataRetention, null);
124138
}
125139

126140
public Request(TimeValue masterNodeTimeout, TimeValue ackTimeout, String[] names, DataStreamLifecycle lifecycle) {
@@ -136,7 +150,7 @@ public Request(
136150
@Nullable TimeValue dataRetention,
137151
@Nullable Boolean enabled
138152
) {
139-
this(masterNodeTimeout, ackTimeout, names, dataRetention, enabled, null);
153+
this(masterNodeTimeout, ackTimeout, names, dataRetention, enabled, null, null);
140154
}
141155

142156
public Request(
@@ -145,14 +159,16 @@ public Request(
145159
String[] names,
146160
@Nullable TimeValue dataRetention,
147161
@Nullable Boolean enabled,
148-
@Nullable List<DataStreamLifecycle.DownsamplingRound> downsamplingRounds
162+
@Nullable List<DataStreamLifecycle.DownsamplingRound> downsamplingRounds,
163+
@Nullable DownsampleConfig.SamplingMethod downsamplingMethod
149164
) {
150165
super(masterNodeTimeout, ackTimeout);
151166
this.names = names;
152167
this.lifecycle = DataStreamLifecycle.dataLifecycleBuilder()
153168
.dataRetention(dataRetention)
154169
.enabled(enabled == null || enabled)
155170
.downsamplingRounds(downsamplingRounds)
171+
.downsamplingMethod(downsamplingMethod)
156172
.build();
157173
}
158174

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public class RestPutComponentTemplateAction extends BaseRestHandler {
3232
public static final String SUPPORTS_FAILURE_STORE_LIFECYCLE = "data_stream_options.failure_store.lifecycle";
3333
public static final String SUPPORTS_FAILURE_STORE = "data_stream_options.failure_store";
3434
private static final String COMPONENT_TEMPLATE_TRACKING_INFO = "component_template_tracking_info";
35+
static final String SUPPORTS_DOWNSAMPLING_METHOD = "dlm.downsampling_method";
3536
private static final Set<String> CAPABILITIES = Set.of(
3637
SUPPORTS_FAILURE_STORE,
3738
SUPPORTS_FAILURE_STORE_LIFECYCLE,
38-
COMPONENT_TEMPLATE_TRACKING_INFO
39+
COMPONENT_TEMPLATE_TRACKING_INFO,
40+
SUPPORTS_DOWNSAMPLING_METHOD
3941
);
4042

4143
@Override

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@
2525
import static org.elasticsearch.rest.RestRequest.Method.POST;
2626
import static org.elasticsearch.rest.RestRequest.Method.PUT;
2727
import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout;
28+
import static org.elasticsearch.rest.action.admin.indices.RestPutComponentTemplateAction.SUPPORTS_DOWNSAMPLING_METHOD;
2829
import static org.elasticsearch.rest.action.admin.indices.RestPutComponentTemplateAction.SUPPORTS_FAILURE_STORE;
2930
import static org.elasticsearch.rest.action.admin.indices.RestPutComponentTemplateAction.SUPPORTS_FAILURE_STORE_LIFECYCLE;
3031

3132
@ServerlessScope(Scope.PUBLIC)
3233
public class RestPutComposableIndexTemplateAction extends BaseRestHandler {
3334

3435
private static final String INDEX_TEMPLATE_TRACKING_INFO = "index_template_tracking_info";
36+
3537
private static final Set<String> CAPABILITIES = Set.of(
3638
SUPPORTS_FAILURE_STORE,
3739
SUPPORTS_FAILURE_STORE_LIFECYCLE,
38-
INDEX_TEMPLATE_TRACKING_INFO
40+
INDEX_TEMPLATE_TRACKING_INFO,
41+
SUPPORTS_DOWNSAMPLING_METHOD
3942
);
4043

4144
@Override

0 commit comments

Comments
 (0)