Skip to content

Commit 51eaf4b

Browse files
authored
Disable downsampling force merge via mapping metadata (#135694)
In this PR we introduce a mapping metadata field that allows us to skip the force-merge request during a downsamping API request. When an index has the `downsample.forcemerge.enabled` in their mapping metadata, they can enable or disable the force merge: ``` { "_meta": { "downsample.forcemerge.enabled": false } } ``` By default, force merge is enabled to match the current user experience.
1 parent b40021a commit 51eaf4b

File tree

4 files changed

+549
-44
lines changed

4 files changed

+549
-44
lines changed

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DownsampleIT.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.IOException;
3232
import java.time.Instant;
3333
import java.util.List;
34+
import java.util.Locale;
3435
import java.util.concurrent.TimeUnit;
3536
import java.util.function.Supplier;
3637

@@ -44,8 +45,9 @@ public class DownsampleIT extends DownsamplingIntegTestCase {
4445

4546
public void testDownsamplingPassthroughDimensions() throws Exception {
4647
String dataStreamName = "metrics-foo";
47-
String mapping = """
48+
String mapping = String.format(Locale.ROOT, """
4849
{
50+
%s
4951
"properties": {
5052
"attributes": {
5153
"type": "passthrough",
@@ -64,7 +66,7 @@ public void testDownsamplingPassthroughDimensions() throws Exception {
6466
}
6567
}
6668
}
67-
""";
69+
""", generateForceMergeMetadata());
6870

6971
// Create data stream by indexing documents
7072
final Instant now = Instant.now();
@@ -171,6 +173,16 @@ private void downsampleAndAssert(String dataStreamName, String mapping, Supplier
171173
assertDownsampleIndexFieldsAndDimensions(sourceIndex, targetIndex, downsampleConfig);
172174
}
173175

176+
private String generateForceMergeMetadata() {
177+
return switch (randomIntBetween(0, 4)) {
178+
case 0 -> "\"_meta\": { \"downsample.forcemerge.enabled\": false},";
179+
case 1 -> "\"_meta\": { \"downsample.forcemerge.enabled\": true},";
180+
case 2 -> "\"_meta\": { \"downsample.forcemerge.enabled\": 4},";
181+
case 3 -> "\"_meta\": { \"downsample.forcemerge.enabled\": null},";
182+
default -> "";
183+
};
184+
}
185+
174186
public void testAggMetricInEsqlTSAfterDownsampling() throws Exception {
175187
String dataStreamName = "metrics-foo";
176188
Settings settings = Settings.builder().put("mode", "time_series").putList("routing_path", List.of("host", "cluster")).build();

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DownsamplingIntegTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ void assertDownsampleIndexFieldsAndDimensions(String sourceIndex, String downsam
264264
final CompressedXContent sourceIndexCompressedXContent = new CompressedXContent(sourceIndexMappings);
265265
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, sourceIndexCompressedXContent, MapperService.MergeReason.INDEX_TEMPLATE);
266266

267+
assertThat(downsampleIndexMappings.get("_meta"), equalTo(sourceIndexMappings.get("_meta")));
268+
267269
// Collect expected mappings for fields and dimensions
268270
Map<String, TimeSeriesParams.MetricType> metricFields = new HashMap<>();
269271
Map<String, String> dimensionFields = new HashMap<>();

0 commit comments

Comments
 (0)