21
21
import org .elasticsearch .index .IndexMode ;
22
22
import org .elasticsearch .index .IndexSettings ;
23
23
import org .elasticsearch .index .IndexVersion ;
24
+ import org .elasticsearch .index .IndexVersions ;
24
25
import org .elasticsearch .index .MapperTestUtils ;
25
26
import org .elasticsearch .index .mapper .DocumentMapper ;
26
27
import org .elasticsearch .index .mapper .MapperService ;
27
28
import org .elasticsearch .test .ESTestCase ;
29
+ import org .elasticsearch .test .index .IndexVersionUtils ;
28
30
import org .junit .Before ;
29
31
30
32
import java .io .IOException ;
@@ -48,12 +50,19 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
48
50
private static final TimeValue DEFAULT_LOOK_AHEAD_TIME = TimeValue .timeValueMinutes (30 ); // default
49
51
50
52
DataStreamIndexSettingsProvider provider ;
53
+ private boolean indexDimensionsTsidOptimizationEnabled ;
54
+ private IndexVersion indexVersion ;
51
55
52
56
@ Before
53
57
public void setup () {
54
58
provider = new DataStreamIndexSettingsProvider (
55
59
im -> MapperTestUtils .newMapperService (xContentRegistry (), createTempDir (), im .getSettings (), im .getIndex ().getName ())
56
60
);
61
+ indexVersion = randomBoolean ()
62
+ ? IndexVersionUtils .randomPreviousCompatibleVersion (random (), IndexVersions .TSID_CREATED_DURING_ROUTING )
63
+ : IndexVersionUtils .randomVersionBetween (random (), IndexVersions .TSID_CREATED_DURING_ROUTING , IndexVersion .current ());
64
+ indexDimensionsTsidOptimizationEnabled = INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG
65
+ && indexVersion .onOrAfter (IndexVersions .TSID_CREATED_DURING_ROUTING );
57
66
}
58
67
59
68
public void testGetAdditionalIndexSettings () throws Exception {
@@ -101,21 +110,22 @@ public void testGetAdditionalIndexSettings() throws Exception {
101
110
now ,
102
111
settings ,
103
112
List .of (new CompressedXContent (mapping )),
104
- IndexVersion . current () ,
113
+ indexVersion ,
105
114
additionalSettings
106
115
);
107
116
Settings result = additionalSettings .build ();
108
117
// The index.time_series.end_time setting requires index.mode to be set to time_series adding it here so that we read this setting:
109
118
// (in production the index.mode setting is usually provided in an index or component template)
110
119
result = builder ().put (result ).put ("index.mode" , "time_series" ).build ();
111
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
120
+ assertThat (result .size (), equalTo (4 ));
112
121
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
113
122
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
114
123
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
115
- assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("field3" , "field4" , "field5" , "field6" ));
116
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
124
+ if (indexDimensionsTsidOptimizationEnabled ) {
117
125
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("field3" , "field4" , "field5" , "field6" ));
126
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), empty ());
118
127
} else {
128
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("field3" , "field4" , "field5" , "field6" ));
119
129
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
120
130
}
121
131
}
@@ -155,7 +165,7 @@ public void testGetAdditionalIndexSettingsIndexRoutingPathAlreadyDefined() throw
155
165
now ,
156
166
settings ,
157
167
List .of (new CompressedXContent (mapping )),
158
- IndexVersion . current () ,
168
+ indexVersion ,
159
169
additionalSettings
160
170
);
161
171
Settings result = additionalSettings .build ();
@@ -229,21 +239,22 @@ public void testGetAdditionalIndexSettingsMappingsMerging() throws Exception {
229
239
now ,
230
240
settings ,
231
241
List .of (new CompressedXContent (mapping1 ), new CompressedXContent (mapping2 ), new CompressedXContent (mapping3 )),
232
- IndexVersion . current () ,
242
+ indexVersion ,
233
243
additionalSettings
234
244
);
235
245
Settings result = additionalSettings .build ();
236
246
// The index.time_series.end_time setting requires index.mode to be set to time_series adding it here so that we read this setting:
237
247
// (in production the index.mode setting is usually provided in an index or component template)
238
248
result = builder ().put (result ).put ("index.mode" , "time_series" ).build ();
239
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
249
+ assertThat (result .size (), equalTo (4 ));
240
250
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
241
251
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
242
252
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
243
- assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("field1" , "field3" ));
244
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
253
+ if (indexDimensionsTsidOptimizationEnabled ) {
245
254
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("field1" , "field3" ));
255
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), empty ());
246
256
} else {
257
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("field1" , "field3" ));
247
258
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
248
259
}
249
260
}
@@ -263,7 +274,7 @@ public void testGetAdditionalIndexSettingsNoMappings() {
263
274
now ,
264
275
settings ,
265
276
List .of (),
266
- IndexVersion . current () ,
277
+ indexVersion ,
267
278
additionalSettings
268
279
);
269
280
Settings result = additionalSettings .build ();
@@ -292,7 +303,7 @@ public void testGetAdditionalIndexSettingsLookAheadTime() throws Exception {
292
303
now ,
293
304
settings ,
294
305
List .of (new CompressedXContent ("{}" )),
295
- IndexVersion . current () ,
306
+ indexVersion ,
296
307
additionalSettings
297
308
);
298
309
Settings result = additionalSettings .build ();
@@ -321,7 +332,7 @@ public void testGetAdditionalIndexSettingsLookBackTime() throws Exception {
321
332
now ,
322
333
settings ,
323
334
List .of (new CompressedXContent ("{}" )),
324
- IndexVersion . current () ,
335
+ indexVersion ,
325
336
additionalSettings
326
337
);
327
338
Settings result = additionalSettings .build ();
@@ -357,7 +368,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreated() throws Exce
357
368
now ,
358
369
settings ,
359
370
List .of (new CompressedXContent ("{}" )),
360
- IndexVersion . current () ,
371
+ indexVersion ,
361
372
additionalSettings
362
373
);
363
374
var result = additionalSettings .build ();
@@ -397,7 +408,7 @@ public void testGetAdditionalIndexSettingsDataStreamAlreadyCreatedTimeSettingsMi
397
408
now ,
398
409
settings ,
399
410
null ,
400
- IndexVersion . current () ,
411
+ indexVersion ,
401
412
builder ()
402
413
)
403
414
);
@@ -426,7 +437,7 @@ public void testGetAdditionalIndexSettingsNonTsdbTemplate() {
426
437
Instant .ofEpochMilli (1L ),
427
438
settings ,
428
439
null ,
429
- IndexVersion . current () ,
440
+ indexVersion ,
430
441
additionalSettings
431
442
);
432
443
Settings result = additionalSettings .build ();
@@ -452,7 +463,7 @@ public void testGetAdditionalIndexSettingsMigrateToTsdb() {
452
463
now ,
453
464
settings ,
454
465
List .of (),
455
- IndexVersion . current () ,
466
+ indexVersion ,
456
467
additionalSettings
457
468
);
458
469
Settings result = additionalSettings .build ();
@@ -485,7 +496,7 @@ public void testGetAdditionalIndexSettingsDowngradeFromTsdb() {
485
496
Instant .ofEpochMilli (1L ),
486
497
Settings .EMPTY ,
487
498
List .of (),
488
- IndexVersion . current () ,
499
+ indexVersion ,
489
500
additionalSettings
490
501
);
491
502
Settings result = additionalSettings .build ();
@@ -706,14 +717,15 @@ public void testGenerateNonDimensionDynamicTemplate() throws Exception {
706
717
}
707
718
""" ;
708
719
Settings result = generateTsdbSettings (mapping , now );
709
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
720
+ assertThat (result .size (), equalTo (4 ));
710
721
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
711
722
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
712
723
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
713
- assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("host.id" ));
714
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
724
+ if (indexDimensionsTsidOptimizationEnabled ) {
715
725
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("host.id" ));
726
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), empty ());
716
727
} else {
728
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("host.id" ));
717
729
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
718
730
}
719
731
}
@@ -793,14 +805,15 @@ public void testGenerateRoutingPathFromPassThroughObject() throws Exception {
793
805
}
794
806
""" ;
795
807
Settings result = generateTsdbSettings (mapping , now );
796
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
808
+ assertThat (result .size (), equalTo (4 ));
797
809
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
798
810
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
799
811
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
800
- assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("labels.*" ));
801
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
812
+ if (indexDimensionsTsidOptimizationEnabled ) {
802
813
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("labels.*" ));
814
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), empty ());
803
815
} else {
816
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("labels.*" ));
804
817
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
805
818
}
806
819
}
@@ -943,9 +956,10 @@ public void testAddDynamicTemplate() throws Exception {
943
956
}
944
957
""" ;
945
958
// we don't support index.dimensions with dynamic templates so we'll unset index.dimensions
946
- Settings result = onUpdateMappings ("labels.*" , "labels.*" , mapping );
947
- assertThat (result .size (), equalTo (1 ));
959
+ Settings result = onUpdateMappings (null , "labels.*" , mapping );
960
+ assertThat (result .size (), equalTo (2 ));
948
961
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
962
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("labels.*" ));
949
963
}
950
964
951
965
private Settings generateTsdbSettings (String mapping , Instant now ) throws IOException {
@@ -962,7 +976,7 @@ private Settings generateTsdbSettings(String mapping, Instant now) throws IOExce
962
976
now ,
963
977
settings ,
964
978
List .of (new CompressedXContent (mapping )),
965
- IndexVersion . current () ,
979
+ indexVersion ,
966
980
additionalSettings
967
981
);
968
982
var result = additionalSettings .build ();
@@ -976,7 +990,7 @@ private Settings onUpdateMappings(String routingPath, String dimensions, String
976
990
Settings .Builder currentSettings = Settings .builder ()
977
991
.put (IndexMetadata .INDEX_ROUTING_PATH .getKey (), routingPath )
978
992
.put (IndexMetadata .INDEX_DIMENSIONS .getKey (), dimensions )
979
- .put (IndexMetadata .SETTING_VERSION_CREATED , IndexVersion . current () )
993
+ .put (IndexMetadata .SETTING_VERSION_CREATED , indexVersion )
980
994
.put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
981
995
.put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
982
996
.put (IndexMetadata .SETTING_INDEX_UUID , UUIDs .randomBase64UUID ())
0 commit comments