Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

masseyke
Copy link
Member

@masseyke masseyke commented May 7, 2025

This builds on #127417, #126947, and #127282, adding rest actions to get and set data stream settings. The rest API changes are only visible if the logs_stream feature flag is enabled (i.e. you are running a snapshot, or the es.logs_stream_enabled system property is set to true).
Example usage:
Before setting any data stream settings,

GET _data_stream/my-data-stream/_settings

returns:

{
  "data_streams": [
    {
      "name": "my-data-stream",
      "settings": {},
      "effective_settings": {
        "index": {
          "lifecycle": {
            "name": "test-policy"
          },
          "mode": "standard",
          "number_of_replicas": "0"
        }
      }
    }
  ]
}

The settings field is empty because there are no settings directly on the my-data-stream data stream. The effective_settings field shows the result of merging this data stream's settings in with the settings it inherited from its template(s).
Now we can set settings on the data stream:

PUT _data_stream/my-data-stream/_settings
{
    "index.lifecycle.name" : "new-test-policy",
    "index.number_of_shards": 10
}

and the response is:

{
  "data_streams": [
    {
      "name": "my-data-stream",
      "applied_to_data_stream": true,
      "settings": {
        "index": {
          "lifecycle": {
            "name": "new-test-policy"
          },
          "number_of_shards": "10"
        }
      },
      "effective_settings": {
        "index": {
          "lifecycle": {
            "name": "new-test-policy"
          },
          "mode": "standard",
          "number_of_shards": "10",
          "number_of_replicas": "0"
        }
      },
      "index_settings_results": {
        "applied_to_data_stream_only": [
          "index.number_of_shards"
        ],
        "applied_to_data_stream_and_backing_indices": [
          "index.lifecycle.name"
        ]
      }
    }
  ]
}

The response lets the user know which settings were applied to all backing indices, and which were applied only to the data stream. Now doing a get settings API call shows these new data stream settings:

GET _data_stream/my-data-stream/_settings

returns

{
  "data_streams": [
    {
      "name": "my-data-stream",
      "settings": {
        "index": {
          "lifecycle": {
            "name": "new-test-policy"
          },
          "number_of_shards": "10"
        }
      },
      "effective_settings": {
        "index": {
          "lifecycle": {
            "name": "new-test-policy"
          },
          "mode": "standard",
          "number_of_shards": "10",
          "number_of_replicas": "0"
        }
      }
    }
  ]
}

The get data stream API now also returns the settings that have been applied to the current data stream. Using the example above:

GET _data_stream/my-data-stream

returns:

{
  "data_streams": [
    {
      "name": "my-data-stream",
      "timestamp_field": {
        "name": "@timestamp"
      },
      "indices": [
        {
          "index_name": ".ds-my-data-stream-2025.05.07-000001",
          "index_uuid": "_2sdNBZZTGqkwj247VlGdg",
          "managed_by": "Index Lifecycle Management",
          "prefer_ilm": true,
          "ilm_policy": "new-test-policy",
          "index_mode": "standard"
        }
      ],
      "generation": 1,
      "status": "GREEN",
      "template": "my-template",
      "ilm_policy": "new-test-policy",
      "next_generation_managed_by": "Index Lifecycle Management",
      "prefer_ilm": true,
      "hidden": false,
      "system": false,
      "allow_custom_routing": false,
      "replicated": false,
      "rollover_on_write": false,
      "index_mode": "standard",
      "settings": {
        "index": {
          "lifecycle": {
            "name": "new-test-policy"
          },
          "number_of_shards": "10"
        }
      },
      "failure_store": {
        "enabled": false,
        "rollover_on_write": true,
        "indices": []
      }
    }
  ]
}

The settings field contains only those settings that have been applied to this data stream, and does not incorporate settings from templates.

Note: A dry-run mode will come in a follow-up PR.

@masseyke masseyke added >non-issue :Data Management/Data streams Data streams and their lifecycles v9.1.0 labels May 7, 2025
@masseyke
Copy link
Member Author

masseyke commented May 8, 2025

Note: the serverless check is failing b/c the yaml rest test uses ILM settings that are not available in serverless. Before merging this PR, I'll exclude those tests from serverless in https://github.com/elastic/elasticsearch-serverless/pull/3890.

@masseyke masseyke marked this pull request as ready for review May 8, 2025 20:51
@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label May 8, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@lukewhiting lukewhiting requested a review from Copilot May 20, 2025 08:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for REST endpoints to get and set data stream settings behind a feature flag.

  • Introduces RestGetDataStreamSettingsAction and RestUpdateDataStreamSettingsAction handlers registered when the logs_stream flag is enabled
  • Updates DataStream.toXContent to include a settings field when the feature is on
  • Adds YAML tests for the new GET/PUT settings APIs and extends existing Java tests to round-trip the settings

Reviewed Changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java Adds a LOGS_STREAM_FEATURE_FLAG and gates settings output in XContent
server/src/main/java/org/elasticsearch/action/datastreams/GetDataStreamAction.java Adds settings ParseField and emits data stream settings when flagged
server/src/test/java/org/elasticsearch/action/datastreams/GetDataStreamActionTests.java Imports Settings and tests that settings round-trip through XContent
modules/data-streams/src/main/java/org/elasticsearch/datastreams/rest/RestGetDataStreamSettingsAction.java New GET settings handler
modules/data-streams/src/main/java/org/elasticsearch/datastreams/rest/RestUpdateDataStreamSettingsAction.java New PUT settings handler
modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamsPlugin.java Registers the new handlers behind the feature flag
modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamFeatures.java Exposes the logs_stream feature for tests
modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/240_data_stream_settings.yml Integration tests for the new settings endpoints
Files not reviewed (2)
  • rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_stream_settings.json: Language not supported
  • rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_data_stream_settings.json: Language not supported
Comments suppressed due to low confidence (1)

modules/data-streams/src/main/java/org/elasticsearch/datastreams/rest/RestGetDataStreamSettingsAction.java:32

  • Typo in action name: should be "get_data_stream_settings_action" for consistency with other handlers.
return "gett_data_stream_settings_action";

@@ -79,6 +80,7 @@ public final class DataStream implements SimpleDiffable<DataStream>, ToXContentO
private static final Logger LOGGER = LogManager.getLogger(DataStream.class);

public static final NodeFeature DATA_STREAM_FAILURE_STORE_FEATURE = new NodeFeature("data_stream.failure_store");
public static final boolean LOGS_STREAM_FEATURE_FLAG = new FeatureFlag("logs_stream").isEnabled();
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Directly instantiating a raw FeatureFlag here duplicates the NodeFeature in DataStreamFeatures. Consider centralizing feature checks via the NodeFeature or a shared utility.

Suggested change
public static final boolean LOGS_STREAM_FEATURE_FLAG = new FeatureFlag("logs_stream").isEnabled();
public static final NodeFeature LOGS_STREAM_FEATURE = new NodeFeature("logs_stream");

Copilot uses AI. Check for mistakes.

@@ -280,6 +283,10 @@ public List<RestHandler> getRestHandlers(
handlers.add(new RestGetDataStreamOptionsAction());
handlers.add(new RestPutDataStreamOptionsAction());
handlers.add(new RestDeleteDataStreamOptionsAction());
if (DataStream.LOGS_STREAM_FEATURE_FLAG) {
Copy link
Preview

Copilot AI May 20, 2025

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.

Copy link
Contributor

@lukewhiting lukewhiting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small typo to fix but otherwise, looks good :-)

public class RestGetDataStreamSettingsAction extends BaseRestHandler {
@Override
public String getName() {
return "gett_data_stream_settings_action";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Suggested change
return "gett_data_stream_settings_action";
return "get_data_stream_settings_action";

@masseyke masseyke requested a review from lukewhiting May 20, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Data streams Data streams and their lifecycles >non-issue Team:Data Management Meta label for data/management team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants