|  | @@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.equalTo;
 | 
	
		
			
				|  |  |  public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static final TimeValue DEFAULT_LOOK_BACK_TIME = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  | -    private static final TimeValue DEFAULT_LOOK_AHEAD_TIME = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  | +    private static final TimeValue DEFAULT_LOOK_AHEAD_TIME = TimeValue.timeValueMinutes(30); // default
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      DataStreamIndexSettingsProvider provider;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -94,7 +94,6 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          String dataStreamName = "logs-app1";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          Settings settings = builder().putList(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "field2").build();
 | 
	
		
			
				|  |  |          String mapping = """
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -126,8 +125,8 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              List.of(new CompressedXContent(mapping))
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |          assertThat(result.size(), equalTo(2));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGetAdditionalIndexSettingsMappingsMerging() throws Exception {
 | 
	
	
		
			
				|  | @@ -135,7 +134,6 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          String dataStreamName = "logs-app1";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          Settings settings = Settings.EMPTY;
 | 
	
		
			
				|  |  |          String mapping1 = """
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -193,8 +191,8 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              List.of(new CompressedXContent(mapping1), new CompressedXContent(mapping2), new CompressedXContent(mapping3))
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |          assertThat(result.size(), equalTo(3));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |          assertThat(IndexMetadata.INDEX_ROUTING_PATH.get(result), containsInAnyOrder("field1", "field3"));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -203,7 +201,6 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |          String dataStreamName = "logs-app1";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          Settings settings = Settings.EMPTY;
 | 
	
		
			
				|  |  |          Settings result = provider.getAdditionalIndexSettings(
 | 
	
		
			
				|  |  |              DataStream.getDefaultBackingIndexName(dataStreamName, 1),
 | 
	
	
		
			
				|  | @@ -215,8 +212,8 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              List.of()
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |          assertThat(result.size(), equalTo(2));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGetAdditionalIndexSettingsLookAheadTime() throws Exception {
 | 
	
	
		
			
				|  | @@ -263,7 +260,7 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGetAdditionalIndexSettingsDataStreamAlreadyCreated() throws Exception {
 | 
	
		
			
				|  |  |          String dataStreamName = "logs-app1";
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2);
 | 
	
		
			
				|  |  | +        TimeValue lookAheadTime = TimeValue.timeValueMinutes(30);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Instant sixHoursAgo = Instant.now().minus(6, ChronoUnit.HOURS).truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  |          Instant currentEnd = sixHoursAgo.plusMillis(lookAheadTime.getMillis());
 | 
	
	
		
			
				|  | @@ -415,7 +412,6 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGenerateRoutingPathFromDynamicTemplate() throws Exception {
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          String mapping = """
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  "_doc": {
 | 
	
	
		
			
				|  | @@ -448,14 +444,13 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              """;
 | 
	
		
			
				|  |  |          Settings result = generateTsdbSettings(mapping, now);
 | 
	
		
			
				|  |  |          assertThat(result.size(), equalTo(3));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |          assertThat(IndexMetadata.INDEX_ROUTING_PATH.get(result), containsInAnyOrder("host.id", "prometheus.labels.*"));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntries() throws Exception {
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          String mapping = """
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  "_doc": {
 | 
	
	
		
			
				|  | @@ -488,8 +483,8 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              """;
 | 
	
		
			
				|  |  |          Settings result = generateTsdbSettings(mapping, now);
 | 
	
		
			
				|  |  |          assertThat(result.size(), equalTo(3));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |          assertThat(
 | 
	
		
			
				|  |  |              IndexMetadata.INDEX_ROUTING_PATH.get(result),
 | 
	
		
			
				|  |  |              containsInAnyOrder("host.id", "xprometheus.labels.*", "yprometheus.labels.*")
 | 
	
	
		
			
				|  | @@ -500,7 +495,6 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGenerateRoutingPathFromDynamicTemplate_templateWithNoPathMatch() throws Exception {
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          String mapping = """
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  "_doc": {
 | 
	
	
		
			
				|  | @@ -542,14 +536,13 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              """;
 | 
	
		
			
				|  |  |          Settings result = generateTsdbSettings(mapping, now);
 | 
	
		
			
				|  |  |          assertThat(result.size(), equalTo(3));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |          assertThat(IndexMetadata.INDEX_ROUTING_PATH.get(result), containsInAnyOrder("host.id", "prometheus.labels.*"));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testGenerateRoutingPathFromDynamicTemplate_nonKeywordTemplate() throws Exception {
 | 
	
		
			
				|  |  |          Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
 | 
	
		
			
				|  |  | -        TimeValue lookAheadTime = TimeValue.timeValueHours(2); // default
 | 
	
		
			
				|  |  |          String mapping = """
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  |                  "_doc": {
 | 
	
	
		
			
				|  | @@ -590,8 +583,8 @@ public class DataStreamIndexSettingsProviderTests extends ESTestCase {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              """;
 | 
	
		
			
				|  |  |          Settings result = generateTsdbSettings(mapping, now);
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | -        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(lookAheadTime.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
 | 
	
		
			
				|  |  | +        assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
 | 
	
		
			
				|  |  |          assertThat(IndexMetadata.INDEX_ROUTING_PATH.get(result), containsInAnyOrder("host.id", "prometheus.labels.*"));
 | 
	
		
			
				|  |  |          assertEquals(2, IndexMetadata.INDEX_ROUTING_PATH.get(result).size());
 | 
	
		
			
				|  |  |      }
 |