Skip to content

Data stream settings rest actions #127298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a4bd582
Using DataStream::getEffectiveSettings for rollover
masseyke Apr 23, 2025
4c47be2
Merge branch 'main' into using-data-stream-get-effective-settings
masseyke Apr 23, 2025
e83aae1
Adding transport actions for getting and updating data stream settings
masseyke Apr 23, 2025
68719e1
avoiding NPE in getEffectiveSettings
masseyke Apr 23, 2025
a07a97d
Merge branch 'using-data-stream-get-effective-settings' into data-str…
masseyke Apr 23, 2025
9495926
fixing a checkstyle problem
masseyke Apr 23, 2025
bece8f8
fixing OperatorPrivilegesIT
masseyke Apr 23, 2025
70d768f
Initial data stream settings rest action work
masseyke Apr 23, 2025
3f24b89
adding rest api spec
masseyke Apr 24, 2025
e3637d7
adding yaml rest test for get settings
masseyke Apr 24, 2025
7bced31
adding unit tests
masseyke Apr 24, 2025
4b509c1
Merge branch 'data-stream-settings-transport-actions' into data-strea…
masseyke Apr 24, 2025
609f8c6
improving yaml rest test
masseyke Apr 25, 2025
5d228a5
Adding transport actions for getting and updating data stream settings
masseyke Apr 25, 2025
912de59
Project-centric code review feedback
masseyke Apr 28, 2025
8c13be2
Merge branch 'main' into data-stream-settings-transport-action
masseyke Apr 28, 2025
131e60a
merging
masseyke Apr 28, 2025
7321b59
[CI] Auto commit changes from spotless
elasticsearchmachine Apr 28, 2025
0a1d61d
Merge branch 'main' into data-stream-settings-rest-actions
masseyke Apr 28, 2025
c12b8b8
Merge branch 'data-stream-settings-rest-actions' of github.com:massey…
masseyke Apr 28, 2025
30e2bd8
Merge branch 'main' into data-stream-settings-rest-actions
masseyke May 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@
import org.elasticsearch.datastreams.rest.RestCreateDataStreamAction;
import org.elasticsearch.datastreams.rest.RestDataStreamsStatsAction;
import org.elasticsearch.datastreams.rest.RestDeleteDataStreamAction;
import org.elasticsearch.datastreams.rest.RestGetDataStreamSettingsAction;
import org.elasticsearch.datastreams.rest.RestGetDataStreamsAction;
import org.elasticsearch.datastreams.rest.RestMigrateToDataStreamAction;
import org.elasticsearch.datastreams.rest.RestModifyDataStreamsAction;
import org.elasticsearch.datastreams.rest.RestPromoteDataStreamAction;
import org.elasticsearch.datastreams.rest.RestUpdateDataStreamSettingsAction;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.health.HealthIndicatorService;
import org.elasticsearch.index.IndexSettingProvider;
Expand Down Expand Up @@ -280,6 +282,8 @@ public List<RestHandler> getRestHandlers(
handlers.add(new RestGetDataStreamOptionsAction());
handlers.add(new RestPutDataStreamOptionsAction());
handlers.add(new RestDeleteDataStreamOptionsAction());
handlers.add(new RestGetDataStreamSettingsAction());
handlers.add(new RestUpdateDataStreamSettingsAction());
return handlers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.datastreams.rest;

import org.elasticsearch.action.datastreams.GetDataStreamSettingsAction;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestCancellableNodeClient;
import org.elasticsearch.rest.action.RestRefCountedChunkedToXContentListener;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.rest.RestRequest.Method.GET;

@ServerlessScope(Scope.PUBLIC)
public class RestGetDataStreamSettingsAction extends BaseRestHandler {
@Override
public String getName() {
return "gett_data_stream_settings_action";
}

@Override
public List<Route> routes() {
return List.of(new Route(GET, "/_data_stream/{name}/_settings"));
}

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
GetDataStreamSettingsAction.Request getDataStreamRequest = new GetDataStreamSettingsAction.Request(
RestUtils.getMasterNodeTimeout(request)
).indices(Strings.splitStringByCommaToArray(request.param("name")));
return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).execute(
GetDataStreamSettingsAction.INSTANCE,
getDataStreamRequest,
new RestRefCountedChunkedToXContentListener<>(channel)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
package org.elasticsearch.datastreams.rest;

import org.elasticsearch.action.datastreams.UpdateDataStreamSettingsAction;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestCancellableNodeClient;
import org.elasticsearch.rest.action.RestRefCountedChunkedToXContentListener;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.rest.RestRequest.Method.PUT;

@ServerlessScope(Scope.PUBLIC)
public class RestUpdateDataStreamSettingsAction extends BaseRestHandler {

@Override
public String getName() {
return "update_data_stream_settings_action";
}

@Override
public List<Route> routes() {
return List.of(new Route(PUT, "/_data_stream/{name}/_settings"));
}

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
Settings settings;
try (XContentParser parser = request.contentParser()) {
settings = Settings.fromXContent(parser);
}
UpdateDataStreamSettingsAction.Request putDataStreamRequest = new UpdateDataStreamSettingsAction.Request(
settings,
RestUtils.getMasterNodeTimeout(request),
RestUtils.getAckTimeout(request)
).indices(Strings.splitStringByCommaToArray(request.param("name")));
return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).execute(
UpdateDataStreamSettingsAction.INSTANCE,
putDataStreamRequest,
new RestRefCountedChunkedToXContentListener<>(channel)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
setup:
- skip:
features: allowed_warnings

---
"Test single data stream":
- do:
allowed_warnings:
- "index template [my-template] has index patterns [data-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
indices.put_index_template:
name: my-template
body:
index_patterns: [ my-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
lifecycle.name: my-policy

- do:
indices.create_data_stream:
name: my-data-stream-1

- do:
cluster.health:
index: "my-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_settings:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.settings: {} }
- match: { data_streams.0.effective_settings.index.number_of_shards: null }
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
- match: { data_streams.0.effective_settings.index.lifecycle.name: "my-policy" }

- do:
indices.get_data_stream:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.settings: {} }
- match: { data_streams.0.effective_settings: null }

- do:
indices.put_data_stream_settings:
name: my-data-stream-1
body:
index:
number_of_shards: 2
lifecycle.name: my-new-policy
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.applied_to_data_stream: true }
- match: { data_streams.0.index_settings_results.applied_to_data_stream_only: [index.number_of_shards]}
- match: { data_streams.0.index_settings_results.applied_to_data_stream_and_backing_indices: [index.lifecycle.name] }
- match: { data_streams.0.settings.index.number_of_shards: "2" }
- match: { data_streams.0.settings.index.lifecycle.name: "my-new-policy" }
- match: { data_streams.0.effective_settings.index.number_of_shards: "2" }
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
- match: { data_streams.0.effective_settings.index.lifecycle.name: "my-new-policy" }

- do:
indices.rollover:
alias: "my-data-stream-1"

- do:
cluster.health:
index: "my-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_settings:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.settings.index.number_of_shards: "2" }
- match: { data_streams.0.effective_settings.index.number_of_shards: "2" }
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
- match: { data_streams.0.effective_settings.index.lifecycle.name: "my-new-policy" }

- do:
indices.get_data_stream:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.settings.index.number_of_shards: "2" }
- match: { data_streams.0.settings.index.lifecycle.name: "my-new-policy" }
- match: { data_streams.0.effective_settings: null }

- do:
indices.get_data_stream:
name: my-data-stream-1
- set: { data_streams.0.indices.0.index_name: idx0name }
- set: { data_streams.0.indices.1.index_name: idx1name }

- do:
indices.get_settings:
index: my-data-stream-1
- match: { .$idx0name.settings.index.number_of_shards: "1" }
- match: { .$idx0name.settings.index.lifecycle.name: "my-new-policy" }
- match: { .$idx1name.settings.index.number_of_shards: "2" }
- match: { .$idx1name.settings.index.lifecycle.name: "my-new-policy" }

---
"Test multiple data streams":
- do:
allowed_warnings:
- "index template [my-template] has index patterns [data-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
indices.put_index_template:
name: my-template
body:
index_patterns: [ my-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
lifecycle.name: my-policy

- do:
indices.create_data_stream:
name: my-data-stream-1

- do:
indices.create_data_stream:
name: my-data-stream-2

- do:
indices.create_data_stream:
name: my-data-stream-3

- do:
cluster.health:
index: "my-data-stream-1,my-data-stream-2,my-data-stream-3"
wait_for_status: green

- do:
indices.get_data_stream_settings:
name: "*"
- length: { data_streams: 3 }

- do:
indices.get_data_stream_settings:
name: "my-data-stream-1,my-data-stream-2"
- length: { data_streams: 2 }

- do:
indices.put_data_stream_settings:
name: my-data-stream-1,my-data-stream-2
body:
index:
number_of_shards: 2
lifecycle.name: my-new-policy
- length: { data_streams: 2 }

---
"Test invalid settings":
- do:
allowed_warnings:
- "index template [my-template] has index patterns [data-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
indices.put_index_template:
name: my-template
body:
index_patterns: [ my-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
lifecycle.name: my-policy

- do:
indices.create_data_stream:
name: my-data-stream-1

- do:
cluster.health:
index: "my-data-stream-1"
wait_for_status: green

- do:
indices.put_data_stream_settings:
name: my-data-stream-1
body:
index:
fake_setting: 1234
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.applied_to_data_stream: false }
- match: { data_streams.0.error: "Cannot set the following settings on a data stream: [index.fake_setting]" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"indices.get_data_stream_settings":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html",
"description":"Gets a data stream's settings"
},
"stability":"stable",
"visibility":"public",
"headers":{
"accept": [ "application/json"]
},
"url":{
"paths":[
{
"path":"/_data_stream/{name}/_settings",
"methods":[
"GET"
],
"parts":{
"name":{
"type":"string",
"description":"The name of the data stream or data stream pattern"
}
}
}
]
},
"params":{
"timeout":{
"type":"time",
"description":"Specify timeout for acknowledging the cluster state update"
},
"master_timeout":{
"type":"time",
"description":"Specify timeout for connection to master"
}
}
}
}
Loading