@@ -525,16 +525,12 @@ public void testGenerateRoutingPathFromDynamicTemplate() throws Exception {
525
525
}
526
526
""" ;
527
527
Settings result = generateTsdbSettings (mapping , now );
528
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
528
+ assertThat (result .size (), equalTo (4 ));
529
529
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
530
530
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
531
531
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
532
532
assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("host.id" , "prometheus.labels.*" ));
533
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
534
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("host.id" , "prometheus.labels.*" ));
535
- } else {
536
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
537
- }
533
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
538
534
}
539
535
540
536
public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntries () throws Exception {
@@ -570,22 +566,15 @@ public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntri
570
566
}
571
567
""" ;
572
568
Settings result = generateTsdbSettings (mapping , now );
573
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
569
+ assertThat (result .size (), equalTo (4 ));
574
570
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
575
571
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
576
572
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
577
573
assertThat (
578
574
IndexMetadata .INDEX_ROUTING_PATH .get (result ),
579
575
containsInAnyOrder ("host.id" , "xprometheus.labels.*" , "yprometheus.labels.*" )
580
576
);
581
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
582
- assertThat (
583
- IndexMetadata .INDEX_DIMENSIONS .get (result ),
584
- containsInAnyOrder ("host.id" , "xprometheus.labels.*" , "yprometheus.labels.*" )
585
- );
586
- } else {
587
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
588
- }
577
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
589
578
}
590
579
591
580
public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntriesMultiFields () throws Exception {
@@ -626,22 +615,15 @@ public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntri
626
615
}
627
616
""" ;
628
617
Settings result = generateTsdbSettings (mapping , now );
629
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
618
+ assertThat (result .size (), equalTo (4 ));
630
619
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
631
620
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
632
621
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
633
622
assertThat (
634
623
IndexMetadata .INDEX_ROUTING_PATH .get (result ),
635
624
containsInAnyOrder ("host.id" , "xprometheus.labels.*" , "yprometheus.labels.*" )
636
625
);
637
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
638
- assertThat (
639
- IndexMetadata .INDEX_DIMENSIONS .get (result ),
640
- containsInAnyOrder ("host.id" , "xprometheus.labels.*" , "yprometheus.labels.*" )
641
- );
642
- } else {
643
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
644
- }
626
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
645
627
}
646
628
647
629
public void testGenerateRoutingPathFromDynamicTemplate_templateWithNoPathMatch () throws Exception {
@@ -686,13 +668,51 @@ public void testGenerateRoutingPathFromDynamicTemplate_templateWithNoPathMatch()
686
668
}
687
669
""" ;
688
670
Settings result = generateTsdbSettings (mapping , now );
689
- assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
671
+ assertThat (result .size (), equalTo (4 ));
690
672
assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
691
673
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
692
674
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
693
675
assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("host.id" , "prometheus.labels.*" ));
676
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
677
+ }
678
+
679
+ public void testGenerateNonDimensionDynamicTemplate () throws Exception {
680
+ Instant now = Instant .now ().truncatedTo (ChronoUnit .SECONDS );
681
+ String mapping = """
682
+ {
683
+ "_doc": {
684
+ "dynamic_templates": [
685
+ {
686
+ "strings_as_keyword": {
687
+ "match_mapping_type": "string",
688
+ "mapping": {
689
+ "type": "keyword",
690
+ "ignore_above": 1024,
691
+ "time_series_dimension": false
692
+ }
693
+ }
694
+ }
695
+ ],
696
+ "properties": {
697
+ "host.id": {
698
+ "type": "keyword",
699
+ "time_series_dimension": true
700
+ },
701
+ "another_field": {
702
+ "type": "keyword"
703
+ }
704
+ }
705
+ }
706
+ }
707
+ """ ;
708
+ Settings result = generateTsdbSettings (mapping , now );
709
+ assertThat (result .size (), equalTo (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ? 5 : 4 ));
710
+ assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
711
+ assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
712
+ 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" ));
694
714
if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
695
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("host.id" , "prometheus.labels.*" ));
715
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("host.id" ));
696
716
} else {
697
717
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
698
718
}
@@ -742,11 +762,7 @@ public void testGenerateRoutingPathFromDynamicTemplate_nonKeywordTemplate() thro
742
762
Settings result = generateTsdbSettings (mapping , now );
743
763
assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
744
764
assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
745
- if (INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG ) {
746
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), containsInAnyOrder ("host.id" , "prometheus.labels.*" ));
747
- } else {
748
- assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
749
- }
765
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
750
766
}
751
767
752
768
public void testGenerateRoutingPathFromPassThroughObject () throws Exception {
@@ -789,6 +805,44 @@ public void testGenerateRoutingPathFromPassThroughObject() throws Exception {
789
805
}
790
806
}
791
807
808
+ public void testDynamicTemplatePrecedence () throws Exception {
809
+ Instant now = Instant .now ().truncatedTo (ChronoUnit .SECONDS );
810
+ String mapping = """
811
+ {
812
+ "_doc": {
813
+ "dynamic_templates": [
814
+ {
815
+ "no_dimension_labels": {
816
+ "path_match": "labels.host_ip",
817
+ "mapping": {
818
+ "type": "keyword"
819
+ }
820
+ }
821
+ },
822
+ {
823
+ "labels": {
824
+ "path_match": "labels.*",
825
+ "mapping": {
826
+ "type": "keyword",
827
+ "time_series_dimension": true
828
+ }
829
+ }
830
+ }
831
+ ]
832
+ }
833
+ }
834
+ """ ;
835
+ Settings result = generateTsdbSettings (mapping , now );
836
+ assertThat (result .size (), equalTo (4 ));
837
+ assertThat (IndexSettings .MODE .get (result ), equalTo (IndexMode .TIME_SERIES ));
838
+ assertThat (IndexSettings .TIME_SERIES_START_TIME .get (result ), equalTo (now .minusMillis (DEFAULT_LOOK_BACK_TIME .getMillis ())));
839
+ assertThat (IndexSettings .TIME_SERIES_END_TIME .get (result ), equalTo (now .plusMillis (DEFAULT_LOOK_AHEAD_TIME .getMillis ())));
840
+ // labels.host_ip is not a dimension because it matches the first template which does not have time_series_dimension:true
841
+ // we can't use index.dimensions as it would add non-dimension fields to the tsid
842
+ assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
843
+ assertThat (IndexMetadata .INDEX_ROUTING_PATH .get (result ), containsInAnyOrder ("labels.*" ));
844
+ }
845
+
792
846
public void testAddNewDimension () throws Exception {
793
847
String newMapping = """
794
848
{
@@ -888,7 +942,7 @@ public void testAddDynamicTemplate() throws Exception {
888
942
}
889
943
}
890
944
""" ;
891
- // the new labels.label1 field already matches labels.*, so no change
945
+ // we don't support index.dimensions with dynamic templates so we'll unset index.dimensions
892
946
Settings result = onUpdateMappings ("labels.*" , "labels.*" , mapping );
893
947
assertThat (result .size (), equalTo (1 ));
894
948
assertThat (IndexMetadata .INDEX_DIMENSIONS .get (result ), empty ());
0 commit comments