Skip to content

Commit d539957

Browse files
authored
TSDB: Implement downsampling on time-series indices (#85708)
This PR implements downsampling operation on time series indices. The PR creates a _rollup endpoint that allows users to downsample an index and can be accessed by the following call: POST /<source_index>/_rollup/<rollup_index> { "fixed_interval": "1d" } Requirements An index can be downsampled if all of the following requirements are met: Must be a time series index (have the index.mode: time_series index setting) Must not be writeable (have the index.blocks.write: true index setting) Must have dimension fields marked with mapping parameter time_series_dimension: true Must have metric fields marked with mapping parameter time_series_metric Relates to #74660 Fixes #65769 Fixes #69799 Finally, this PR is based on the code written for #64900
1 parent beadcaf commit d539957

File tree

40 files changed

+2060
-2603
lines changed

40 files changed

+2060
-2603
lines changed

docs/changelog/85708.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pr: 85708
2+
summary: "TSDB: Implement downsampling on time-series indices"
3+
area: TSDB
4+
type: feature
5+
issues:
6+
- 69799
7+
- 65769

server/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@
290290
exports org.elasticsearch.rest.action.document;
291291
exports org.elasticsearch.rest.action.ingest;
292292
exports org.elasticsearch.rest.action.search;
293-
exports org.elasticsearch.rollup;
294293
exports org.elasticsearch.script;
295294
exports org.elasticsearch.script.field;
296295
exports org.elasticsearch.search;

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ public Index getResizeSourceIndex() {
866866

867867
public static final String INDEX_ROLLUP_SOURCE_UUID_KEY = "index.rollup.source.uuid";
868868
public static final String INDEX_ROLLUP_SOURCE_NAME_KEY = "index.rollup.source.name";
869+
870+
public static final String INDEX_ROLLUP_STATUS_KEY = "index.rollup.status";
869871
public static final Setting<String> INDEX_ROLLUP_SOURCE_UUID = Setting.simpleString(
870872
INDEX_ROLLUP_SOURCE_UUID_KEY,
871873
Property.IndexScope,
@@ -877,6 +879,24 @@ public Index getResizeSourceIndex() {
877879
Property.PrivateIndex
878880
);
879881

882+
public enum RollupTaskStatus {
883+
STARTED,
884+
SUCCESS;
885+
886+
@Override
887+
public String toString() {
888+
return name().toLowerCase(Locale.ROOT);
889+
}
890+
}
891+
892+
public static final Setting<RollupTaskStatus> INDEX_ROLLUP_STATUS = Setting.enumSetting(
893+
RollupTaskStatus.class,
894+
INDEX_ROLLUP_STATUS_KEY,
895+
RollupTaskStatus.SUCCESS,
896+
Property.IndexScope,
897+
Property.InternalIndex
898+
);
899+
880900
// LIFECYCLE_NAME is here an as optimization, see LifecycleSettings.LIFECYCLE_NAME and
881901
// LifecycleSettings.LIFECYCLE_NAME_SETTING for the 'real' version
882902
public static final String LIFECYCLE_NAME = "index.lifecycle.name";

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
7373
IndexMetadata.INDEX_FORMAT_SETTING,
7474
IndexMetadata.INDEX_ROLLUP_SOURCE_NAME,
7575
IndexMetadata.INDEX_ROLLUP_SOURCE_UUID,
76+
IndexMetadata.INDEX_ROLLUP_STATUS,
7677
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING,
7778
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING,
7879
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO_SETTING,

server/src/main/java/org/elasticsearch/index/mapper/TimeSeriesParams.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ public final class TimeSeriesParams {
2323
private TimeSeriesParams() {}
2424

2525
public enum MetricType {
26-
gauge,
27-
counter,
28-
histogram,
29-
summary
26+
gauge(new String[] { "max", "min", "value_count", "sum" }),
27+
counter(new String[] { "last_value" }),
28+
histogram(new String[] { "value_count" }), // TODO Add more aggs
29+
summary(new String[] { "value_count", "sum", "min", "max" });
30+
31+
private final String[] supportedAggs;
32+
33+
MetricType(String[] supportedAggs) {
34+
this.supportedAggs = supportedAggs;
35+
}
36+
37+
public String[] supportedAggs() {
38+
return supportedAggs;
39+
}
3040
}
3141

3242
public static FieldMapper.Parameter<MetricType> metricParam(Function<FieldMapper, MetricType> initializer, MetricType... values) {

server/src/main/java/org/elasticsearch/rollup/RollupV2.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.cluster.metadata.Metadata;
1414
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1515
import org.elasticsearch.common.settings.Setting;
16+
import org.elasticsearch.index.IndexSettings;
1617
import org.elasticsearch.license.DeleteLicenseAction;
1718
import org.elasticsearch.license.GetBasicStatusAction;
1819
import org.elasticsearch.license.GetLicenseAction;
@@ -27,7 +28,6 @@
2728
import org.elasticsearch.plugins.ActionPlugin;
2829
import org.elasticsearch.plugins.NetworkPlugin;
2930
import org.elasticsearch.plugins.Plugin;
30-
import org.elasticsearch.rollup.RollupV2;
3131
import org.elasticsearch.tasks.Task;
3232
import org.elasticsearch.xcontent.NamedXContentRegistry;
3333
import org.elasticsearch.xcontent.ParseField;
@@ -412,8 +412,8 @@ public List<ActionType<? extends ActionResponse>> getClientActions() {
412412
)
413413
);
414414

415-
// rollupV2
416-
if (RollupV2.isEnabled()) {
415+
// TSDB Downsampling / Rollup
416+
if (IndexSettings.isTimeSeriesModeEnabled()) {
417417
actions.add(RollupIndexerAction.INSTANCE);
418418
actions.add(RollupAction.INSTANCE);
419419
}
@@ -566,7 +566,8 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
566566
)
567567
);
568568

569-
if (RollupV2.isEnabled()) {
569+
// TSDB Downsampling / Rollup
570+
if (IndexSettings.isTimeSeriesModeEnabled()) {
570571
namedWriteables.add(new NamedWriteableRegistry.Entry(LifecycleAction.class, RollupILMAction.NAME, RollupILMAction::new));
571572
}
572573

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.elasticsearch.common.io.stream.StreamOutput;
1111
import org.elasticsearch.common.util.set.Sets;
1212
import org.elasticsearch.core.TimeValue;
13-
import org.elasticsearch.rollup.RollupV2;
13+
import org.elasticsearch.index.IndexSettings;
1414

1515
import java.io.IOException;
1616
import java.util.ArrayList;
@@ -56,7 +56,7 @@ public class TimeseriesLifecycleType implements LifecycleType {
5656
UnfollowAction.NAME,
5757
RolloverAction.NAME,
5858
ReadOnlyAction.NAME,
59-
RollupV2.isEnabled() ? RollupILMAction.NAME : null,
59+
IndexSettings.isTimeSeriesModeEnabled() ? RollupILMAction.NAME : null,
6060
ShrinkAction.NAME,
6161
ForceMergeAction.NAME,
6262
SearchableSnapshotAction.NAME
@@ -78,7 +78,7 @@ public class TimeseriesLifecycleType implements LifecycleType {
7878
AllocateAction.NAME,
7979
MigrateAction.NAME,
8080
FreezeAction.NAME,
81-
RollupV2.isEnabled() ? RollupILMAction.NAME : null
81+
IndexSettings.isTimeSeriesModeEnabled() ? RollupILMAction.NAME : null
8282
).filter(Objects::nonNull).toList();
8383
public static final List<String> ORDERED_VALID_FROZEN_ACTIONS = List.of(UnfollowAction.NAME, SearchableSnapshotAction.NAME);
8484
public static final List<String> ORDERED_VALID_DELETE_ACTIONS = List.of(WaitForSnapshotAction.NAME, DeleteAction.NAME);

0 commit comments

Comments
 (0)