Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
109bf28
Use the global retention in data stream lifecycle retention calculation
gmarouli Mar 11, 2024
b5d4378
Update data stream APIs
gmarouli Mar 11, 2024
78a0efd
Update explain APIs
gmarouli Mar 11, 2024
fab2817
Update template related APIs
gmarouli Mar 11, 2024
73f0225
Update telemetry to use the configured retention
gmarouli Mar 11, 2024
c74ff7d
Merge with main
gmarouli Mar 12, 2024
76f058a
Merge branch 'main' into use-data-stream-global-retention-metadata
gmarouli Mar 12, 2024
91ccdb0
Fix DataStreamTests
gmarouli Mar 12, 2024
b58d10b
Fix DataStreamTests
gmarouli Mar 12, 2024
57f39a2
Update some doc tests with the new fields
gmarouli Mar 12, 2024
9eff27b
Add missing commas in json payload
gmarouli Mar 12, 2024
bed854d
Merge branch 'main' into use-data-stream-global-retention-metadata
gmarouli Mar 12, 2024
e36d47a
Checkpont
gmarouli Mar 12, 2024
758cbbf
Merge with main
gmarouli Mar 19, 2024
83c4b93
format
gmarouli Mar 19, 2024
c696e52
rounding up tests & polishing
gmarouli Mar 19, 2024
39aeb28
Fix tests
gmarouli Mar 19, 2024
f95180d
Remove seeds
gmarouli Mar 19, 2024
c310f52
Merge branch 'main' into use-data-stream-global-retention-metadata
gmarouli Mar 20, 2024
3e8b2d5
Change the approach of adding the effective retention
gmarouli Mar 20, 2024
2da8616
Polishing
gmarouli Mar 20, 2024
fca0063
typo
gmarouli Mar 20, 2024
c5f8ad7
Fix test
gmarouli Mar 20, 2024
ce33ba9
Fix yaml test
gmarouli Mar 20, 2024
1150a64
Fix test
gmarouli Mar 20, 2024
79f6809
Remove seed
gmarouli Mar 20, 2024
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 @@ -130,14 +130,18 @@ The response will look like the following:
"name": "my-data-stream-1",
"lifecycle": {
"enabled": true,
"data_retention": "7d"
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
},
{
"name": "my-data-stream-2",
"lifecycle": {
"enabled": true,
"data_retention": "7d"
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ The response will look like:
"generation_time": "6.84s", <9>
"lifecycle": {
"enabled": true,
"data_retention": "30d" <10>
"data_retention": "30d",
"effective_retention": "30d" <10>
"retention_determined_by": "data_stream_configuration"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,24 @@ The result will look like this:
{
"data_streams": [
{
"name": "my-data-stream",<1>
"name": "my-data-stream", <1>
"lifecycle": {
"enabled": true, <2>
"data_retention": "7d" <3>
"enabled": true, <2>
"data_retention": "7d", <3>
"effective_retention": "7d", <4>
"retention_determined_by": "data_stream_configuration" <5>
}
}
]
}
--------------------------------------------------
<1> The name of your data stream.
<2> Shows if the data stream lifecycle is enabled for this data stream.
<3> The retention period of the data indexed in this data stream, this means that the data in this data stream will
<3> The desired retention period of the data indexed in this data stream, this means that if there are no other limitations
the data for this data stream will be preserved for at least 7 days.
<4> The effective retention, this means that the data in this data stream will
be kept at least for 7 days. After that {es} can delete it at its own discretion.
<5> The configuration that determined the effective retention.

If you want to see more information about how the data stream lifecycle is applied on individual backing indices use the
<<data-streams-explain-lifecycle,explain data stream lifecycle API>>:
Expand All @@ -128,7 +133,9 @@ The result will look like this:
"time_since_index_creation": "1.6m", <3>
"lifecycle": { <4>
"enabled": true,
"data_retention": "7d"
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ PUT _index_template/dsl-data-stream-template
"template": {
"settings": {
"index.lifecycle.name": "pre-dsl-ilm-policy",
"index.lifecycle.prefer_ilm": false <1>
"index.lifecycle.prefer_ilm": false <1>
},
"lifecycle": {
"data_retention": "7d" <2>
"lifecycle": { <2>
"data_retention": "7d" <3>
}
}
}
Expand All @@ -215,6 +215,8 @@ PUT _index_template/dsl-data-stream-template
precedence over data stream lifecycle.
<2> We're configuring the data stream lifecycle so _new_ data streams will be
managed by data stream lifecycle.
<3> The desired retention, meaning that this data stream should keep the data for at least 7 days,
if this retention is possible.

We've now made sure that new data streams will be managed by data stream lifecycle.

Expand Down Expand Up @@ -268,7 +270,9 @@ GET _data_stream/dsl-data-stream
"template": "dsl-data-stream-template",
"lifecycle": {
"enabled": true,
"data_retention": "7d"
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
},
"ilm_policy": "pre-dsl-ilm-policy",
"next_generation_managed_by": "Data stream lifecycle", <3>
Expand Down Expand Up @@ -346,7 +350,9 @@ GET _data_stream/dsl-data-stream
"template": "dsl-data-stream-template",
"lifecycle": {
"enabled": true,
"data_retention": "7d"
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
},
"ilm_policy": "pre-dsl-ilm-policy",
"next_generation_managed_by": "Data stream lifecycle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.health.ClusterStateHealth;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
Expand Down Expand Up @@ -199,7 +200,8 @@ static GetDataStreamAction.Response innerOperation(
}
return new GetDataStreamAction.Response(
dataStreamInfos,
request.includeDefaults() ? clusterSettings.get(DataStreamLifecycle.CLUSTER_LIFECYCLE_DEFAULT_ROLLOVER_SETTING) : null
request.includeDefaults() ? clusterSettings.get(DataStreamLifecycle.CLUSTER_LIFECYCLE_DEFAULT_ROLLOVER_SETTING) : null,
DataStreamGlobalRetention.getFromClusterState(state)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.datastreams.lifecycle.action;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
Expand All @@ -16,6 +17,8 @@
import org.elasticsearch.action.datastreams.lifecycle.ExplainIndexDataStreamLifecycle;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -136,23 +139,33 @@ public Request indicesOptions(IndicesOptions indicesOptions) {
}

/**
* Class representing the response for the explain of the data stream lifecycle action for one or more indices.
* Class representing the response for the 'explain' of the data stream lifecycle action for one or more indices.
*/
public static class Response extends ActionResponse implements ChunkedToXContentObject {
public static final ParseField INDICES_FIELD = new ParseField("indices");
private List<ExplainIndexDataStreamLifecycle> indices;
private final List<ExplainIndexDataStreamLifecycle> indices;
@Nullable
private final RolloverConfiguration rolloverConfiguration;
@Nullable
private final DataStreamGlobalRetention globalRetention;

public Response(List<ExplainIndexDataStreamLifecycle> indices, @Nullable RolloverConfiguration rolloverConfiguration) {
public Response(
List<ExplainIndexDataStreamLifecycle> indices,
@Nullable RolloverConfiguration rolloverConfiguration,
@Nullable DataStreamGlobalRetention globalRetention
) {
this.indices = indices;
this.rolloverConfiguration = rolloverConfiguration;
this.globalRetention = globalRetention;
}

public Response(StreamInput in) throws IOException {
super(in);
this.indices = in.readCollectionAsList(ExplainIndexDataStreamLifecycle::new);
this.rolloverConfiguration = in.readOptionalWriteable(RolloverConfiguration::new);
this.globalRetention = in.getTransportVersion().onOrAfter(TransportVersions.USE_DATA_STREAM_GLOBAL_RETENTION)
? in.readOptionalWriteable(DataStreamGlobalRetention::read)
: null;
}

public List<ExplainIndexDataStreamLifecycle> getIndices() {
Expand All @@ -163,10 +176,17 @@ public RolloverConfiguration getRolloverConfiguration() {
return rolloverConfiguration;
}

public DataStreamGlobalRetention getGlobalRetention() {
return globalRetention;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeCollection(indices);
out.writeOptionalWriteable(rolloverConfiguration);
if (out.getTransportVersion().onOrAfter(TransportVersions.USE_DATA_STREAM_GLOBAL_RETENTION)) {
out.writeOptionalWriteable(globalRetention);
}
}

@Override
Expand All @@ -178,12 +198,14 @@ public boolean equals(Object o) {
return false;
}
Response response = (Response) o;
return Objects.equals(indices, response.indices) && Objects.equals(rolloverConfiguration, response.rolloverConfiguration);
return Objects.equals(indices, response.indices)
&& Objects.equals(rolloverConfiguration, response.rolloverConfiguration)
&& Objects.equals(globalRetention, response.globalRetention);
}

@Override
public int hashCode() {
return Objects.hash(indices, rolloverConfiguration);
return Objects.hash(indices, rolloverConfiguration, globalRetention);
}

@Override
Expand All @@ -194,7 +216,11 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
return builder;
}), Iterators.map(indices.iterator(), explainIndexDataLifecycle -> (builder, params) -> {
builder.field(explainIndexDataLifecycle.getIndex());
explainIndexDataLifecycle.toXContent(builder, params, rolloverConfiguration);
ToXContent.Params withEffectiveRetentionParams = new ToXContent.DelegatingMapParams(
DataStreamLifecycle.INCLUDE_EFFECTIVE_RETENTION_PARAMS,
params
);
explainIndexDataLifecycle.toXContent(builder, withEffectiveRetentionParams, rolloverConfiguration, globalRetention);
return builder;
}), Iterators.single((builder, params) -> {
builder.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
*/
package org.elasticsearch.datastreams.lifecycle.action;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -157,19 +159,24 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return toXContent(builder, params, null);
return toXContent(builder, params, null, null);
}

/**
* Converts the response to XContent and passes the RolloverConditions, when provided, to the data stream lifecycle.
* Converts the response to XContent and passes the RolloverConditions and the global retention, when provided,
* to the data stream lifecycle.
*/
public XContentBuilder toXContent(XContentBuilder builder, Params params, @Nullable RolloverConfiguration rolloverConfiguration)
throws IOException {
public XContentBuilder toXContent(
XContentBuilder builder,
Params params,
@Nullable RolloverConfiguration rolloverConfiguration,
@Nullable DataStreamGlobalRetention globalRetention
) throws IOException {
builder.startObject();
builder.field(NAME_FIELD.getPreferredName(), dataStreamName);
if (lifecycle != null) {
builder.field(LIFECYCLE_FIELD.getPreferredName());
lifecycle.toXContent(builder, params, rolloverConfiguration);
lifecycle.toXContent(builder, params, rolloverConfiguration, globalRetention);
}
builder.endObject();
return builder;
Expand All @@ -179,18 +186,31 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params, @Nulla
private final List<DataStreamLifecycle> dataStreamLifecycles;
@Nullable
private final RolloverConfiguration rolloverConfiguration;
@Nullable
private final DataStreamGlobalRetention globalRetention;

public Response(List<DataStreamLifecycle> dataStreamLifecycles) {
this(dataStreamLifecycles, null);
this(dataStreamLifecycles, null, null);
}

public Response(List<DataStreamLifecycle> dataStreamLifecycles, @Nullable RolloverConfiguration rolloverConfiguration) {
public Response(
List<DataStreamLifecycle> dataStreamLifecycles,
@Nullable RolloverConfiguration rolloverConfiguration,
@Nullable DataStreamGlobalRetention globalRetention
) {
this.dataStreamLifecycles = dataStreamLifecycles;
this.rolloverConfiguration = rolloverConfiguration;
this.globalRetention = globalRetention;
}

public Response(StreamInput in) throws IOException {
this(in.readCollectionAsList(Response.DataStreamLifecycle::new), in.readOptionalWriteable(RolloverConfiguration::new));
this(
in.readCollectionAsList(Response.DataStreamLifecycle::new),
in.readOptionalWriteable(RolloverConfiguration::new),
in.getTransportVersion().onOrAfter(TransportVersions.USE_DATA_STREAM_GLOBAL_RETENTION)
? in.readOptionalWriteable(DataStreamGlobalRetention::read)
: null
);
}

public List<DataStreamLifecycle> getDataStreamLifecycles() {
Expand All @@ -206,6 +226,9 @@ public RolloverConfiguration getRolloverConfiguration() {
public void writeTo(StreamOutput out) throws IOException {
out.writeCollection(dataStreamLifecycles);
out.writeOptionalWriteable(rolloverConfiguration);
if (out.getTransportVersion().onOrAfter(TransportVersions.USE_DATA_STREAM_GLOBAL_RETENTION)) {
out.writeOptionalWriteable(globalRetention);
}
}

@Override
Expand All @@ -214,17 +237,17 @@ public Iterator<ToXContent> toXContentChunked(ToXContent.Params outerParams) {
builder.startObject();
builder.startArray(DATA_STREAMS_FIELD.getPreferredName());
return builder;
}),
Iterators.map(
dataStreamLifecycles.iterator(),
dataStreamLifecycle -> (builder, params) -> dataStreamLifecycle.toXContent(builder, params, rolloverConfiguration)
),
Iterators.single((builder, params) -> {
builder.endArray();
builder.endObject();
return builder;
})
);
}), Iterators.map(dataStreamLifecycles.iterator(), dataStreamLifecycle -> (builder, params) -> {
ToXContent.Params withEffectiveRetentionParams = new ToXContent.DelegatingMapParams(
org.elasticsearch.cluster.metadata.DataStreamLifecycle.INCLUDE_EFFECTIVE_RETENTION_PARAMS,
params
);
return dataStreamLifecycle.toXContent(builder, withEffectiveRetentionParams, rolloverConfiguration, globalRetention);
}), Iterators.single((builder, params) -> {
builder.endArray();
builder.endObject();
return builder;
}));
}

@Override
Expand All @@ -233,12 +256,13 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Response response = (Response) o;
return dataStreamLifecycles.equals(response.dataStreamLifecycles)
&& Objects.equals(rolloverConfiguration, response.rolloverConfiguration);
&& Objects.equals(rolloverConfiguration, response.rolloverConfiguration)
&& Objects.equals(globalRetention, response.globalRetention);
}

@Override
public int hashCode() {
return Objects.hash(dataStreamLifecycles, rolloverConfiguration);
return Objects.hash(dataStreamLifecycles, rolloverConfiguration, globalRetention);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention;
import org.elasticsearch.cluster.metadata.DataStreamLifecycle;
import org.elasticsearch.cluster.metadata.IndexAbstraction;
import org.elasticsearch.cluster.metadata.IndexMetadata;
Expand Down Expand Up @@ -111,7 +112,8 @@ protected void masterOperation(
listener.onResponse(
new ExplainDataStreamLifecycleAction.Response(
explainIndices,
request.includeDefaults() ? clusterSettings.get(DataStreamLifecycle.CLUSTER_LIFECYCLE_DEFAULT_ROLLOVER_SETTING) : null
request.includeDefaults() ? clusterSettings.get(DataStreamLifecycle.CLUSTER_LIFECYCLE_DEFAULT_ROLLOVER_SETTING) : null,
DataStreamGlobalRetention.getFromClusterState(state)
)
);
}
Expand Down
Loading