Skip to content
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

[Data stream lifecycle] Conditionally display effective retention #107964

Merged

Conversation

gmarouli
Copy link
Contributor

While the global retention is work in progress, we would like to display the effective retention conditionally. For this reason we added an extra requirement to determine if we are going to add the field in XContent serialisation.

A sample yaml test for this could be:

---
"Get effective retention from component template":

  - do:
      cluster.put_component_template:
        name: test-component-template
        body:
          template:
            lifecycle:
              data_retention: "10d"
  - is_true: acknowledged

  - do:
      cluster.get_component_template:
        name: test-component-template
  - match: { component_templates.0.component_template.template.lifecycle.effective_retention: "10d" }
  - match: { component_templates.0.component_template.template.lifecycle.retention_determined_by: "data_stream_configuration" }

---
"Get effective retention from index template":

  - do:
      indices.put_index_template:
        name: test-composable-template
        body:
          index_patterns: "my-data-stream"
          template:
            lifecycle:
              data_retention: "10d"
          data_stream: {}
  - is_true: acknowledged

  - do:
      indices.get_index_template:
        name: test-composable-template
  - match: {index_templates.0.index_template.template.lifecycle.effective_retention: "10d"}
  - match: {index_templates.0.index_template.template.lifecycle.retention_determined_by: "data_stream_configuration"}

---
"Get effective retention from data stream":
  - do:
      indices.put_index_template:
        name: ds-template
        body:
          index_patterns: "my-data-stream"
          template:
            lifecycle:
              data_retention: 10d
          data_stream: { }
  - is_true: acknowledged

  - do:
      indices.create_data_stream:
        name: my-data-stream
  - is_true: acknowledged

  - do:
      indices.get_data_lifecycle:
        name: "my-data-stream"

  - match: { data_streams.0.lifecycle.effective_retention: "10d" }
  - match: { data_streams.0.lifecycle.retention_determined_by: "data_stream_configuration" }

  - do:
      indices.get_data_stream:
        name: "my-data-stream"

  - match: { data_streams.0.lifecycle.effective_retention:  "10d" }
  - match: { data_streams.0.lifecycle.retention_determined_by: "data_stream_configuration" }

---
"Get effective retention from simulating index template":

  - do:
      indices.put_index_template:
        name: test
        body:
          index_patterns: te*
          template:
            lifecycle:
              data_retention: "10d"
          data_stream: {}
  - do:
      indices.simulate_index_template:
        name: test

  - match: {template.lifecycle.effective_retention: "10d"}
  - match: {template.lifecycle.retention_determined_by: "data_stream_configuration"}

@gmarouli gmarouli added >non-issue :Data Management/Data streams Data streams and their lifecycles labels Apr 26, 2024
@gmarouli gmarouli requested a review from masseyke April 26, 2024 17:45
@elasticsearchmachine elasticsearchmachine added v8.15.0 Team:Data Management Meta label for data/management team labels Apr 26, 2024
@elasticsearchmachine
Copy link
Collaborator

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

*/
public static ToXContent.Params maybeAddEffectiveRetentionParams(ToXContent.Params params) {
boolean shouldAddEffectiveRetention = Objects.equals(params.param(RestRequest.PATH_RESTRICTED), "serverless");
return new DelegatingMapParams(
Copy link
Member

Choose a reason for hiding this comment

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

You told me this when we spoke offline and it made sense, but now I can't remember -- why can't we just check PATH_RESTRICTED in toXContent(), and not worry about remembering to call maybeAddEffectiveRetentionParams?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem it's a lot to keep in mind. We want only the specific APIs to add the effective retention to their response, at the DataStreamLifecycle level we do not know who called us and probably multiple places set the PATH_RESTRICTED. So, we are trying to ensure we do not expose this more than we should by explicitly choosing when to set the maybeAddEffectiveRetentionParams.

Is this clear now?

@masseyke masseyke merged commit b0283eb into elastic:main Apr 29, 2024
13 of 14 checks passed
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 v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants