-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Cluster state and CRUD operations for data streams #53877
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
Changes from all commits
6aa44d2
9a44505
a2ff592
fcacbbf
169efc4
bef471d
4a9c39d
bfa64f1
f2ae126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,33 @@ | ||
| --- | ||
| "Test stubs": | ||
| "Create data stream": | ||
| - skip: | ||
| version: " - 7.6.99" | ||
| reason: only available in 7.7+ | ||
| version: "all" | ||
| reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/54022" | ||
|
|
||
| - do: | ||
| indices.create_data_stream: | ||
| name: data-stream2 | ||
| name: simple-data-stream1 | ||
| body: | ||
| timestamp_field: "@timestamp" | ||
| - is_true: acknowledged | ||
|
|
||
| - do: | ||
| indices.create_data_stream: | ||
| name: simple-data-stream2 | ||
| body: | ||
| timestamp_field: "@timestamp2" | ||
| - is_true: acknowledged | ||
|
|
||
| - do: | ||
| indices.get_data_streams: {} | ||
| - match: { 0.name: my_data_stream1 } | ||
| - match: { 0.name: simple-data-stream1 } | ||
| - match: { 0.timestamp_field: '@timestamp' } | ||
| - match: { 0.indices: ['my_data_stream1-000000'] } | ||
| - match: { 1.name: my_data_stream2 } | ||
| - match: { 1.timestamp_field: '@timestamp' } | ||
| - match: { 0.indices: [] } | ||
| - match: { 1.name: simple-data-stream2 } | ||
| - match: { 1.timestamp_field: '@timestamp2' } | ||
| - match: { 1.indices: [] } | ||
|
|
||
| - do: | ||
| indices.delete_data_stream: | ||
| name: data-stream2 | ||
| name: simple-data-stream2 | ||
| - is_true: acknowledged |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,15 +34,18 @@ | |
| import org.elasticsearch.common.inject.Inject; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.regex.Regex; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.TransportService; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| public class GetDataStreamsAction extends ActionType<GetDataStreamsAction.Response> { | ||
|
|
@@ -154,11 +157,30 @@ protected Response read(StreamInput in) throws IOException { | |
| @Override | ||
| protected void masterOperation(Task task, Request request, ClusterState state, | ||
| ActionListener<Response> listener) throws Exception { | ||
| List<DataStream> dataStreams = List.of( | ||
| new DataStream("my_data_stream1", "@timestamp", List.of("my_data_stream1-000000")), | ||
| new DataStream("my_data_stream2", "@timestamp", List.of()) | ||
| ); | ||
| listener.onResponse(new Response(dataStreams)); | ||
| listener.onResponse(new Response(getDataStreams(state, request))); | ||
| } | ||
|
|
||
| static List<DataStream> getDataStreams(ClusterState clusterState, Request request) { | ||
| Map<String, DataStream> dataStreams = clusterState.metaData().dataStreams(); | ||
|
Member
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. unit test?
Contributor
Author
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. It seems there are different existing behaviors when attempting to retrieve a specific resource that does not exist. E.g., aliases and indices return a 404 and index templates and ingest pipelines return an empty list. I don't if those are intentional behavioral differences, but I can certainly return a 404 if that's appropriate for data streams.
Member
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. I think that returning a 404 in case of requesting a specific data stream is appropriate. |
||
|
|
||
| // return all data streams if no name was specified | ||
| if (request.names.length == 0) { | ||
| return new ArrayList<>(dataStreams.values()); | ||
| } | ||
|
|
||
| final List<DataStream> results = new ArrayList<>(); | ||
| for (String name : request.names) { | ||
| if (Regex.isSimpleMatchPattern(name)) { | ||
| for (Map.Entry<String, DataStream> entry : dataStreams.entrySet()) { | ||
| if (Regex.simpleMatch(name, entry.getKey())) { | ||
| results.add(entry.getValue()); | ||
| } | ||
| } | ||
| } else if (dataStreams.containsKey(name)) { | ||
| results.add(dataStreams.get(name)); | ||
| } | ||
| } | ||
| return results; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.