Skip to content

Commit 7bb4583

Browse files
authored
Introduce the index.downsample.origin.name and index.downsample.origin.uuid settings (#99061) (#99182)
This proposes introducing two new settings we configure when downsampling: `index.downsample.origin.name` `index.downsample.origin.uuid` These settings will carry on the name and uuid of the first source index we downsample (like the source.name and source.uuid settings behaved before this PR). This also changes the behaviour of `index.downsample.source.name` and `index.downsample.source.uuid` to always reflect the source of the current downsampling round. If an index is downsampled once, both the source and origin settings will have the same value. However, for subsequent downsampling operations, a later downsampling round will have the actual index name and uuid that were used as the source of the downsampling operation configured e.g. `downsample-350s-.ds-metrics-foo-2023.08.17-000001` will have the `index.downsample.source.name` configured to `downsample-1s-.ds-metrics-foo-2023.08.17-000001` and `index.downsample.origin.name` configured to `.ds-metrics-foo-2023.08.17-000001`. Note that this will help us simplify things in data stream lifecycle as with subsequent downsampling configuration we currently have to store the true source of the downsampling operation in the downsample index metadata ( https://github.com/elastic/elasticsearch/blob/main/modules/data-streams/src/main/java/org/elasticsearch/datastreams/lifecycle/downsampling/ReplaceSourceWithDownsampleIndexTask.java#L173 ) If you agree with this proposal we'll have to manually backport to 8.10 as well to make sure the `generateDownsampleIndexName` method is consistent across releases https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/action/downsample/DownsampleConfig.java#L249 Note that the `index.provided_name` setting which is set on indices when rolling over cannot act like a source (initially I thought we can use that instead of introducing a new setting, the origin one) because it contains date-math patterns. (cherry picked from commit 6c3a464) Signed-off-by: Andrei Dan <[email protected]>
1 parent fe27a1e commit 7bb4583

File tree

7 files changed

+61
-14
lines changed

7 files changed

+61
-14
lines changed

server/src/main/java/org/elasticsearch/action/downsample/DownsampleConfig.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static Rounding.Prepared createRounding(final String expr, final String t
242242
* prefix-fixedInterval-baseIndexName
243243
*
244244
* Note that this looks for the base index name of the provided index metadata via the
245-
* {@link IndexMetadata#INDEX_DOWNSAMPLE_SOURCE_NAME_KEY} setting. This means that in case
245+
* {@link IndexMetadata#INDEX_DOWNSAMPLE_ORIGIN_NAME_KEY} setting. This means that in case
246246
* the provided index was already downsampled, we'll use the original source index (of the
247247
* current provided downsample index) as the base index name.
248248
*/
@@ -251,10 +251,13 @@ public static String generateDownsampleIndexName(
251251
IndexMetadata sourceIndexMetadata,
252252
DateHistogramInterval fixedInterval
253253
) {
254-
String downsampleSourceName = sourceIndexMetadata.getSettings().get(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME_KEY);
254+
String downsampleOriginName = IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME.get(sourceIndexMetadata.getSettings());
255255
String sourceIndexName;
256-
if (downsampleSourceName != null) {
257-
sourceIndexName = downsampleSourceName;
256+
if (Strings.hasText(downsampleOriginName)) {
257+
sourceIndexName = downsampleOriginName;
258+
} else if (Strings.hasText(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.get(sourceIndexMetadata.getSettings()))) {
259+
// bwc for downsample indices created pre 8.10 which didn't configure the origin
260+
sourceIndexName = IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.get(sourceIndexMetadata.getSettings());
258261
} else {
259262
sourceIndexName = sourceIndexMetadata.getIndex().getName();
260263
}

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

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

12281228
public static final String INDEX_DOWNSAMPLE_SOURCE_UUID_KEY = "index.downsample.source.uuid";
12291229
public static final String INDEX_DOWNSAMPLE_SOURCE_NAME_KEY = "index.downsample.source.name";
1230+
public static final String INDEX_DOWNSAMPLE_ORIGIN_NAME_KEY = "index.downsample.origin.name";
1231+
public static final String INDEX_DOWNSAMPLE_ORIGIN_UUID_KEY = "index.downsample.origin.uuid";
12301232

12311233
public static final String INDEX_DOWNSAMPLE_STATUS_KEY = "index.downsample.status";
12321234
public static final Setting<String> INDEX_DOWNSAMPLE_SOURCE_UUID = Setting.simpleString(
@@ -1240,6 +1242,18 @@ public Index getResizeSourceIndex() {
12401242
Property.PrivateIndex
12411243
);
12421244

1245+
public static final Setting<String> INDEX_DOWNSAMPLE_ORIGIN_NAME = Setting.simpleString(
1246+
INDEX_DOWNSAMPLE_ORIGIN_NAME_KEY,
1247+
Property.IndexScope,
1248+
Property.PrivateIndex
1249+
);
1250+
1251+
public static final Setting<String> INDEX_DOWNSAMPLE_ORIGIN_UUID = Setting.simpleString(
1252+
INDEX_DOWNSAMPLE_ORIGIN_UUID_KEY,
1253+
Property.IndexScope,
1254+
Property.PrivateIndex
1255+
);
1256+
12431257
public enum DownsampleTaskStatus {
12441258
UNKNOWN,
12451259
STARTED,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
7272
IndexMetadata.INDEX_FORMAT_SETTING,
7373
IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME,
7474
IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_UUID,
75+
IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME,
76+
IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_UUID,
7577
IndexMetadata.INDEX_DOWNSAMPLE_STATUS,
7678
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG_SETTING,
7779
SearchSlowLog.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN_SETTING,

server/src/test/java/org/elasticsearch/action/downsample/DonwsampleConfigTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ public void testGenerateDownsampleIndexName() {
2828
{
2929
String downsampledIndex = "downsample-1h-test";
3030
IndexMetadata indexMeta = IndexMetadata.builder(downsampledIndex)
31-
.settings(indexSettings(IndexVersion.current(), 1, 0).put(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME_KEY, "test"))
31+
.settings(indexSettings(IndexVersion.current(), 1, 0).put(IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME_KEY, "test"))
32+
.build();
33+
assertThat(generateDownsampleIndexName("downsample-", indexMeta, new DateHistogramInterval("8h")), is("downsample-8h-test"));
34+
}
35+
36+
{
37+
// test origin takes higher precedence than the configured source setting
38+
String downsampledIndex = "downsample-1h-test";
39+
IndexMetadata indexMeta = IndexMetadata.builder(downsampledIndex)
40+
.settings(
41+
indexSettings(IndexVersion.current(), 1, 0).put(IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME_KEY, "test")
42+
.put(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME_KEY, "downsample-1s-test")
43+
)
3244
.build();
3345
assertThat(generateDownsampleIndexName("downsample-", indexMeta, new DateHistogramInterval("8h")), is("downsample-8h-test"));
3446
}

x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,17 +680,19 @@ static IndexMetadata.Builder copyIndexMetadata(
680680
}
681681

682682
/*
683-
* Add the source index name and UUID to the downsample index metadata.
684-
* If the source index is a downsample index, we will add the name and UUID
683+
* Add the origin index name and UUID to the downsample index metadata.
684+
* If the origin index is a downsample index, we will add the name and UUID
685685
* of the first index that we initially rolled up.
686686
*/
687-
if (IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_UUID.exists(sourceIndexMetadata.getSettings()) == false
688-
|| IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.exists(sourceIndexMetadata.getSettings()) == false) {
689-
Index sourceIndex = sourceIndexMetadata.getIndex();
690-
targetSettings.put(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.getKey(), sourceIndex.getName())
691-
.put(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_UUID.getKey(), sourceIndex.getUUID());
687+
Index sourceIndex = sourceIndexMetadata.getIndex();
688+
if (IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_UUID.exists(sourceIndexMetadata.getSettings()) == false
689+
|| IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME.exists(sourceIndexMetadata.getSettings()) == false) {
690+
targetSettings.put(IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME.getKey(), sourceIndex.getName())
691+
.put(IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_UUID.getKey(), sourceIndex.getUUID());
692692
}
693693

694+
targetSettings.put(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME_KEY, sourceIndex.getName());
695+
targetSettings.put(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_UUID_KEY, sourceIndex.getUUID());
694696
return IndexMetadata.builder(downsampleIndexMetadata).settings(targetSettings);
695697
}
696698

x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
3434
import org.elasticsearch.cluster.metadata.IndexMetadata;
3535
import org.elasticsearch.cluster.metadata.Template;
36+
import org.elasticsearch.common.Strings;
3637
import org.elasticsearch.common.compress.CompressedXContent;
3738
import org.elasticsearch.common.document.DocumentField;
3839
import org.elasticsearch.common.network.NetworkAddress;
@@ -339,7 +340,7 @@ public void testDownsampleOfDownsample() throws IOException {
339340
String downsampleIndex2 = downsampleIndex + "-2";
340341
DownsampleConfig config2 = new DownsampleConfig(DateHistogramInterval.minutes(intervalMinutes * randomIntBetween(2, 50)));
341342
downsample(downsampleIndex, downsampleIndex2, config2);
342-
assertDownsampleIndex(sourceIndex, downsampleIndex2, config2);
343+
assertDownsampleIndex(downsampleIndex, downsampleIndex2, config2);
343344
}
344345

345346
private Date randomDate() {
@@ -1278,6 +1279,18 @@ private void assertDownsampleIndexSettings(String sourceIndex, String downsample
12781279
assertEquals(sourceIndex, downsampleSettings.get(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME_KEY));
12791280
assertEquals(sourceSettings.get(IndexSettings.MODE.getKey()), downsampleSettings.get(IndexSettings.MODE.getKey()));
12801281

1282+
if (Strings.hasText(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.get(sourceSettings))) {
1283+
// if the source is a downsample index itself, we're in the "downsample of downsample" test case and both indices should have
1284+
// the same ORIGIN configured
1285+
assertEquals(
1286+
IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME.get(sourceSettings),
1287+
IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME.get(downsampleSettings)
1288+
);
1289+
assertEquals(
1290+
IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_UUID.get(sourceSettings),
1291+
IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_UUID.get(downsampleSettings)
1292+
);
1293+
}
12811294
assertNotNull(sourceSettings.get(IndexSettings.TIME_SERIES_START_TIME.getKey()));
12821295
assertNotNull(downsampleSettings.get(IndexSettings.TIME_SERIES_START_TIME.getKey()));
12831296
assertEquals(

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/DownsampleActionIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ public void testDownsampleTwice() throws Exception {
373373
assertThat(indexExists(downsampleIndexName), is(false));
374374

375375
Map<String, Object> settings = getOnlyIndexSettings(client(), downsampleOfDownsampleIndexName);
376-
assertEquals(firstBackingIndex, settings.get(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.getKey()));
376+
assertEquals(firstBackingIndex, settings.get(IndexMetadata.INDEX_DOWNSAMPLE_ORIGIN_NAME.getKey()));
377+
assertEquals(downsampleIndexName, settings.get(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME.getKey()));
377378
assertEquals(DownsampleTaskStatus.SUCCESS.toString(), settings.get(IndexMetadata.INDEX_DOWNSAMPLE_STATUS.getKey()));
378379
assertEquals(policy, settings.get(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey()));
379380
}, 60, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)