-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Adding rest actions to get and set data stream settings #127858
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
Merged
masseyke
merged 5 commits into
elastic:main
from
masseyke:data-stream-settings-rest-action
May 21, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c923b7
Adding rest actions to get and set data stream settings
masseyke 33fc52e
Merge branch 'main' into data-stream-settings-rest-action
masseyke efff8ae
Merge branch 'main' into data-stream-settings-rest-action
masseyke d30e656
fixing a typo
masseyke c0b65f3
Merge branch 'main' into data-stream-settings-rest-action
masseyke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ams/src/main/java/org/elasticsearch/datastreams/rest/RestGetDataStreamSettingsAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo?
Suggested change
|
||||||
} | ||||||
|
||||||
@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) | ||||||
); | ||||||
} | ||||||
} |
59 changes: 59 additions & 0 deletions
59
.../src/main/java/org/elasticsearch/datastreams/rest/RestUpdateDataStreamSettingsAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
194 changes: 194 additions & 0 deletions
194
...ms/src/yamlRestTest/resources/rest-api-spec/test/data_stream/240_data_stream_settings.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
setup: | ||
- skip: | ||
features: allowed_warnings | ||
|
||
--- | ||
"Test single data stream": | ||
- requires: | ||
cluster_features: [ "logs_stream" ] | ||
reason: requires setting 'logs_stream' to get or set data stream settings | ||
- do: | ||
allowed_warnings: | ||
- "index template [my-template] has index patterns [my-data-stream-*] 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": | ||
- requires: | ||
cluster_features: [ "logs_stream" ] | ||
reason: requires setting 'logs_stream' to get or set data stream settings | ||
- do: | ||
allowed_warnings: | ||
- "index template [my-template] has index patterns [my-data-stream-*] 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": | ||
- requires: | ||
cluster_features: [ "logs_stream" ] | ||
reason: requires setting 'logs_stream' to get or set data stream settings | ||
- do: | ||
allowed_warnings: | ||
- "index template [my-template] has index patterns [my-data-stream-*] 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]" } |
40 changes: 40 additions & 0 deletions
40
rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_stream_settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"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": "feature_flag", | ||
"feature_flag": "logs_stream", | ||
"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" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using the static flag on DataStream couples plugin registration to the metadata class. Consider referencing the NodeFeature from DataStreamFeatures for a clearer separation of concerns.
Copilot uses AI. Check for mistakes.