7
7
8
8
package org .elasticsearch .xpack .logsdb ;
9
9
10
+ import org .elasticsearch .Version ;
10
11
import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
11
12
import org .elasticsearch .cluster .metadata .ComposableIndexTemplateMetadata ;
12
13
import org .elasticsearch .cluster .metadata .DataStream ;
@@ -83,6 +84,10 @@ public void setup() throws Exception {
83
84
}
84
85
85
86
private LogsdbIndexModeSettingsProvider withSyntheticSourceDemotionSupport (boolean enabled ) {
87
+ return withSyntheticSourceDemotionSupport (enabled , Version .CURRENT );
88
+ }
89
+
90
+ private LogsdbIndexModeSettingsProvider withSyntheticSourceDemotionSupport (boolean enabled , Version version ) {
86
91
newMapperServiceCounter .set (0 );
87
92
var provider = new LogsdbIndexModeSettingsProvider (
88
93
logsdbLicenseService ,
@@ -91,15 +96,28 @@ private LogsdbIndexModeSettingsProvider withSyntheticSourceDemotionSupport(boole
91
96
provider .init (im -> {
92
97
newMapperServiceCounter .incrementAndGet ();
93
98
return MapperTestUtils .newMapperService (xContentRegistry (), createTempDir (), im .getSettings (), im .getIndex ().getName ());
94
- }, IndexVersion ::current , true , true );
99
+ }, IndexVersion ::current , () -> version , true , true );
100
+ return provider ;
101
+ }
102
+
103
+ private LogsdbIndexModeSettingsProvider withoutMapperService (boolean enabled ) {
104
+ var provider = new LogsdbIndexModeSettingsProvider (
105
+ logsdbLicenseService ,
106
+ Settings .builder ().put ("cluster.logsdb.enabled" , enabled ).build ()
107
+ );
108
+ provider .init (im -> null , IndexVersion ::current , () -> Version .CURRENT , true , true );
95
109
return provider ;
96
110
}
97
111
98
112
private Settings generateLogsdbSettings (Settings settings ) throws IOException {
99
- return generateLogsdbSettings (settings , null );
113
+ return generateLogsdbSettings (settings , null , Version . CURRENT );
100
114
}
101
115
102
116
private Settings generateLogsdbSettings (Settings settings , String mapping ) throws IOException {
117
+ return generateLogsdbSettings (settings , mapping , Version .CURRENT );
118
+ }
119
+
120
+ private Settings generateLogsdbSettings (Settings settings , String mapping , Version version ) throws IOException {
103
121
Metadata metadata = Metadata .EMPTY_METADATA ;
104
122
var provider = new LogsdbIndexModeSettingsProvider (
105
123
logsdbLicenseService ,
@@ -108,7 +126,7 @@ private Settings generateLogsdbSettings(Settings settings, String mapping) throw
108
126
provider .init (im -> {
109
127
newMapperServiceCounter .incrementAndGet ();
110
128
return MapperTestUtils .newMapperService (xContentRegistry (), createTempDir (), im .getSettings (), im .getIndex ().getName ());
111
- }, IndexVersion ::current , true , true );
129
+ }, IndexVersion ::current , () -> version , true , true );
112
130
var result = provider .getAdditionalIndexSettings (
113
131
DataStream .getDefaultBackingIndexName (DATA_STREAM_NAME , 0 ),
114
132
DATA_STREAM_NAME ,
@@ -217,11 +235,7 @@ public void testNonLogsDataStream() throws IOException {
217
235
}
218
236
219
237
public void testWithoutLogsComponentTemplate () throws IOException {
220
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
221
- logsdbLicenseService ,
222
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
223
- );
224
-
238
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (true );
225
239
final Settings additionalIndexSettings = provider .getAdditionalIndexSettings (
226
240
null ,
227
241
"logs-apache-production" ,
@@ -236,11 +250,7 @@ public void testWithoutLogsComponentTemplate() throws IOException {
236
250
}
237
251
238
252
public void testWithLogsComponentTemplate () throws IOException {
239
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
240
- logsdbLicenseService ,
241
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
242
- );
243
-
253
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (true );
244
254
final Settings additionalIndexSettings = provider .getAdditionalIndexSettings (
245
255
null ,
246
256
"logs-apache-production" ,
@@ -255,11 +265,7 @@ public void testWithLogsComponentTemplate() throws IOException {
255
265
}
256
266
257
267
public void testWithMultipleComponentTemplates () throws IOException {
258
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
259
- logsdbLicenseService ,
260
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
261
- );
262
-
268
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (true );
263
269
final Settings additionalIndexSettings = provider .getAdditionalIndexSettings (
264
270
null ,
265
271
"logs-apache-production" ,
@@ -274,11 +280,7 @@ public void testWithMultipleComponentTemplates() throws IOException {
274
280
}
275
281
276
282
public void testWithCustomComponentTemplatesOnly () throws IOException {
277
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
278
- logsdbLicenseService ,
279
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
280
- );
281
-
283
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (true );
282
284
final Settings additionalIndexSettings = provider .getAdditionalIndexSettings (
283
285
null ,
284
286
"logs-apache-production" ,
@@ -293,11 +295,7 @@ public void testWithCustomComponentTemplatesOnly() throws IOException {
293
295
}
294
296
295
297
public void testNonMatchingTemplateIndexPattern () throws IOException {
296
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
297
- logsdbLicenseService ,
298
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
299
- );
300
-
298
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (true );
301
299
final Settings additionalIndexSettings = provider .getAdditionalIndexSettings (
302
300
null ,
303
301
"logs-apache-production" ,
@@ -331,10 +329,7 @@ public void testCaseSensitivity() throws IOException {
331
329
}
332
330
333
331
public void testMultipleHyphensInDataStreamName () throws IOException {
334
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
335
- logsdbLicenseService ,
336
- Settings .builder ().put ("cluster.logsdb.enabled" , true ).build ()
337
- );
332
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (true );
338
333
339
334
final Settings additionalIndexSettings = provider .getAdditionalIndexSettings (
340
335
null ,
@@ -349,12 +344,8 @@ public void testMultipleHyphensInDataStreamName() throws IOException {
349
344
assertIndexMode (additionalIndexSettings , IndexMode .LOGSDB .getName ());
350
345
}
351
346
352
- public void testBeforeAndAFterSettingUpdate () throws IOException {
353
- final LogsdbIndexModeSettingsProvider provider = new LogsdbIndexModeSettingsProvider (
354
- logsdbLicenseService ,
355
- Settings .builder ().put ("cluster.logsdb.enabled" , false ).build ()
356
- );
357
-
347
+ public void testBeforeAndAfterSettingUpdate () throws IOException {
348
+ final LogsdbIndexModeSettingsProvider provider = withoutMapperService (false );
358
349
final Settings beforeSettings = provider .getAdditionalIndexSettings (
359
350
null ,
360
351
"logs-apache-production" ,
@@ -627,7 +618,7 @@ public void testNewIndexHasSyntheticSourceUsageInvalidSettings() throws IOExcept
627
618
}
628
619
}
629
620
630
- public void testGetAdditionalIndexSettingsDowngradeFromSyntheticSource () throws IOException {
621
+ public void testGetAdditionalIndexSettingsDowngradeFromSyntheticSource () {
631
622
String dataStreamName = DATA_STREAM_NAME ;
632
623
Metadata .Builder mb = Metadata .builder (
633
624
DataStreamTestHelper .getClusterStateWithDataStreams (
@@ -698,6 +689,33 @@ public void testGetAdditionalIndexSettingsDowngradeFromSyntheticSource() throws
698
689
assertThat (newMapperServiceCounter .get (), equalTo (4 ));
699
690
}
700
691
692
+ public void testGetAdditionalIndexSettingsDowngradeFromSyntheticSourceOldNode () {
693
+ logsdbLicenseService .setSyntheticSourceFallback (true );
694
+ LogsdbIndexModeSettingsProvider provider = withSyntheticSourceDemotionSupport (true , Version .V_8_16_0 );
695
+ Metadata .Builder mb = Metadata .builder (
696
+ DataStreamTestHelper .getClusterStateWithDataStreams (
697
+ List .of (Tuple .tuple (DATA_STREAM_NAME , 1 )),
698
+ List .of (),
699
+ Instant .now ().toEpochMilli (),
700
+ builder ().build (),
701
+ 1
702
+ ).getMetadata ()
703
+ );
704
+ Metadata metadata = mb .build ();
705
+ Settings settings = builder ().put (IndexSettings .INDEX_MAPPER_SOURCE_MODE_SETTING .getKey (), SourceFieldMapper .Mode .SYNTHETIC )
706
+ .build ();
707
+ var result = provider .getAdditionalIndexSettings (
708
+ DataStream .getDefaultBackingIndexName (DATA_STREAM_NAME , 2 ),
709
+ DATA_STREAM_NAME ,
710
+ null ,
711
+ metadata ,
712
+ Instant .ofEpochMilli (1L ),
713
+ settings ,
714
+ List .of ()
715
+ );
716
+ assertTrue (result .isEmpty ());
717
+ }
718
+
701
719
public void testGetAdditionalIndexSettingsDowngradeFromSyntheticSourceFileMatch () throws IOException {
702
720
logsdbLicenseService .setSyntheticSourceFallback (true );
703
721
LogsdbIndexModeSettingsProvider provider = withSyntheticSourceDemotionSupport (true );
@@ -773,6 +791,15 @@ public void testRoutingPathOnSortFields() throws Exception {
773
791
assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), contains ("host" , "message" ));
774
792
}
775
793
794
+ public void testRoutingPathOnSortFieldsDisabledInOldNode () throws Exception {
795
+ var settings = Settings .builder ()
796
+ .put (IndexSortConfig .INDEX_SORT_FIELD_SETTING .getKey (), "host,message" )
797
+ .put (IndexSettings .LOGSDB_ROUTE_ON_SORT_FIELDS .getKey (), true )
798
+ .build ();
799
+ Settings result = generateLogsdbSettings (settings , null , Version .V_8_17_0 );
800
+ assertTrue (result .isEmpty ());
801
+ }
802
+
776
803
public void testRoutingPathOnSortFieldsFilterTimestamp () throws Exception {
777
804
var settings = Settings .builder ()
778
805
.put (IndexSortConfig .INDEX_SORT_FIELD_SETTING .getKey (), "host,message,@timestamp" )
@@ -868,6 +895,42 @@ public void testSortAndHostNameWithCustomSortConfig() throws Exception {
868
895
assertEquals (0 , newMapperServiceCounter .get ());
869
896
}
870
897
898
+ public void testSortAndHostNoHost () throws Exception {
899
+ var settings = Settings .builder ().put (IndexSettings .MODE .getKey (), IndexMode .LOGSDB ).build ();
900
+ var mappings = """
901
+ {
902
+ "_doc": {
903
+ "properties": {
904
+ "@timestamp": {
905
+ "type": "date"
906
+ }
907
+ }
908
+ }
909
+ }
910
+ """ ;
911
+ Settings result = generateLogsdbSettings (settings , mappings );
912
+ assertTrue (IndexSettings .LOGSDB_SORT_ON_HOST_NAME .get (result ));
913
+ assertTrue (IndexSettings .LOGSDB_ADD_HOST_NAME_FIELD .get (result ));
914
+ assertEquals (1 , newMapperServiceCounter .get ());
915
+ }
916
+
917
+ public void testSortAndHostNoHostOldNode () throws Exception {
918
+ var settings = Settings .builder ().put (IndexSettings .MODE .getKey (), IndexMode .LOGSDB ).build ();
919
+ var mappings = """
920
+ {
921
+ "_doc": {
922
+ "properties": {
923
+ "@timestamp": {
924
+ "type": "date"
925
+ }
926
+ }
927
+ }
928
+ }
929
+ """ ;
930
+ Settings result = generateLogsdbSettings (settings , mappings , Version .V_8_17_0 );
931
+ assertTrue (result .isEmpty ());
932
+ }
933
+
871
934
public void testSortAndHostNameKeyword () throws Exception {
872
935
var settings = Settings .builder ().put (IndexSettings .MODE .getKey (), IndexMode .LOGSDB ).build ();
873
936
var mappings = """
0 commit comments